File tree Expand file tree Collapse file tree 1 file changed +6
-6
lines changed
src/main/java/com/uid2/shared/logback Expand file tree Collapse file tree 1 file changed +6
-6
lines changed Original file line number Diff line number Diff line change 33import ch .qos .logback .classic .PatternLayout ;
44import ch .qos .logback .classic .spi .ILoggingEvent ;
55
6- import java .util .Map ;
76import java .util .regex .Pattern ;
87
98public class MaskingPatternLayout extends PatternLayout {
10- private static final Pattern maskPattern = Pattern .compile ("\\ S+s3\\ .amazonaws\\ .com/\\ S*X-Amz-Security-Token=\\ S+" );
11- private static final String maskBroadCheckSubstring = "X-Amz-Security-Token=" ;
12- private static final String maskedRedaction = "REDACTED - S3" ;
9+ private static final Pattern AWS_PRESIGNED_URL_REGEX_PATTERN = Pattern .compile ("\\ S+s3\\ .amazonaws\\ .com/\\ S*X-Amz-Security-Token=\\ S+" );
10+ private static final String AWS_SECURITY_TOKEN_HEADER = "X-Amz-Security-Token=" ;
11+ private static final String AWS_PRESIGNED_URL_REDACTION_MASK = "REDACTED - S3" ;
1312
1413 @ Override
1514 public String doLayout (ILoggingEvent event ) {
@@ -22,8 +21,9 @@ private String mask(String message) {
2221 }
2322
2423 String maskedMessage = message ;
25- if (maskedMessage .contains (maskBroadCheckSubstring )) {
26- maskedMessage = maskPattern .matcher (maskedMessage ).replaceAll (maskedRedaction );
24+ // Perform a broad check to potentially skip regex
25+ if (maskedMessage .contains (AWS_SECURITY_TOKEN_HEADER )) {
26+ maskedMessage = AWS_PRESIGNED_URL_REGEX_PATTERN .matcher (maskedMessage ).replaceAll (AWS_PRESIGNED_URL_REDACTION_MASK );
2727 }
2828
2929 return maskedMessage ;
You can’t perform that action at this time.
0 commit comments