Skip to content

feat(rules): rate cookie-flags and token-storage higher and name the hosts when third-party scripts run on the page #2089 - #2260

Merged
nc9 merged 1 commit into
mainfrom
boat/third-party-exposure-2089
Nov 22, 2026
Merged

nc9 merged 1 commit into
mainfrom
boat/third-party-exposure-2089

Conversation

@nc9

@nc9 nc9 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Summary

security/cookie-flags and security/token-storage now take into account who else runs code on the page. When the page's markup loads <script src> from another registrable domain, a session-like cookie without HttpOnly and a token written to web storage are rated one step higher (warn to fail). The finding names up to five third-party script hosts and counts the rest. With no third-party script the output is byte-identical to today.

Closes #2089

  • New helper packages/rules/src/security/third-party-script-hosts.ts: executable <script src> outside <noscript>, resolved against the page URL, http(s) only, registrable domain different from the page (tldts, as isThirdPartyScript already did). It returns sorted, deduplicated hostnames. isThirdPartyScript and EXECUTABLE_SCRIPT_TYPE moved here, and token-storage re-exports isThirdPartyScript.
  • cookie-flags: session-like cookies (default session names such as PHPSESSID, JSESSIONID, connect.sid, *_session, plus any name token-storage's isTokenKey accepts) move from cookie-httponly (warn) into a new cookie-httponly-third-party-scripts (fail) check. Other cookies keep the warning. Platform and CSRF exemptions are unchanged.
  • token-storage: findings on such a page fail instead of warning. For a write inside a third-party script, that script's own host is not counted. The external-script foldKey adds the host set, so a folded message never names a host a page does not load.
  • Data source: the page DOM, not site.externalAssets. externalAssets is only present when another rule turns on the external probe, so it can't be relied on.
  • Unread page (no parsed document): no hosts, so reports as today. security/cookie-flags is added to READS_PARSED_BUT_RUNS in unread-page-gate-1570.test.ts, with the reason given.

Acceptance criteria

  • Session-like cookie without HttpOnly plus third-party scripts gives one step higher (fail), names the hosts, capped with a count. Tests: cookie-flags.test.ts, "a session cookie without HttpOnly fails and names the third-party hosts" and "names five hosts and counts the rest, sorted and deduplicated".
  • token-storage localStorage/sessionStorage, same treatment. Tests: "an inline token write fails and names the third-party hosts" and "a sessionStorage write in an external script fails too, and folds per host set".
  • No third-party script means unchanged output. Tests deep-equal the output with first-party scripts to the bare-page output for both rules ("... exactly as before"). Existing test expectations in both files are unmodified and pass (cookie-flags gained only an import).
  • Text never calls a vendor malicious. It says "Any script on the page can read ...". Tests: "never calls a vendor malicious" in both files.
  • Fixtures cover both cases for both rules, and both docs pages describe the change (docs/rules/security/cookie-flags.mdx, token-storage.mdx, new section "Third-party scripts on the page").

Mutation check: forcing thirdPartyScriptHosts to return [] fails 8 of the new tests, and the "unchanged" tests still pass. Expected values are literals, not imported constants.

Gates

  • packages/rules: format:check, lint, typecheck (all three tsconfigs) pass.
  • CI rules step bun run scripts/test-suites.ts --run rules: 12658 pass, 0 fail (415 files).
  • Audit-engine goldens and identity: streaming-rules-canonical-golden, item-finding-identity, ignore-rule-cache-1262, ignore-timeout-cut-1419, build-headers-map: 31 pass. golden-finding-messages-229, docs-rule-pages, docs-category-table, apps/cli/tests/mcp/docs-sync: 16 pass.
  • docs/: make validate passes (tangly strict, links, glossary, rule-checks, 74 script tests).
  • bun scripts/changelog.ts check: OK. Entry changelog.d/2089-third-party-script-exposure.security.md.

Agent skill

The squirrelscan agent skill may want a line saying the new cookie-httponly-third-party-scripts check fails, and that token-storage findings can now be failures. This is noted for the maintainer; no skill change is in this PR.

Hold-list (security rule severity): draft for planning review.

…hosts when third-party scripts run on the page #2089

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 marked this pull request as ready for review November 22, 2026 23:05
@nc9
nc9 merged commit 3f39d15 into main Nov 22, 2026
10 checks passed
@nc9
nc9 deleted the boat/third-party-exposure-2089 branch November 22, 2026 23:12
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.

security/cookie-flags and security/token-storage: rate higher and name the hosts when third-party scripts run on the site

1 participant