(Snyk) Fixed finding: "Improper Neutralization of CRLF Sequences in HTTP Headers"

This commit is contained in:
pixeebot[bot] 2025-04-26 22:05:24 +00:00 committed by GitHub
parent 5f8b208db4
commit 806d5e7a9b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -121,7 +121,7 @@ public class UserBasedRateLimitingFilter extends OncePerRequestFilter {
if (probe.isConsumed()) { if (probe.isConsumed()) {
response.setHeader( response.setHeader(
"X-Rate-Limit-Remaining", "X-Rate-Limit-Remaining",
Newlines.stripAll(Long.toString(probe.getRemainingTokens()))); stripNewlines(Newlines.stripAll(Long.toString(probe.getRemainingTokens()))));
filterChain.doFilter(request, response); filterChain.doFilter(request, response);
} else { } else {
long waitForRefill = probe.getNanosToWaitForRefill() / 1_000_000_000; long waitForRefill = probe.getNanosToWaitForRefill() / 1_000_000_000;
@ -141,4 +141,8 @@ public class UserBasedRateLimitingFilter extends OncePerRequestFilter {
.build(); .build();
return Bucket.builder().addLimit(limit).build(); return Bucket.builder().addLimit(limit).build();
} }
private static String stripNewlines(final String s) {
return s.replaceAll("[\n\r]", "");
}
} }