Repository navigation
Make the markdown/frontmatter regexes linear (CodeQL polynomial-redos) - #89
Merged
Merged
Conversation
…dos) CodeQL's first scan of the repo flagged ten regexes whose whitespace or wildcard runs overlap, so a crafted line makes them backtrack quadratically. Each is rewritten so no two adjacent repetitions can match the same text, or replaced by a loop or an indexed search: - lenientScalars: the value starts at its first non-space. - FOOTNOTE_DEF_RE: `:(.*)` without `\s*` or `$`; callers already trim. - list items (citations, migrate): one `listItemText()` helper, `\s+(\S.*)` plus trimEnd, shared so both sides agree. - citation links: unanchored search with the prefix taken by index instead of a lazy `^(.*?)`; no part of a candidate crosses a `[`, so the scan is linear even on bracket-heavy items. - separator trim before a link: a loop instead of `/[...]+$/`. - sourceId: dashes are already collapsed, so `^-|-$`. - linkFieldValues: the wikilink target is `[^|]*`. - firstHeading: `\s+(\S.*)` plus trimEnd. Behavior is unchanged on every line of every file in the repo (checked differentially). Three deliberate edge-case changes: a `#` heading with no text no longer yields a whitespace title; a CRLF footnote definition now parses; `[a [b](u)` yields the link text `b` (CommonMark), not `a [b`. Adds a regression test with the pumps CodeQL named, 200k chars each.
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configuration
📒 Files selected for processing: 4
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
The Windows CI job (added in #82) fails on main in vcs.test.ts: at a fresh git toplevel under tmpdir(), "auto" degraded to the filesystem provider. git prints the toplevel as C:/Users/runneradmin/... while tmpdir() is the 8.3-spelled C:\Users\RUNNER~1\..., and realpathSync does not reconcile them. `git rev-parse --show-prefix` is empty exactly at the toplevel, so use that and drop the path comparison.
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.
Resolves all ten open code scanning alerts (
js/polynomial-redos, lib.ts and migrate-doc.ts) from CodeQL's first scan of the repo.What changed
Each flagged regex had two adjacent repetitions that could match the same text (
\s+next to.*,.*\Snext to\s*$, a lazy^(.*?)ahead of a bracket class), so a crafted line made it backtrack quadratically. Each is rewritten so the repetitions cannot overlap, or replaced by a loop or an indexed search:lenientScalars(\s+)?)(.*)$(\S.*)?$FOOTNOTE_DEF_RE:\s*(.*)$:(.*), callers already trim\s+(.*\S)\s*$twicelistItemText():\s+(\S.*)+trimEnd^(.*?)\[([^\]]*)\]\(…[/[\s:—–-]+$/sourceId^-+|-+$^-|-$linkFieldValues\[\[(.*?)(?:|.*)?\]\]firstHeading^#\s+(.+?)\s*$^#\s+(\S.*)+trimEndVerification
.md/.ts/.tomlfile in the repo (183k lines, 1.1M comparisons): no differences on real content.tsgo --noEmitclean.Deliberate edge-case changes
#heading with no text no longer yields a single-space title; the search moves on to the next heading.[^a]: text\r) now parses; before,$rejected it.[a [b](u)yields link textbwith prefix[a(CommonMark's reading), nota [b.Summary by CodeRabbit