Skip to content

Redact sensitive headers from debug logs#2279

Open
pavel-ptashyts wants to merge 2 commits into
AsyncHttpClient:mainfrom
maygemdev:perf/redact-sensitive-log-headers
Open

Redact sensitive headers from debug logs#2279
pavel-ptashyts wants to merge 2 commits into
AsyncHttpClient:mainfrom
maygemdev:perf/redact-sensitive-log-headers

Conversation

@pavel-ptashyts

@pavel-ptashyts pavel-ptashyts commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Summary

  • redact authentication and cookie values in HTTP and WebSocket debug logs
  • expose a shared sensitive-header predicate and redaction value for DefaultRequest
  • allow sensitive logging through an explicit startup-only JVM property or environment variable
  • avoid rendering complete request objects in retry and replay logs by default
  • add regression coverage for Netty message formatting and request string output

Root cause

Debug logging passed complete Netty request and response objects to SLF4J. Their
string representations included every header value, so user-supplied
Authorization headers and other credentials could be written to application
logs.

Sensitive logging

Sensitive values remain redacted by default. Full header values can be enabled
before HttpMessageFormatter is initialized with either:

  • JVM property: -Dorg.asynchttpclient.enableSensitiveLogging=true
  • environment variable: AHC_ENABLE_SENSITIVE_LOGGING=true

The JVM property takes precedence over the environment variable. The setting is
read once and remains immutable for the process. Enabling it can expose
credentials and session data in logs.

Validation

  • JDK 11 default-redaction focused suite: 32 tests passed, 2 startup-mode tests skipped
  • JDK 11 system-property, environment-variable, and precedence startup cases passed
  • JDK 11 ./mvnw clean verify: 1,307 tests passed, 17 skipped; Javadocs and Revapi passed

Closes #1739
Closes #1740

Codex on behalf of Pavel Ptashyts

Request and response debug logging rendered complete Netty messages,
which exposed Authorization values and other credentials.

Format logged HTTP messages with shared redaction for authentication and
cookie headers. Reuse the same public predicate in DefaultRequest, and
avoid rendering complete requests from retry and replay paths.

Add regression coverage for HTTP message formatting and request string
representations.

Fixes AsyncHttpClient#1739
Fixes AsyncHttpClient#1740

Codex on behalf of Pavel Ptashyts

Co-Authored-By: Codex <codex@openai.com>
@hyperxpro

Copy link
Copy Markdown
Member

I would like to have a system property / environment variable to enable non-redacted logs. It is helpful in debugging at CI pipeline.

Probably like AHC_ENABLE_SENSITIVE_LOGGING=true?

Of course feel free to choose a better key.

Redaction is secure by default, but it can prevent diagnosis of
authentication failures that only occur in CI.

Read a JVM property or environment variable once when the HTTP message
formatter is initialized. Fold that immutable setting into
isSensitiveHeader so both Netty logging and DefaultRequest use the same
decision without repeated configuration lookups.

Refs AsyncHttpClient#1739
Refs AsyncHttpClient#1740

Codex on behalf of Pavel Ptashyts

Co-Authored-By: Codex <codex@openai.com>
@pavel-ptashyts

Copy link
Copy Markdown
Contributor Author

@hyperxpro Implemented in 2a7f11b84.

Sensitive values remain redacted by default. Unredacted logging can be enabled before HttpMessageFormatter is initialized with either:

  • JVM property: -Dorg.asynchttpclient.enableSensitiveLogging=true
  • environment variable: AHC_ENABLE_SENSITIVE_LOGGING=true

The value is calculated once and remains immutable for the process. The JVM property takes precedence over the environment variable, including allowing an explicit false to keep redaction enabled. Full JDK 11 verification passes.

Thanks for the suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

authorization headers sensitive data leaks in debug logs authorization headers exposed in log

2 participants