Repository navigation
feat(rules): add security/csp-blocks-own-resources - #583
Conversation
…cks the page's own resources Matches each page's own CSP against what its HTML references, third-party script URLs inside same-site chunks, and the runtime hosts of detected vendors. Preloaded script chunks are now fetched like script tags. Signed-off-by: Nik Cubrilovic <[email protected]>
|
Status: pushed and ready for review. Waiting on the bot review; I will fix or rebut any critical, high or medium findings. |
|
Review of
|
…pets safely in csp-blocks-own-resources Signed-off-by: Nik Cubrilovic <[email protected]>
|
Review round 1, pushed in 252d0a2. Medium (preloaded chunks in the shared Low, fixed:
Nit, not changed: per-script scan caching. The scan is bounded (2 MB per chunk, 6 MB per page) and only runs on pages that have an enforced CSP; a cache keyed by script URL would be new shared state in a page rule for a bounded cost, so I'm leaving it. |
Signed-off-by: Nik Cubrilovic <[email protected]>
|
CodeQL (11 "missing regular expression anchor" alerts on |
|
I read the diff for the new Findings:
Tests: the rule test, the preload extractor test and the updated golden counts (101234 findings, 298 rules, 500 passes) look appropriate. Consider adding a nonce-only policy without |
|
Review round 2, no new push. Medium (preloaded chunks reach every script rule): same finding as round 1, and the answer stands. The per-audit cap you suggest already exists and covers these fetches. Lows, left as they are:
Nits: IPv6 and punycode sources are out of scope for a static check of http(s) hostnames, and Suggested tests: the multi-policy case (one policy allows, another blocks) is already covered by |
…hunks to the rule Preloaded script chunks are fetched into a separate preloadedScripts list, capped at 20 per audit, so no other rule's site.scripts input changes. The rule cache format is bumped and the run context hashes the new field. Signed-off-by: Nik Cubrilovic <[email protected]>
|
Pushed 0981460: merged origin/main (the only conflict was What changed
Evidence that no other rule's output changes
|
|
Review of Overall the design is solid. Preloaded chunks are kept out of
Test coverage looks good: the acceptance fixtures, the matcher unit tests, the parser extractor test and the updated golden counts. No security concerns, since preload fetches are limited to same-domain URLs via |
…njected chunk scripts as undecidable Signed-off-by: Nik Cubrilovic <[email protected]>
|
Review round 3, pushed in 62655c4. Medium, nonce policies and chunk-injected scripts: fixed. A script URL found inside a chunk is now undecidable (not reported) when the governing list carries a Medium, extra fetches on sites with no CSP: fixed. Preloaded chunks are now collected only from pages that enforce a CSP (response header or Low, vendor path scoping: fixed. Vendor needs are judged on host only, since the real request path is unknown, so a policy allowing Low, unsupported references: the docs now list what is not checked ( Nit, Left as is: IDN and punycode hosts and trailing-dot wildcard normalisation (edge cases for a static http(s) check), and short-circuiting the hint regex by host (the scan is already bounded). Rule tests (32), canonical golden, rule-cache replay golden, page-rule site context, verdict scope, typecheck, format check, docs validation and the secret scan pass locally. That is the third review round, so I'm stopping the review loop here and not merging. |
…blocks-own-resources Signed-off-by: Nik Cubrilovic <[email protected]>
|
CodeQL, "incomplete multi-character sanitization" on the comment strip in |
|
Review of the new
Otherwise the design is solid: preloads stay in a separate field so other rules' inputs don't change, fetches are capped, and the cache format bump to |
|
Round 4 review, answered with evidence, no push (review rounds are spent, and neither medium reproduces). Medium, comma split of the header: the CSP3 grammar defines a header value as Medium, Low, tests: they exist: Low, chunk hint heuristic and path approximation: already documented as best-effort, and chunk findings warn. Nit, |
|
Reviewed the diff for the new rule, the source-matching module, the parser extractor and the adapter and cache plumbing. I did not read No blocking issues found. The CSP3 fallback chain,
Test coverage looks good: acceptance fixtures, a source-matching block, extractor tests, and the golden tally update (+500 passes, 298 rules). |
|
Status: the latest bot review has no critical, high or medium findings, only lows and nits (meta CSP inside |
|
Review of the new
I found nothing blocking. The preloaded scripts are kept in a separate map, so existing script rules should be unaffected. |
Refs #426
Adds the per-page rule
security/csp-blocks-own-resources, which flags a Content-Security-Policy that blocks what the page itself loads. It matches each page's own policy (header plus<meta http-equiv>) against the page's scripts, preloaded modules, stylesheets, frames and images, third-party script URLs inside same-site chunks, and the runtime hosts of detected vendors.Acceptance criteria
connect-src 'self' https://www.google-analytics.comproduces an error listinganalytics.google.com,www.google.comandstats.g.doubleclick.netforconnect-src. Test:acceptance fixtures > gtag for an Ads-linked property...inpackages/rules/tests/csp-blocks-own-resources.test.ts.script-src, produces a finding. Test:...named only inside a preloaded same-origin chunk is a finding. The audit fetchesmodulepreloadandpreload as=scriptchunks (extractPreloadedScriptUrlsin the parser, used byadapter.ts), covered bypackages/parser/tests/extract-preloaded-script-urls.test.ts.https://*.example.compasses forcdn.example.comand produces a finding forexample.com. Test:a *.example.com source allows cdn.example.com and blocks example.com, plus thesource matchingblock.no CSP header passes, and a report-only policy blocks nothing.each page is judged by its own policy,every vendor entry records an ISO last-verified date. Docs:docs/rules/security/csp-blocks-own-resources.mdx, listed indocs/docs.jsonand the Security index.Engine change
Preloaded chunks are fetched only when a crawled page enforces a CSP, into a separate
preloadedScriptslist capped at 20 per audit. They are not added tosite.scripts, so no other rule's input changes (the canonical golden is unchanged apart from this rule's passes). The rule cache format is bumped toprc-4and its run context hashes the new field, so the first audit of each site after the upgrade runs every rule fresh, once.False-positive fixtures
no false positivesin the test file covers'self', directive fallback (script-src-elem,child-src,default-src), unset directives, scheme, port and path sources, nonces, hash sources withintegrity,'strict-dynamic', noscript anddata:images, chunk URLs with no script-loading context, chunk-injected scripts under a nonce policy, own-host chunk URLs, a proxied PostHog, commented-out vendor snippets and a covered GA4-only setup.Registration and counts
packages/rules/src/security/index.ts; declaredverdictScope: "page"(it reads the response header) and added tovaryingRulesintemplate-invariance-measured.json. That list is normally produced by measuring two third-party crawls, which I cannot do here, so the entry is by construction.README.md,docs/index.mdx,docs/rules/index.mdx,docs/rules/security/index.mdxanddocs/agent-setup/index.mdx. CHANGELOG has an Unreleased entry.streaming-rules-canonical-golden.test.ts: 297 to 298 rules and 100734 to 101234 findings (500 passes on the synthetic site, which serves no CSP).Verification
rule-verdict-scope, the canonical golden,rule-cache-replay-golden,page-rule-site-contextand the parser extractor test pass. CI is green on the current head.rules,parserandaudit-engine;make validatein docs, rootformat:checkand the detect-secrets hook pass.Smoke on public sites
The sandbox egress allows very few hosts (most returned 403 from the proxy, others served a bot wall), so the sample is small.
0 findings on about 17 pages under an enforced CSP, so the measured false-positive rate is 0 of 17. That is too small to call it a rate, and it exercises no true positives on live sites.
Agent skill
No change needed to the squirrelscan agent skill.