Skip to content

chrome-nav.js: validate the page path the chrome restore keys on - #2901

Merged
chalin merged 8 commits into
docsy:mainfrom
chalin:chalin-m24-chrome-nav-guard-2026-1029
Oct 30, 2026
Merged

chalin merged 8 commits into
docsy:mainfrom
chalin:chalin-m24-chrome-nav-guard-2026-1029

Conversation

@chalin

@chalin chalin commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator
  • Fixes https://github.com/docsy/docsy/security/code-scanning/24 (CodeQL js/xss-through-dom on main)
  • Scope:
    • currentPath() limited to same-origin paths that re-parse to themselves, whatever the data-canonical-path hint or the request URL supplies
    • the composed language link parsed the same way before it's written
    • red-first probes for hostile hints, the request-path fallback, and the /<lang>//host/… composition
    • scripts-goldens refresh (bundle and fingerprint)
  • Out of scope:
    • an origin check on the version-link prefix (base), legitimately cross-origin
    • a changelog entry, the hardening changing nothing for conforming sites
    • comment hygiene in untouched code (section banners, the canonical test's header and captions), pre-existing
  • Verified: local CodeQL 2.27.3 (js/xss-through-dom over theme/assets/js) reports 2 results on main, both sourced at the data-canonical-path read, and 0 on this branch (the repo's default setup doesn't analyze fork PRs, hence the local run)
  • Why:
    • follows up alerts 13 and 14, dismissed as false positives on 2026-09-18
    • clears the alert on the merits: the query flags tainted text anywhere in an href, so only a parser-produced path passes
    • validates with the platform URL parser rather than encoding or path-shape tests (encodeURI leaves javascript: intact; string tests miss spellings the parser catches)
  • Review start: sameOriginPath in theme/assets/js/chrome-nav.js

- Hardens the `shared`-mode restore: the canonical-path hint and the request-path fallback both pass one same-origin-path check before any selector href is rebuilt from them; no change for conforming sites
- Clears the CodeQL `js/xss-through-dom` alert on the merits (parse and check origin, not encode), closing the hardening filed at the 2026-09-18 triage
- Probe in chrome-canonical.test.mjs is red against the previous code; the goldens delta is the bundle fingerprint only
@chalin chalin added this to the 0.19.0 milestone Oct 29, 2026
@chalin
chalin requested a review from a team October 29, 2026 20:53
@netlify

netlify Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for docsydocs ready!

Name Link
🔨 Latest commit 02c06ff
🔍 Latest deploy log https://app.netlify.com/projects/docsydocs/deploys/6ae3e774ca6ed6f7b2213a9f
😎 Deploy Preview https://deploy-preview-2901--docsydocs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

- Renames `raw` to `urlOrPath` (what `sameOriginPath` accepts) and `hint` (the canonical-path attribute); bundle bytes unchanged, so no goldens delta
- Drops the one-use local in readCanonicalPath: a falsy input is the helper's null, so the contract reads "anything falsy or unsafe yields null"; goldens follow the bundle
- An origin-inheriting scheme (`blob:`) passes the origin check with a non-path `pathname`, so the guard now requires the leading `/` too (r1.1)
- The request-path fallback had no probe of its own: a hint-less page at a canonical and at a protocol-relative request URL, red against main (r1.3); the probe comments keep to input classes and point at the guard (r1.4)
- The guard moves to the sink that composes: `langHome + rel` is parsed and written only when it stays same-origin, so a `//` after the language prefix can't read as a host; the path-shape test goes, the parser decides (r2.1, r2.6)
- Resolves against `location.href`, so `file:`-served sites keep their active state (r2.2)
- Probes: one hostile hint per check, a foreign-host request path restores the root navbar, the lang fixture gets the `/ja//host/…` case, red on main
- A same-origin parse isn't enough when the pathname is then written as a relative reference: `/.//host/…` drops its dot segment and reads back as a host. The pathname now round-trips through the parser before it's returned (r3.1); the dot-segment hint joins the probes
- Declaration comments keep to contracts; the gotchas sit beside their checks (r3.2, r3.3)
- The re-parse compared origins only, so a doubled own-host prefix (`//site//site//host/…`) still came back as `//host/…`; the path must now be a fixed point of the parser (same origin, same pathname), which also retires the `blob:` string test (r4.1)
- Probes: double-wrap hints in both files, the `blob:` value pointed at another page, a sanity match before the lang probe strips the hint; red on the previous code (r4.5, r4.6)
…link in the lang probe

- The doubled own-host form re-parses to the same origin with a different path, not to another host; the comment says so (r5.1), and the clause restating `if (target)` goes (r5.2)
- The lang probe asserts the donor's root link, not a path shape, so a composition that wrote a wrong same-origin page would fail (r5.4)
@chalin
chalin merged commit 46ecd3f into docsy:main Oct 30, 2026
14 checks passed
@chalin
chalin deleted the chalin-m24-chrome-nav-guard-2026-1029 branch October 30, 2026 01:04
@chalin chalin modified the milestones: 0.19.0, 0.18.1 Oct 30, 2026
chalin added a commit to chalin/docsy that referenced this pull request Oct 31, 2026
Changelog v0.18.1: credit the contributed tabpane fix (docsy#2869)

Changelog v0.18.1: Security line for the chrome-restore hardening (docsy#2901)

Link cache: docsy#2869, docsy#2901, docsy#2910

Changelog v0.18.1: the Security line links the chrome guide
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