Repository navigation
fix: resolve open GitHub security findings - #630
Conversation
PR Summary by QodoResolve ReDoS, dependency, and workflow security findings
AI Description
Diagram
High-Level Assessment
Files changed (7)
|
Code Review by Qodo🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)
Great, no issues found!Qodo reviewed your code and found no material issues that require reviewTip of the day💡 Did you know, you can enable the Remediation agent and Qodo fixes findings in a dedicated fix PR |
Code scanning (js/polynomial-redos, alerts #16 and #17) ------------------------------------------------------- bowser applies these regexps to attacker-controlled User-Agent strings, and four of them ran in quadratic time: * The "Something else" fallback used /^(.*)\/(.*) / and /^(.*)\/(.*)[ \t]\((.*)/. Two unbounded `.*` before a required literal make the split ambiguous, so a UA of "/a" repeated backtracks O(n^2). Greedy `(.*)` always picks the last `/` that still has the delimiter after it, so the second group can never span a `/` -- narrowing it to `[^/]*` is exactly equivalent and removes the ambiguity. Verified identical on 1,000,000 fuzzed inputs and on the full acceptance corpus. * The Linespider and SlackBot version regexps used `(?:-[-\w]+)?` before a required `[\s/]`. Since `[-\w]` and `[\s/]` are disjoint the backtracking is pure waste, but the engine still walks it once per start position, so "linespider-" repeated is quadratic. Bounding the run to `{1,64}` makes it linear; no real bot-name suffix approaches 64 characters. A sweep of all 253 regexp literals in src/ (fuzzed for superlinear scaling, with the four pre-fix patterns used to confirm the detector works) reports no remaining superlinear regexps. test/unit/redos.js locks this in. Actions (actions/missing-workflow-permissions, alerts #5 and #15) ----------------------------------------------------------------- merge-to-master.yml and draft-or-update-next-release.yml had no `permissions` block and so inherited the default token. Both now declare least privilege, matching publish.yml and pull-request.yml. Dependabot (22 open alerts, all development scope) -------------------------------------------------- bowser ships no runtime dependencies, so none of these reached consumers, but they were live in CI. `pnpm audit` goes from 29 advisories to 0: * jsdoc 3 -> 4 (with docdash 1 -> 2) drops taffydb, which has no patched release, and picks up current markdown-it/linkify-it. * coveralls -> coveralls-next 6 drops `request`, which is deprecated with no patched release, along with form-data, qs 6.5.x, uuid 3 and tough-cookie 2. Same `coveralls` bin and same stdin contract; lcov conversion verified. * gh-pages 3 -> 6 clears the critical prototype pollution advisory. * pnpm overrides pin the remaining transitive-only advisories to the lowest patched release on each existing major. Verified: pnpm audit clean, lint clean, 346 tests pass (the acceptance corpus runs against both src/ and the built es5.js), build, package smoke test, and doc generation.
0db82fa to
982a91d
Compare
Resolves every open security finding on the repo: 4 code scanning alerts and 22 Dependabot alerts.
Code scanning
ReDoS —
js/polynomial-redos(#16, #17, high)bowser applies these regexps to attacker-controlled
User-Agentstrings, and four of them ran in quadratic time. Measured throughBowser.parse(), before → after:/^(.*)\/(.*) /"/a"× 60000/^(.*)\/(.*)[ \t]\((.*)/"/a"× 60000"linespider-"× 20000"slackbot-"× 20000The two
.*regexps have two unbounded.*before a required literal, which makes the split ambiguous and backtracksO(n²). Greedy(.*)always picks the last/that still has the delimiter after it, so the second group can never span a/— narrowing it to[^/]*is exactly equivalent and removes the ambiguity.The Linespider and SlackBot regexps use
(?:-[-\w]+)?before a required[\s/]. Because[-\w]and[\s/]are disjoint the backtracking is pure waste, but the engine still walks it once per start position, so a repeated-token UA is quadratic. Bounding the run to{1,64}makes it linear.Note
The
{1,64}bound is the one deliberate behaviour change: a bot-name suffix longer than 64 characters no longer yields a version. Real suffixes are ~13–22 characters (Slackbot-LinkExpanding), so this is unreachable in practice, and it degrades gracefully — browser name and platform are still detected, onlyversionis dropped.The bound is not free, so it is deliberately modest. Hostile-input cost scales with it on both engines tested (220k-char UA): V8 3.3ms at 64 → 41ms at 1024; JavaScriptCore 4ms at 64 → 30ms at 1024. All bounds are linear in input length; only the constant grows. Raising the bound is behaviour-safe if ever needed — it is strictly monotonic (verified: over 300,000 matching inputs, no match is lost going 64 → 256 → unbounded, so raising only ever adds matches back).
Atomic-group emulation (
(?=([-\w]+))\1) was measured and does not help — the lookahead still scans the run once per start position.I also swept all 253 regexp literals in
src/for superlinear scaling, first validating the detector against the four pre-fix patterns (4/4 caught). No other superlinear regexp remains.test/unit/redos.jslocks this in; all four tests were confirmed failing before the fix.Equivalence evidence
The old parser (from
master) and the new one were run side by side over 2,954,636 user-agent strings, comparing fullBowser.parse()output rather than the regexps in isolation:a/space(tabThe exhaustive bucket is every possible string up to length 9 over exactly the characters the changed regexps branch on — not a sample. The 640 differences are all the documented
{1,64}bound: the shortest diverging suffix is 65 characters, and every divergence has a suffix >64.Missing workflow permissions (#5, #15, medium)
merge-to-master.ymlanddraft-or-update-next-release.ymlhad nopermissionsblock and inherited the default token. Both now declare least privilege, matchingpublish.ymlandpull-request.yml.Dependabot — 22 alerts,
pnpm audit29 → 0All are
developmentscope. bowser ships no runtime dependencies, so none reached consumers, but they were live in CI.Two had no patched release at all, so an override could not fix them — the parent had to be replaced:
jsdoc3 → 4 (withdocdash1 → 2) dropstaffydb, and picks up currentmarkdown-it/linkify-it.coveralls→coveralls-next@6dropsrequest, which is deprecated and unpatched, and with itform-data,qs@6.5.x,uuid@3andtough-cookie@2. Samecoverallsbin and same stdin contract; lcov conversion verified locally against real coverage output.The rest:
gh-pages3 → 6 clears the critical prototype pollution advisory.Verification
pnpm audit— no known vulnerabilities (was 29 advisories)pnpm lint:check— clean (1 pre-existing warning, unrelated)pnpm test— 346 tests pass, including all 270 acceptance UAs run against bothsrc/and the builtes5.jspnpm build,pnpm test:package(25 checks), and doc generation on the upgraded jsdoc/docdash all passpnpm install --frozen-lockfilepasses, so CI installs cleanlyOut of scope, flagged for a maintainer
publish.ymldeclaresid-token: writeat the top level, so thebuildjob inherits it although onlypublishneeds it. Worth scoping to the job, but I left release publishing alone.