-
Notifications
You must be signed in to change notification settings - Fork 357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Redact HTTP headers on LoggingFeature #5025
Redact HTTP headers on LoggingFeature #5025
Conversation
…sts and responses
Hi, @senivam. Just noticed that I'm lowering the case on test assertions and I think that's not needed with the provided matcher. Please give me some time to check that. |
ContainsHeaderMatcher is case-insensitive for header names.
Confirmed. Change pushed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -165,6 +186,11 @@ | |||
* Client property for logging separator. | |||
*/ | |||
public static final String LOGGING_FEATURE_SEPARATOR_CLIENT = LOGGING_FEATURE_CLIENT_PREFIX + SEPARATOR_POSTFIX; | |||
/** | |||
* Client property for configuring headers to be redacted. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add The headers are semicolon-separated
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do. Please give me some time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushed changes to the Javadocs on the 3 variations of the property.
I checked if we could set a property multiple times and then get a collection, but it looked like that's not possible.
Can you confirm that? Please let me know if you think of a better way to do this.
core-common/src/main/java/org/glassfish/jersey/logging/ClientLoggingFilter.java
Show resolved
Hide resolved
} | ||
|
||
private static String normalize(String input) { | ||
return input.trim().toLowerCase(Locale.ROOT); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's OK. This code final String header = headerEntry.getKey();
is NPE safe and this code
this.headersToRedact = headersToRedact.stream()
.filter(Objects::nonNull)
.filter(Predicates.not(String::isEmpty))
.map(RedactHeaderPredicate::normalize)
.collect(Collectors.toSet());
is NPE safe. Nothing else calls that predicate.
As talked on #5014, this allows configuring
LoggingFeature
with a list of HTTP headers to have their value redacted when printing to logs. By default, the Authorization header is redacted.Example of a logged request/response with the Authorization header redacted (default behavior):
And an example with two headers configured to be redacted (overriding the default behavior of redacting the Authorization header):