Skip to content
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

Bugfix/auth header log fix #3674

Merged
merged 2 commits into from
Nov 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
public class TestnavLogbackEncoder extends LogstashEncoder {

// matches exactly 11 digits (\\d{11}) that are not immediately preceded ((?<!\\d)) or followed ((?!\\d)) by another digit.
private final Pattern pattern = Pattern.compile("(?<!\\d)\\d{11}(?!\\d)");

private final Pattern identNummer = Pattern.compile("(?<!\\d)\\d{11}(?!\\d)");
private final Pattern bearer = Pattern.compile("Bearer [a-zA-Z0-9\\-_.]+");
@Setter
private int maxStackTraceLength = 480;

Expand Down Expand Up @@ -113,24 +113,15 @@ private void appendStackTraceCauses(ThrowableProxy exception, StringWriter write
}

private String formatMessage(String message) {
var matcher = pattern.matcher(message);

if (!matcher.find()) {
return message;
}

matcher.reset();
var result = new StringBuilder();

while (matcher.find()) {
var match = matcher.group();
if (match.charAt(2) == '0' || match.charAt(2) == '1') {
var replacement = match.substring(0, 6) + "xxxxx";
matcher.appendReplacement(result, replacement);
message = identNummer.matcher(message).replaceAll(match -> {
if (match.group().charAt(2) == '0' || match.group().charAt(2) == '1') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strengt tatt vil if (match.group().charAt(2) < '4') være bedre da det også fanger opp NPID som har +2 på måned i prod

return match.group().substring(0, 6) + "xxxxx";
}
}
matcher.appendTail(result);
return match.group();
});

message = bearer.matcher(message).replaceAll("REDACTED_BEARER");

return result.toString();
return message;
}
}