fix(code-scanner): remove ReDoS and TOCTOU risks CodeQL found in secrets - #52
Merged
Merged
Conversation
CodeQL flagged three findings in the secrets subsystem after it merged. All
three are real, and they matter more here than they would elsewhere: this code
reads file content and operator config that the scanner does not control, so a
crafted file becomes a denial of service against the security agent itself —
a worse outcome than any placeholder a bound might cause us to miss.
js/polynomial-redos rules.ts `<[^>]+>` in the placeholder pattern
js/polynomial-redos index.ts `/^\*+/` trimming an allowlist entry
js/file-system-race index.ts stat(path) then readFile(path)
Fixes:
- the placeholder pattern is bounded (`<[^<>]{1,64}>`, `0{8,12}`)
- star-trimming is a plain loop, not a regex, in both isAllowed and
matchesIgnore. CodeQL only flagged the first; the second has the identical
weakness and is fixed too rather than waiting to be reported
- size check and read now go through ONE file handle. stat-then-read is a
time-of-check/time-of-use gap: on a host where an attacker can write to a
scanned directory, the bytes examined need not be the bytes measured
Four regression tests assert 50,000-character pathological inputs complete
within a second.
90 tests.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
vu1nz Security Review0 finding(s) in PR #? No security issues found. |
ralyodio
added a commit
that referenced
this pull request
Jul 28, 2026
The secrets subsystem's stat-then-read gap was fixed in #52; sast had the identical pattern and CodeQL flagged it on the next scan. Same fix: one file handle for the size check and the read, so the bytes analysed are the bytes measured. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CodeQL flagged three findings in
modules/code-scanner/src/secrets/after PR #50 merged. All three are real.They matter more here than they would in most code: this module reads file content and operator config that the scanner does not control. An unbounded quantifier turns a crafted file into a denial of service against the security agent itself — which is a worse outcome than the missed placeholder that a bound might cost.
js/polynomial-redosrules.ts<[^>]+>in the placeholder patternjs/polynomial-redosindex.ts/^\*+/trimming an allowlist entryjs/file-system-raceindex.tsstat(path)thenreadFile(path)Fixes
<[^<>]{1,64}>,0{8,12}.isAllowedandmatchesIgnore. CodeQL only flagged the first; the second has the identical weakness, so it's fixed now rather than waiting to be reported.stat(path)followed byreadFile(path)is a time-of-check/time-of-use gap: the path can be replaced between the calls, so the bytes examined need not be the bytes measured. On a host where an attacker can write to a scanned directory, that's a way to feed the scanner something other than what it approved. Holding a descriptor and stat-ing that closes the gap.Verification
Four regression tests feed 50,000-character pathological inputs and assert completion within a second. 90 tests total, build clean.