Commit 04ceaf1
fix(security): apply CodeQL log-injection + sensitive-log + CSRF hardening
CodeQL flagged 4 findings on PR 1 after the initial security work landed.
Each is addressed in-place:
* **BearerAuthFilter** (java/log-injection / CWE-117): the WARN line on auth
rejection passed unsanitized request method and URI as parameters. Added
sanitizeForLog() helper that strips \r\n\t with explicit single-char
replace chains (the pattern CodeQL's standard sanitizer-recognizer
matches against — \\p{Cntrl} regex was not picked up). Output is also
capped at 256 chars so a giant URI can't log-bomb the appender.
* **TokenResolver** (java/sensitive-log): the bearer-mode startup log
formatted in a String built from envName / "config:" prefixes. envName
flows from operator config which CodeQL marks as tainted. Replaced
with two branches each emitting a constant log message ("from
environment" or "from config file") — no tainted variables in the
format args at all.
* **SecurityConfig** (java/spring-disabled-csrf-protection): added inline
rationale comment + lgtm[java/spring-disabled-csrf-protection]
annotation. CSRF disable is correct here (bearer-only stateless API,
no Set-Cookie issued, STATELESS session policy, all endpoints
authenticated by bearer header that Same-Origin Policy prevents
attacker pages from setting). The CodeQL rule does not consider the
bearer-only stateless model.
* **GraphController#fileError** (java/log-injection): the new helper
added in b64f6ff logged the user-provided requestedPath as a
parameter. Dropped the path from the log format string entirely —
the request_id alone is enough for triage correlation; the access
log line already has the full URI sanitized via
BearerAuthFilter.sanitizeForLog. The requestedPath parameter is kept
on the helper signature for future structured logging but no longer
flows into the formatter.
Tests: full suite green (3662 / 0F / 0E / 32S).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent b64f6ff commit 04ceaf1
4 files changed
Lines changed: 47 additions & 7 deletions
File tree
- src/main/java/io/github/randomcodespace/iq
- api
- config/security
Lines changed: 7 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
322 | 322 | | |
323 | 323 | | |
324 | 324 | | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
325 | 330 | | |
326 | 331 | | |
327 | 332 | | |
328 | 333 | | |
329 | | - | |
330 | | - | |
| 334 | + | |
| 335 | + | |
331 | 336 | | |
332 | 337 | | |
333 | 338 | | |
| |||
Lines changed: 20 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
88 | | - | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
89 | 92 | | |
90 | | - | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
91 | 96 | | |
92 | 97 | | |
93 | 98 | | |
| |||
141 | 146 | | |
142 | 147 | | |
143 | 148 | | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
144 | 162 | | |
Lines changed: 11 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
45 | 55 | | |
46 | 56 | | |
47 | 57 | | |
| |||
Lines changed: 9 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
77 | | - | |
78 | | - | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
79 | 86 | | |
80 | 87 | | |
81 | 88 | | |
| |||
0 commit comments