Skip to content

fix: resolve open GitHub security findings - #630

Merged
naorpeled merged 1 commit into
masterfrom
claude/bowser-security-findings-615c1e
Aug 30, 2026
Merged

naorpeled merged 1 commit into
masterfrom
claude/bowser-security-findings-615c1e

Conversation

@naorpeled

@naorpeled naorpeled commented Aug 30, 2026 •

Copy link
Copy Markdown
Collaborator

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-Agent strings, and four of them ran in quadratic time. Measured through Bowser.parse(), before → after:

Regexp Pathological UA Before After
/^(.*)\/(.*) / "/a" × 60000 6723ms <5ms
/^(.*)\/(.*)[ \t]\((.*)/ "/a" × 60000 6767ms <5ms
Linespider version "linespider-" × 20000 >30s <5ms
SlackBot version "slackbot-" × 20000 >30s <5ms

The two .* regexps have two unbounded .* before a required literal, which makes the split ambiguous and backtracks O(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, only version is 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.js locks 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 full Bowser.parse() output rather than the regexps in isolation:

Input bucket Compared Differences
Real acceptance corpus 270 0
Exhaustive — every string ≤9 chars over a / space ( tab ~2,400,000 0
Mutated real UAs (1–5 random edits) 150,000 0
Random UA-shaped strings (exercises the fallback) 150,000 0
Random structural strings, up to 60 chars 200,000 0
Bot names × suffix length 0–80 × separators × versions ~54,000 640

The 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.yml and draft-or-update-next-release.yml had no permissions block and inherited the default token. Both now declare least privilege, matching publish.yml and pull-request.yml.

Dependabot — 22 alerts, pnpm audit 29 → 0

All are development scope. 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:

  • jsdoc 3 → 4 (with docdash 1 → 2) drops taffydb, and picks up current markdown-it / linkify-it.
  • coveralls → coveralls-next@6 drops request, which is deprecated and unpatched, and with it form-data, qs@6.5.x, uuid@3 and tough-cookie@2. Same coveralls bin and same stdin contract; lcov conversion verified locally against real coverage output.

The rest:

  • 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, so dependents asking for the old major still resolve. Each carries its GHSA id so it is clear when a pin can be dropped.

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 both src/ and the built es5.js
  • pnpm build, pnpm test:package (25 checks), and doc generation on the upgraded jsdoc/docdash all pass
  • pnpm install --frozen-lockfile passes, so CI installs cleanly

Out of scope, flagged for a maintainer

  • publish.yml declares id-token: write at the top level, so the build job inherits it although only publish needs it. Worth scoping to the job, but I left release publishing alone.
  • Secret scanning returned 404 — either not enabled on the repo or outside my token's scopes — so I could not check it.

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Resolve ReDoS, dependency, and workflow security findings

🐞 Bug fix 🧪 Tests ⚙️ Configuration changes 🕐 40+ Minutes

Grey Divider

AI Description

• Makes UA parsing linear for four attacker-controlled ReDoS patterns.
• Upgrades and overrides development dependencies to eliminate known audit vulnerabilities.
• Restricts workflow tokens and adds ReDoS performance regression coverage.
Diagram

graph TD
  UA["User Agent"] --> Parser["Browser Parser"]
  ReDoS["ReDoS Tests"] --> Parser
  Workspace["Security Overrides"] --> Lockfile["Resolved Toolchain"] --> CI["CI and Docs"]
  Workflows["GitHub Workflows"] --> Permissions["Scoped Tokens"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Replace vulnerable regexes with manual scanners
  • ➕ Can provide explicit linear-time parsing guarantees
  • ➕ Avoids JavaScript regex backtracking behavior entirely
  • ➖ More invasive change to mature parsing behavior
  • ➖ Creates additional parsing code and compatibility surface
2. Upgrade all tooling to latest versions without overrides
  • ➕ Reduces explicit override maintenance
  • ➕ May remove more obsolete transitive packages
  • ➖ Broadens compatibility risk beyond the security findings
  • ➖ Cannot reliably preserve dependency-major expectations
  • ➖ Produces a larger, less focused review

Recommendation: Keep the targeted regex constraints, parent-package replacements, and major-aware transitive overrides. This approach closes the findings with smaller behavioral and tooling changes than custom parsing or wholesale dependency modernization; reviewers should specifically confirm the intentional 64-character bot-suffix limit and periodically retire overrides as parent packages adopt patched versions.

Files changed (7) +346 / -563

Bug fix (1) +10 / -4
parser-browsers.jsEliminate polynomial UA regex backtracking +10/-4

Eliminate polynomial UA regex backtracking

• Bounds optional Linespider and SlackBot suffixes and makes fallback version captures slash-exclusive. The changes remove quadratic behavior on hostile user-agent strings, with an intentional 64-character suffix limit for the two bots.

src/parser-browsers.js

Tests (1) +43 / -0
redos.jsAdd adversarial ReDoS timing regressions +43/-0

Add adversarial ReDoS timing regressions

• Adds four AVA tests for repeated bot tokens and slash-heavy fallback inputs. Each test parses a previously pathological UA within a 500 ms budget to guard against polynomial regressions.

test/unit/redos.js

Other (5) +293 / -559
draft-or-update-next-release.ymlScope release-drafter repository permissions +6/-0

Scope release-drafter repository permissions

• Declares only 'contents: write' and 'pull-requests: read', matching release-drafter's release update and changelog needs instead of inheriting broader defaults.

.github/workflows/draft-or-update-next-release.yml

merge-to-master.ymlRestrict master-build workflow to read access +5/-0

Restrict master-build workflow to read access

• Adds a workflow-level 'contents: read' permission because repository writes are unnecessary for building, testing, and external coverage reporting.

.github/workflows/merge-to-master.yml

package.jsonReplace vulnerable development tooling +5/-5

Replace vulnerable development tooling

• Replaces legacy Coveralls with 'coveralls-next' and upgrades Docdash, gh-pages, JSDoc, and Testem. These changes remove unpatched legacy dependency chains while preserving existing development commands.

package.json

pnpm-lock.yamlResolve the development graph to patched packages +250/-554

Resolve the development graph to patched packages

• Regenerates the lockfile for upgraded direct tools and workspace security overrides. Vulnerable legacy chains such as 'request', 'taffydb', old Markdown tooling, and their transitive packages are removed or replaced.

pnpm-lock.yaml

pnpm-workspace.yamlPin vulnerable transitives to patched release lines +27/-0

Pin vulnerable transitives to patched release lines

• Adds documented pnpm overrides for brace-expansion, js-yaml, ws, socket.io-parser, linkify-it, markdown-it, got, and body-parser. Overrides target patched versions while preserving existing major lines where possible.

pnpm-workspace.yaml

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can enable the Remediation agent and Qodo fixes findings in a dedicated fix PR

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

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.
@naorpeled
naorpeled force-pushed the claude/bowser-security-findings-615c1e branch from 0db82fa to 982a91d Compare August 30, 2026 18:01
@naorpeled
naorpeled merged commit 1d79234 into master Aug 30, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant