fix: harden three regexes flagged by CodeQL polynomial-redos#55
Merged
nahiyankhan merged 1 commit intomainfrom Apr 24, 2026
Merged
fix: harden three regexes flagged by CodeQL polynomial-redos#55nahiyankhan merged 1 commit intomainfrom
nahiyankhan merged 1 commit intomainfrom
Conversation
- FONT_SUFFIXES: dropped the leading \s* that created an ambiguous split
with the word alternation; added a \s+ squash before .trim() so any
leftover whitespace is still collapsed.
- scanHeadings: /^(#{1,6})\s+(.*?)\s*$/ → /^(#{1,6})\s(.*)$/ with .trim()
on the captured text. \s and . both match space characters, so the
original had overlapping quantifiers.
- slug: rewrote as a single imperative O(n) pass. The regex chain kept
getting flagged even after splitting /^-+|-+$/g in two.
Semantics preserved — verified against the existing layout tests and a
broader slug input set (leading/trailing/interior dash runs, mixed case,
unicode dropouts).
Co-Authored-By: Claude Opus 4.7 (1M context) <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.
Summary
Three regexes in
ghost-drifttripped CodeQL'sjs/polynomial-redoscheck when the compileddist/is scanned downstream (surfaced via squareup/ghost-fleet#17). All three were flagged for ambiguous quantifier overlap, not actual ReDoS exposure — inputs are short and controlled — but tightening them is cheap and clears the scanner.FONT_SUFFIXES(embedding/compare.ts) — dropped the leading\s*that created an ambiguous split with the word alternation. Added a\s+ → " "squash before.trim()so any leftover whitespace is still collapsed.scanHeadings(fingerprint/layout.ts) —/^(#{1,6})\s+(.*?)\s*$/→/^(#{1,6})\s(.*)$/+.trim().\sand.both match space characters; the original had overlapping quantifiers.slug(fingerprint/layout.ts) — rewrote as a single imperative O(n) pass. The regex chain kept being flagged even after splitting/^-+|-+$/gin two.Test plan
pnpm test— all 182 tests pass (incl.layout.test.ts,compare.test.ts,fragments.test.ts)pnpm check— biome + typecheck + file-sizes + docs + cli-manifest all greenpnpm build— clean🤖 Generated with Claude Code