Skip to content

Commit

Permalink
Merge pull request #471 from jmartisk/mask-cookie
Browse files Browse the repository at this point in the history
Mask the value of Set-Cookie headers
  • Loading branch information
jmartisk authored Apr 18, 2024
2 parents fe57c36 + a4ac8fe commit 183a967
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,8 @@ private String inOneLine(MultiMap headers) {
headerValue = maskAuthorizationHeaderValue(headerValue);
} else if (headerKey.equals("api-key")) {
headerValue = maskApiKeyHeaderValue(headerValue);
} else if (headerKey.equals("Set-Cookie")) {
headerValue = maskCookieHeaderValue(headerValue);
}
return String.format("[%s: %s]", headerKey, headerValue);
})
Expand Down Expand Up @@ -408,6 +410,19 @@ private static String maskApiKeyHeaderValue(String apiKeyHeaderValue) {
return "Failed to mask the API key.";
}
}

private static String maskCookieHeaderValue(String cookieHeaderValue) {
try {
if (cookieHeaderValue.length() <= 4) {
return cookieHeaderValue;
}
return cookieHeaderValue.substring(0, 2)
+ "..."
+ cookieHeaderValue.substring(cookieHeaderValue.length() - 2);
} catch (Exception e) {
return "Failed to mask the cookie value.";
}
}
}

class ApiMetadata {
Expand Down

0 comments on commit 183a967

Please sign in to comment.