Authentication overview

Authentication for programmatic interaction with the Mozilla http scanner, also known as Mozilla Observatory, is managed through API keys. This method secures access to the platform's web security scanning functionalities, ensuring that all API requests are authorized.

The Mozilla Observatory provides a service for developers and security professionals to analyze website configurations for common security vulnerabilities and best practice adherence, such as HTTP header configurations and TLS settings. An API key serves as a unique identifier and secret token, verifying the identity of the client making requests to the Mozilla Observatory API. This approach is common in web APIs for its simplicity and effectiveness in managing access control for automated systems and integrations.

All communications with the Mozilla Observatory API are expected to occur over HTTPS (Hypertext Transfer Protocol Secure). This protocol encrypts data in transit, protecting API keys and other sensitive information from interception by unauthorized parties. The use of TLS (Transport Layer Security) is a foundational security measure for web services, as outlined by web security standards like those from the World Wide Web Consortium's Content Security Policy. Clients must ensure their requests use the correct HTTPS endpoints to maintain the integrity and confidentiality of their authentication credentials and data.

The API is designed to be integrated into CI/CD pipelines, custom scripts, and monitoring tools, allowing for automated security checks during development and deployment. Proper authentication is a prerequisite for initiating scans programmatically and retrieving scan results, making credential management a critical aspect of using the service effectively.

Supported authentication methods

The Mozilla http scanner API primarily supports authentication via API keys. This is a token-based authentication mechanism where a unique string (the API key) is included with each request to identify and authenticate the calling application or user. The system verifies the submitted key against its records to grant access to the requested API endpoints.

The following table details the supported authentication method for Mozilla http scanner:

Method When to Use Security Level
API Key Automated scripts, CI/CD pipelines, integrations, server-to-server communication Moderate (when properly stored and transmitted over HTTPS)

API keys are generally suitable for scenarios where a client needs to access specific, predefined API functionalities, rather than managing user sessions or complex authorization flows. For the Mozilla http scanner, this means an API key grants the ability to initiate scans and retrieve results, aligning with its function as a utility for web security analysis.

It is important to understand that API keys, by themselves, do not typically provide granular access control beyond enabling or disabling access to an API. They do not usually differentiate between different roles or permissions within an application in the way that more complex authentication and authorization frameworks, like OAuth 2.0, might. However, for the specific purpose of the Mozilla http scanner, where the primary action is initiating a scan, a straightforward API key system is efficient and sufficient. Implementers should focus on securely handling the API key itself to prevent unauthorized usage, as detailed in the Mozilla Observatory API documentation.

Getting your credentials

To obtain an API key for the Mozilla http scanner, you typically need to create an account on the Mozilla Observatory platform. While the core scanning service is free and accessible via the web interface, programmatic access requires an authenticated API key.

  1. Account Creation: Navigate to the Mozilla Observatory homepage and sign up for an account if you do not already have one. This usually involves providing an email address and creating a password.
  2. Accessing API Settings: Once logged in, look for a section related to 'API Keys', 'Developer Settings', or 'Profile Settings'. The exact location may vary, but it is typically found within your user dashboard or account management area. Refer to the Mozilla Observatory documentation for precise navigation instructions.
  3. Generating an API Key: Within the API settings, there should be an option to generate a new API key. This process usually creates a unique alphanumeric string. It is crucial to copy this key immediately upon generation, as some platforms do not display the key again after its initial creation for security reasons.
  4. Storing the API Key: Once generated, store your API key securely. Avoid hardcoding it directly into your source code. Instead, use environment variables, a secrets management service, or a configuration file that is not committed to version control.

The retrieved API key will be used in HTTP headers or as part of the request payload when interacting with the Mozilla Observatory API endpoints. The Mozilla Observatory API reference provides specific examples of how to include the API key in your requests, ensuring proper authentication and successful interaction with the service.

Authenticated request example

When making an authenticated request to the Mozilla http scanner API, the API key is typically included in the HTTP headers. The specific header name is usually specified in the API documentation. For the Mozilla Observatory API, requests are often made to the /api/v1/scan endpoint for initiating a scan.

Here's a conceptual example using curl, a common command-line tool for making HTTP requests:

export MOZILLA_OBSERVATORY_API_KEY="YOUR_API_KEY_HERE"

curl -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Token ${MOZILLA_OBSERVATORY_API_KEY}" \
  -d '{"host": "example.com"}' \
  https://api.observatory.mozilla.org/api/v1/scan

In this example:

  • YOUR_API_KEY_HERE should be replaced with the actual API key you generated.
  • export MOZILLA_OBSERVATORY_API_KEY="YOUR_API_KEY_HERE" demonstrates setting the API key as an environment variable, which is a recommended security practice instead of hardcoding.
  • -H "Content-Type: application/json" specifies that the request body is in JSON format.
  • -H "Authorization: Token ${MOZILLA_OBSERVATORY_API_KEY}" is the critical authentication header. The Token prefix is a common convention for API key authentication, but always verify the exact format required by the Mozilla Observatory API documentation.
  • -d '{"host": "example.com"}' is the request body, specifying the target host for the scan.
  • https://api.observatory.mozilla.org/api/v1/scan is the API endpoint for initiating a scan.

After initiating a scan, you would typically make subsequent authenticated requests to retrieve the scan results, often using an endpoint like /api/v1/analyze with the unique scan ID returned from the initial scan request. The authentication method (including the Authorization header) would remain consistent for these follow-up requests.

Developers using other programming languages would adapt this pattern:

  • Python: Use the requests library to set the Authorization header and send a JSON payload.
  • Node.js: Utilize fetch or axios to construct the HTTP request with the appropriate headers.
  • Java: Employ HttpURLConnection or client libraries like Apache HttpClient to manage headers and request bodies.

Always refer to the official Mozilla Observatory API documentation for the most up-to-date and specific instructions, including required headers, payload structures, and available endpoints.

Security best practices

When authenticating with the Mozilla http scanner API, implementing robust security practices is essential to protect your API keys and prevent unauthorized access to your scanning capabilities. Compromised API keys can lead to misuse of the service or exposure of sensitive scan targets.

  1. Secure Storage of API Keys:
    • Environment Variables: Store API keys as environment variables on your server or local machine. This prevents them from being hardcoded into your application's source code, which could expose them if the code is committed to a public repository.
    • Secrets Management Services: For production environments, consider using dedicated secrets management services like AWS Secrets Manager (AWS Secrets Manager documentation), Google Cloud Secret Manager (Google Cloud Secret Manager overview), or Azure Key Vault (Azure Key Vault overview). These services provide centralized, secure storage and controlled access to sensitive credentials.
    • Configuration Files (with Caution): If using configuration files, ensure they are external to your codebase, encrypted, and excluded from version control systems (e.g., via .gitignore).
  2. Transmit Over HTTPS Only:
    • Always ensure that all API requests to the Mozilla http scanner are made over HTTPS/TLS. This encrypts the communication channel, protecting your API key from interception during transit. The Mozilla Observatory API endpoints will enforce HTTPS.
  3. Principle of Least Privilege:
    • While API keys for Mozilla Observatory typically grant access to all scanning functions, generally, in systems with more granular permissions, you should ensure that the API key or token used has only the minimum necessary permissions required for its intended task.
  4. Regular Key Rotation:
    • Periodically rotate your API keys. If a key is compromised, rotation limits the window of exposure. The frequency of rotation depends on your organization's security policies and risk assessment. When you rotate a key, generate a new one and update all applications using the old key, then revoke the old key.
  5. Monitoring and Alerting:
    • Monitor API usage for unusual activity. Spikes in requests or requests from unexpected geographical locations could indicate a compromised key. Set up alerts for such anomalies if your monitoring infrastructure supports it.
  6. Revocation of Compromised Keys:
    • If you suspect an API key has been compromised, revoke it immediately through the Mozilla Observatory account settings. Revocation invalidates the key, preventing further unauthorized use.
  7. Source Code Security:
    • Regularly scan your codebase for accidental exposure of API keys or other secrets. Tools like GitGuardian or TruffleHog can help detect hardcoded credentials before they are committed or pushed.

Adhering to these security practices helps maintain the integrity of your integrations with the Mozilla http scanner and protects your valuable credentials from unauthorized access and misuse. For further guidance on secure API key management, developers can consult resources from organizations like the Open Web Application Security Project (OWASP).