davsclaus opened a new pull request, #30872:
URL: https://github.com/apache/camel/pull/30872

   JIRA: https://issues.apache.org/jira/browse/CAMEL-27429
   
   ## Problem
   
   With `logHttpActivity=true`, `LoggingHttpActivityListener` logs every 
request and response header as `Name: value`. The value is only masked when 
Apache HttpClient flags the header as sensitive (almost never) or with 
`logMask=true`, and even then the `DefaultMaskingFormatter` only masks 
`key=value`, XML and JSON shapes. So `Authorization: Bearer ...`, `Cookie`, 
`Set-Cookie` and API key headers were written to the log in clear text.
   
   ## Change
   
   Instead of the `logMaskPattern` option proposed in the ticket, the listener 
now masks the value of any request or response header that carries a 
credential, always (secure by default, no configuration needed):
   
   - headers whose name is a sensitive key of 
`SensitiveUtils.containsSensitive` (for example `Authorization`, `Api-Key`, 
`Token`, `Password`);
   - plus a small list of well-known HTTP credential headers that are not 
option names, so not in the generated `SensitiveUtils` list: 
`Proxy-Authorization`, `Cookie`, `Set-Cookie`, `X-Api-Key`, `X-Auth-Token`.
   
   The header name is kept and the whole value is replaced with the mask string 
of the masking formatter (`xxxxx`), for example `Authorization: xxxxx`. The 
`SensitiveUtils` list is not changed: it is generated from the secret options 
of all components and shared by other code (property and URI masking), so 
adding `cookie` there would be the wrong place.
   
   The behaviour for `Header#isSensitive()` and for `logMask=true` on the other 
header values and the body is unchanged.
   
   Only camel-http has this activity-logging feature 
(`LoggingHttpActivityListener` is not shared with other components).
   
   ## Docs
   
   - New section "Logging HTTP activity" in the camel-http component page.
   - The `logMask` description of `LoggingHttpActivityListener` says credential 
headers are always masked (regenerated bean metadata and catalog copies).
   - Upgrade guide 4.24: "camel-http - logHttpActivity masks the values of 
sensitive headers".
   
   ## Tests
   
   - `HttpLoggingActivityMaskHeadersTest` sends a request with `Authorization: 
Bearer secret-token`, `Proxy-Authorization`, `Cookie`, `X-Api-Key` and a plain 
header through an `http` endpoint with `logHttpActivity=true`; the server 
answers with `Set-Cookie`. It captures the lines the listener logs and asserts 
the header names are logged with `xxxxx`, none of the secrets appear, and the 
plain header is logged as is.
   - Fails on main: `Authorization: xxxxx` is not logged (the line is 
`Authorization: Bearer secret-token`).
   - camel-http module tests: 322 run, 0 failures, 9 skipped (plus 9 in the 
second surefire execution), BUILD SUCCESS.
   
   _Claude Code on behalf of davsclaus_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to