Skip to content

Commit f3dc027

Browse files
aksOpsclaude
andcommitted
fix(security): sanitize request method/URI in RateLimitFilter log (CWE-117)
CodeQL flagged RateLimitFilter#doFilterInternal:116 with java/log-injection — same root cause as the BearerAuthFilter finding fixed earlier in this PR: request.getMethod() and request.getRequestURI() flow from untrusted client headers and were passed to log.warn unsanitized. Reuses BearerAuthFilter.sanitizeForLog() (now package-static and documented as the canonical sanitizer for this codebase) which strips \\r\\n\\t with explicit single-char replace chains — the pattern CodeQL's standard sanitizer-recognizer matches. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 664cf42 commit f3dc027

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/main/java/io/github/randomcodespace/iq/config/security/RateLimitFilter.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,14 @@ protected void doFilterInternal(HttpServletRequest request,
113113
long retryAfterSec = Math.max(1L,
114114
Duration.ofNanos(probe.getNanosToWaitForRefill()).toSeconds());
115115
String requestId = currentRequestId();
116+
// CWE-117 / CodeQL java/log-injection: request method and URI flow
117+
// from untrusted client headers; sanitize before logging via
118+
// BearerAuthFilter.sanitizeForLog (strips \r\n\t with explicit
119+
// single-char replace chains — the pattern CodeQL recognizes).
116120
log.warn("Rate-limited: {} {} (request_id={}, retry_after={}s)",
117-
request.getMethod(), request.getRequestURI(), requestId, retryAfterSec);
121+
BearerAuthFilter.sanitizeForLog(request.getMethod()),
122+
BearerAuthFilter.sanitizeForLog(request.getRequestURI()),
123+
requestId, retryAfterSec);
118124
// 429 — jakarta.servlet doesn't define a constant for this in all versions.
119125
response.setStatus(429);
120126
response.setHeader("Retry-After", String.valueOf(retryAfterSec));

0 commit comments

Comments
 (0)