Skip to content

Latest commit

 

History

History
54 lines (45 loc) · 5.68 KB

File metadata and controls

54 lines (45 loc) · 5.68 KB

Threat Model Analysis for apache/httpcomponents-client

  • Description: An attacker performs a Man-in-the-Middle (MITM) attack, intercepting the HTTPS connection and presenting a forged certificate. The attacker exploits a misconfigured client that doesn't properly validate the server's certificate (e.g., hostname verification is disabled, or a custom trust manager accepts all certificates).
    • Impact: Complete compromise of confidentiality and integrity. The attacker can decrypt, view, and modify all data exchanged, including credentials, session tokens, and sensitive data.
    • Affected Component: org.apache.http.conn.ssl.SSLConnectionSocketFactory, org.apache.http.conn.ssl.X509HostnameVerifier (or custom implementations), org.apache.http.ssl.SSLContexts, custom TrustManager implementations.
    • Risk Severity: Critical
    • Mitigation Strategies:
      • Never disable certificate validation. Use the default SSLConnectionSocketFactory and BROWSER_COMPATIBLE_HOSTNAME_VERIFIER.
      • If using a custom SSLContext, ensure it's configured with a TrustManager that properly validates certificates against a trusted certificate authority (CA).
      • Avoid using ALLOW_ALL_HOSTNAME_VERIFIER. If a custom HostnameVerifier is absolutely necessary, ensure it performs rigorous checks.
      • Consider certificate pinning (with careful operational planning) for high-security scenarios.
      • Regularly update HttpComponents Client to benefit from security patches.
  • Description: An attacker gains access to application logs. The application, using HttpComponents Client, has wire logging enabled (org.apache.http.wire), which logs all raw data sent and received, including headers (like Basic Auth) and request/response bodies containing sensitive information.
    • Impact: The attacker obtains valid credentials or session tokens, allowing them to impersonate legitimate users and access protected resources.
    • Affected Component: org.apache.http.impl.client.DefaultHttpClient (if wire logging is enabled), application logging configuration.
    • Risk Severity: High
    • Mitigation Strategies:
      • Disable wire logging (org.apache.http.wire) in production. This is the most critical mitigation.
      • Configure logging levels appropriately (avoid DEBUG or TRACE in production).
      • Implement log redaction to filter out sensitive data.
      • Regularly review and audit logging configurations.
      • Securely store and manage log files.
  • Description: The attacker manipulates the server response to include a redirect (3xx status code) to a malicious host. The client is configured to automatically follow redirects without proper validation, sending subsequent requests (potentially including sensitive data) to the attacker-controlled server.
    • Impact: Leakage of sensitive information (credentials, cookies, request data) to the attacker. The attacker could also serve malicious content.
    • Affected Component: org.apache.http.impl.client.DefaultRedirectStrategy, org.apache.http.client.config.RequestConfig (specifically isRedirectsEnabled and custom RedirectStrategy).
    • Risk Severity: High
    • Mitigation Strategies:
      • Carefully review the use of automatic redirects. If possible, disable automatic redirects (isRedirectsEnabled = false) and handle redirects manually.
      • If automatic redirects are necessary, implement a custom RedirectStrategy that validates the target host before following it. This validation should include:
        • Checking against a whitelist of allowed hosts.
        • Ensuring the redirect stays within the same domain or a set of trusted domains.
        • Verifying that the redirected URL uses HTTPS.
      • Limit the number of redirects followed automatically.
  • Description: While primarily a server-side issue (missing Secure and HttpOnly flags on cookies), the client's handling of cookies can exacerbate the problem. An attacker intercepts network traffic or performs XSS. If the client doesn't enforce a strict cookie policy, it might accept and send cookies that should have been rejected.
    • Impact: The attacker can impersonate the user and gain unauthorized access.
    • Affected Component: org.apache.http.client.CookieStore, org.apache.http.impl.client.BasicCookieStore, org.apache.http.client.config.RequestConfig (cookie policy).
    • Risk Severity: High
    • Mitigation Strategies:
      • Configure the client's cookie policy appropriately. Use CookieSpecs.STANDARD or a custom policy that enforces security best practices. This helps prevent the client from sending cookies that should have been rejected due to missing security flags.
      • Avoid accepting cookies from untrusted sources.
      • Validate the domain and path attributes of cookies.
      • Crucially, ensure the server sets the Secure and HttpOnly flags on all sensitive cookies. The client can help mitigate, but the server is ultimately responsible for setting these flags.