Repository navigation
feat(rules): security/csp reports whether the policy would contain a hijacked third-party script #2087 - #2258
Merged
Merged
Conversation
…hijacked third-party script #2087 Signed-off-by: Nik Cubrilovic <[email protected]>
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.
Closes #2087
Summary
security/cspnow says whether an enforced policy would contain a hijacked third-party script, on the judged page (the entry page, or each listed page on a targeted run) when it loads at least one third-party<script src>:csp-connect-unrestricted(warn): noconnect-srcand nodefault-src, or the one browsers read holds*, a*host (https://*) or a network scheme-only source (https:,http:,wss:,ws:). Message:Script on the page can send data to any host.csp-strict-dynamic-third-party(info): the script list for elements holds'strict-dynamic', so scripts vendors insert are trusted too.csp-no-reporting(info): enforced policy with neitherreport-tonorreport-uri.csp-unsafe-scripts: when'unsafe-eval'is allowed and the page loads third-party scripts, the value names the vendor hosts anddetails.thirdPartyHostsis added. Without third-party scripts the check is byte-for-byte unchanged.Design notes:
security/cspinstead of a new rule, so the judgement stays on the entry page and a site-wide policy is one finding, not one per page.csp.tsis part of the dependency-free@squirrelscan/rules/security-headersWorker entry (guarded bysecurity-headers-entry.test.ts), so it cannot importtldtsor the DOM helpers. Script srcs come from the page-time collected signals (streaming) or a duck-typed read of the live document (v1), skipping<noscript>. "Third party" is a host outside the page's own domain: last two labels of the page host, three for a country suffix likeco.uk. Without a public suffix list this errs toward first party (another tenant of a shared hosting domain is missed); documented.csp-report-onlyalready covers them). Comma-joined policies are judged per policy: one restricting connections restricts them;'strict-dynamic'counts only if every script-controlling policy has it.Acceptance criteria
connect-src/ no restrictingdefault-srcwith a third-party script: finding. Testcsp-connect-unrestricted (#2087) > no connect-src and no default-src: script can send data anywhere.*,https:, other scheme-only (wss:),https://*, inheriteddefault-src */https:fire; host lists,'self','none', subdomain wildcard,data:/blob:, a second restricting policy do not. Tests... %s fires and names the directive(6) and... %s does not fire(7).'strict-dynamic'with third-party scripts: info. Tests incsp-strict-dynamic-third-party (#2087)(4).'unsafe-eval'with third-party scripts reported with that context; unchanged without them. Tests incsp-unsafe-scripts 'unsafe-eval' context (#2087)(3).report-to/report-uri: info. Tests incsp-no-reporting (#2087)(4).<noscript>, non-http src, report-only, collected first-party srcs). Tests inno third-party script, no new findingsandstreaming path reads the collected script srcs.csp.test.ts,csp-evidence-1735,csp-script-src-elem-1600,csp-self-proxy-1604,csp-chunk-only-776,targeted-header-rules-1778,security-header-check-names-1737). Revertingcsp.tsmakes 13 of the new tests fail (all the positive cases).docs/rules/security/csp.mdxdescribes each check, a "Third-party scripts" section with the limits (reads the header and fetched HTML, executes nothing, no PSL), the check-names table and a fix example. No new rule, so README and category tables are unchanged.Gates
packages/rules:bun run typecheckpass; oxfmt--checkand oxlint on the changed files pass.bun run scripts/test-suites.ts --run rules: 12680 pass, 0 fail (416 files).csp-third-party-containment-2087.test.ts: 33+7 = 40 tests pass;security-headers-entry.test.tspass.golden-finding-messages-229,streaming-rules-canonical-golden,targeted-site-rules-1778-e2e: 12 pass, 0 fail.docs/:make validateexit 0.bun scripts/changelog.ts checkOK (entrychangelog.d/2087-csp-third-party-containment.added.md).Agent skill
No change needed to the squirrelscan agent skill: new check names surface through the existing report output and docs.