- 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
, customTrustManager
implementations. - Risk Severity: Critical
- Mitigation Strategies:
- Never disable certificate validation. Use the default
SSLConnectionSocketFactory
andBROWSER_COMPATIBLE_HOSTNAME_VERIFIER
. - If using a custom
SSLContext
, ensure it's configured with aTrustManager
that properly validates certificates against a trusted certificate authority (CA). - Avoid using
ALLOW_ALL_HOSTNAME_VERIFIER
. If a customHostnameVerifier
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.
- Never disable certificate validation. Use the default
- 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
orTRACE
in production). - Implement log redaction to filter out sensitive data.
- Regularly review and audit logging configurations.
- Securely store and manage log files.
- Disable wire logging (
- 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
(specificallyisRedirectsEnabled
and customRedirectStrategy
). - 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.
- Carefully review the use of automatic redirects. If possible, disable automatic redirects (
- Description: While primarily a server-side issue (missing
Secure
andHttpOnly
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
andHttpOnly
flags on all sensitive cookies. The client can help mitigate, but the server is ultimately responsible for setting these flags.
- Configure the client's cookie policy appropriately. Use