-
Notifications
You must be signed in to change notification settings - Fork 207
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
Fix an issue that exception messages are masked #4416
Conversation
Signed-off-by: Hai Yan <[email protected]>
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.
@oeyh , Did you test this? I'm unsure if the way Log4j operates is to give all the parameters, or just the ones that will be formatted into the string.
If it provides all arguments, you will need to modify the code below to keep any object that inherits from Throwable
.
Lines 41 to 48 in e341d7d
// TODO: apply masking on Event type parameter only for EVENT marker. | |
if (marker != null && SENSITIVE_MARKER_NAMES.contains(marker.getName())) { | |
final Object[] maskPatternArguments = new Object[message.getParameters().length]; | |
Arrays.fill(maskPatternArguments, MASK_PATTERN); | |
toAppendTo.append(MessageFormatter.arrayFormat(message.getFormat(), maskPatternArguments).getMessage()); | |
} else { | |
toAppendTo.append(message.getFormattedMessage()); | |
} |
@dlvenable In my experience, you can give Log4j as many arguments as you want and it will add them to the I have used this approach in a logging extension for SAP BTP to provide additional custom fields for log messages: https://github.com/SAP/cf-java-logging-support/blob/26565dc37aa30793f1f5a4684e8e17586bdcf59f/cf-java-logging-support-log4j2/src/main/java/com/sap/hcp/cf/log4j2/layout/supppliers/LogEventUtilities.java#L18-L21 and https://github.com/SAP/cf-java-logging-support/blob/26565dc37aa30793f1f5a4684e8e17586bdcf59f/cf-java-logging-support-core/src/main/java/com/sap/hcp/cf/logging/common/serialization/AbstractContextFieldSupplier.java#L22-L27 |
@dlvenable @KarstenSchnitter Thanks for the comments. I did a test where I called: LOG.error(SENSITIVE, "Failed to process content: [{}]", content, e); and I get these logs with
So this should work. |
Turns out, by default, pattern converter doesn't handle throwables (see this code snippet). So our custom pattern converter will keep the exception message as is. |
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 am not sure, whether including the exception might expose event data or not. For example the JsonProcessingException could contain a text indicating the spot where the error occurred. This message might contain a snippet of the parsed message. Not sure, if it really behaves that way though.
Signed-off-by: Hai Yan <[email protected]>
That may be a concern that we can address separately. The markers we have today cannot filter sensitive information from stack trace. But we do want to show the stack trace for troubleshooting. |
The intention of the |
Description
Show exception messages instead of masking them through the SENSITIVE marker.
I checked all usages of SENSITIVE and EVENT in the repo and seems that all issues are in this S3DlqWriter.java file.
Issues Resolved
Resolves #3375
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.