CodeQL regex alerts (2026-10)
The public mirror runs CodeQL; this repository does not. The first sync with all workspace packages raised 12 alerts. Each was checked here by timing the original regex on CodeQL’s attack shape at the input limit the code actually enforces.
Real: fixed
| Code | Limit | Before | Fix |
|---|---|---|---|
SAFE_IMAGE (core/web/shared/preferences/document.ts) |
600 characters | 200 chars: > 20 s | Drop the repeated , name(…) group |
SVG sniff (packages/image/src/sanitize-format.ts) |
first 1 KiB | 256 bytes: > 20 s | (<!--…-->\s*)* → (<!--…-->\s*)? |
PDF stream blanking (packages/image/src/sanitize-scan.ts) |
10 MiB upload cap | 1 MB: 10.6 s | indexOf loop instead of a lazy regex |
The two regex fixes accept exactly the same strings: one lazy or [^;{}<>]* span already reaches
across what the repeated group matched, so the repetition only added backtracking. A fuzz run of
300,000 random inputs per pattern found no difference against the originals, and the PDF loop
returns the same output. Regression tests: core/web/tests/background-options.spec.ts and
packages/image/tests/sanitize-backtracking.spec.ts.
Bounded or false positive: unchanged
parseByteRange(media-nuxtmedia-cdn.ts): 44 ms at Node’s 16 KB header cap.- Trailing-slash trims
/\/+$/(media-client,media-nuxtmedia-local-s3.ts,media-public-url.ts): 43 ms at 16 KB; the inputs are config values or theHostheader. foucScript(core/web/shared/preferences/fouc.ts): the interpolated values are build-time constants, never user input.core/web/tests/syntax-entities.spec.ts: a test helper that reads rendered output, not a sanitizer.
Rule of thumb
Before rewriting a flagged regex, time it at the real input limit. If the repeated group can be
absorbed by a neighbouring * span, drop the repetition; otherwise replace it with a linear scan.