feat(enrichment): ReDoS scanner on added/changed regex - #1601
Conversation
Adds a REES analyzer that flags regex literals introduced by the PR (added
diff lines) vulnerable to catastrophic backtracking: a group quantified by an
unbounded quantifier (+, *, {n,}) whose body also contains an unbounded
quantifier (the classic (a+)+ / (\w+\.)+ shape that turns attacker-controlled
input into a DoS). This is the structural analysis the no-checkout in-prompt
reviewer cannot do; the brief block is spliced into the review (additive,
fail-safe).
Self-contained and pure-CPU: no network and no new runtime dependency. A
structural detector (not a bundled recheck/redos-detector binary), so no
Dockerfile/runtime-image change. Structural-only keeps precision high: linear
(abc)+, bounded (a+){2,4}, and non-quantified (a|b)+ are not flagged.
Closes JSONbored#1503.
The LITERAL_RE / CTOR_RE extractors were themselves vulnerable to catastrophic backtracking: their alternations overlap (the char-class branch and the single-char fallback both match '[' / ']'), so adversarial diff input such as many empty '[]' classes with no closing slash forced exponential backtracking — the line-length cap does not bound 2^n. Replace both regexes with a single linear character scan (escapes and '[...]' classes transparent to the closing '/', plus a RegExp(...) string-arg reader), so the extractor visits each char once and can never be the DoS it exists to detect. Extraction semantics are preserved; added a regression test feeding the adversarial char-class input.
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
|
Tip 🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩🟩 ✅ Gittensory review — safe to merge
✅ Approved — safe to merge Review summary
Nits — 5 non-blocking
Review context
Contributor next steps
Signal definitions
Review detailsGenerated from public PR metadata and the diff. Advisory only; deterministic signals remain authoritative. Clean, well-scoped analyzer addition. The linear hand-scanner in `extractRegexSources` correctly sidesteps self-ReDoS (the central design constraint), the structural `hasCatastrophicBacktracking` detector correctly handles escapes, char classes, bounded `{n,m}` quantifiers, and nested groups, and wiring through `brief.ts`/`render.ts`/`types.ts` follows the established analyzer pattern exactly. Two issues — one a meaningful false-negative class, one a subtle false-positive edge case in the `{,}` quantifier path — are worth tightening before ship. Nits (5)
🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed 💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →. Checked by Gittensory, a quiet PR intelligence layer for OSS maintainers.
|
Closes #1503.
Adds a REES analyzer that flags regex literals introduced by the PR (added
+diff lines) vulnerable to catastrophic backtracking — a group quantified by an unbounded quantifier (+,*,{n,}) whose body also contains an unbounded quantifier (the classic(a+)+/(\w+\.)+shape that turns attacker-controlled input into a DoS). This is exactly the heavy/structural analysis the no-checkout in-prompt reviewer cannot do; the brief block is spliced into the review (additive + fail-safe).Approach
Self-contained, pure-CPU — no network and no new runtime dependency. A structural detector rather than a bundled
recheck/redos-detectorbinary, so there is no Dockerfile/runtime-image change. Structural-only keeps precision high: linear shapes like(abc)+, bounded(a+){2,4}, and non-quantified alternation(a|b)+are not flagged./.../flagsliterals in regex position +new RegExp("…")/RegExp('…')constructor args. The extractors use only non-overlapping alternations + negated classes, so they are themselves linear-time (no self-ReDoS).MAX_FINDINGS, per-line length guard); the reported pattern is truncated and rendered throughsafeCodeSpan(public-safe — no matched value echoed).Files (all inside
review-enrichment/, per the established analyzer pattern)src/types.ts—RedosFindingtype +redosBriefFindingskeysrc/analyzers/redos.ts— the analyzer (pure helpers +scanRedosentrypoint)src/brief.ts— registered in theANALYZERSregistrysrc/render.ts— public-safe brief blocktest/enrichment.test.ts— detector unit tests, line-cited scan, entrypoint cap, render sanitization, and abuildBriefintegration testValidation
npm test(build +node --test) insidereview-enrichment/: 43/43 pass (5 new).git diff --checkclean; enginesrc/**untouched (outside the engine tsc/vitest/codecov scope — zero conflict).