Repository navigation
feat(rules): security/csp-violations reports what the browser blocked during rendered crawls #425 - #2265
Merged
Conversation
… during rendered crawls #425 Render results can now carry the CSP violations the browser raised (RenderRuntimeDiagnostics.cspViolations). The cloud fetcher passes the runtime block through, bounded and shape-checked; the crawler keeps it in an in-memory sink keyed by page; the streamed page pass hands it to rules as PageData.renderRuntime (such pages skip the rule cache, whose key does not cover it). The new page rule groups enforced violations by directive and host, fails for known analytics, ads, payments, captcha, form or booking vendors and warns otherwise. Raw pages skip with a reason; rendered pages without recorded violations are the runtime-not-recorded gap. 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.
Summary
New page rule
security/csp-violations: on a rendered crawl it reports what the browser actually blocked under the page's Content-Security-Policy, grouped by enforced directive and blocked host, with the host to add. Closes #425.Data path (public half; the renderer listener is private and tracked there):
core-contracts:RenderCspViolationandRenderRuntimeDiagnostics.cspViolations(absent = not recorded,[]= none seen),MAX_CSP_VIOLATIONS_PER_PAGE,RenderRuntimeSink.audit-engine/cloud-fetcher:mapRenderItemToResponsepasses the render item'sruntimeblock through asFetchResponse.renderRuntime, viaboundRenderRuntime(flat copies, count caps, 1 KB per string, a 64 KB per-page budget with CSP violations kept first).fetchers/crawler:renderRuntimeon the fetch result; new opt-inrenderRuntimeSink(set or cleared on every page commit), likerenderedRequestSink.audit-engine/streaming+adapter:renderRuntimeoption setsPageData.renderRuntime; a page with runtime never replays from the rule cache (its key does not hash this in-memory data).csp-vendorshost table, pluswww.google.comvendor paths/g/collect,/pagead/,/ads/,/recaptcha/), warn otherwise. Report-only violations are ignored. Query strings are never printed. Raw pages skip with a reason pointing at--render; rendered pages without recorded violations skip withruntime-not-recorded(listed as not checked, never a pass). Listed inRUNS_ON_UNREAD_PAGE(reads no parsed field) and declaresmeta.checks.The "analytics detected but no hit left the page" follow-on from the issue is not in this PR.
Acceptance criteria
script-srcomits: one finding naming the host andscript-src-elem.packages/rules/tests/csp-violations.test.ts"a script injected after load ..." (violations produced by a browser stand-in that judges each load with the shared CSP source matcher).connect-srclimited towww.google-analytics.com: statusfail(error), itemsanalytics.google.com/g/collect,www.google.com/g/collect,stats.g.doubleclick.net/g/collectwith categories analytics/analytics/ads. Same file, "an Ads-linked gtag page ...".finding-messages.jsonpins the skip line on all 500 synthetic pages.cloud-fetcher-runtime-425.test.ts,render-runtime-stream-425.test.ts, and end to endapps/cli/tests/audit/csp-violations-controller-425.test.ts(fails withskippedwhen the controller wiring is removed). Docs pagedocs/rules/security/csp-violations.mdx. The renderer side (asecuritypolicyviolationinit-script listener kept a few seconds afterload, fillingruntime.cspViolations) is private and not in this PR; until it ships, rendered pages reportruntime-not-recorded, as the docs say.Verification
format:checkandlint: clean. Changedpackages/*files: oxfmt --check and oxlint clean on new files; existing-file lint hits are on untouched lines.scripts/test-suites.ts --run rules12653 pass 0 fail;--run audit-engine2426 pass 0 fail;--run crawler1186 pass 0 fail;--run rest3946 pass 0 fail;--run cli4664 pass 0 fail;bun run test:engine273 pass 0 fail;--checkok.security/csp-violations: 500(one skip per synthetic page), health score unchanged at 58; finding-messages snapshot adds the one skip line.bun run docs:check: pass.bun scripts/changelog.ts check: OK./g/collectvendor path, the raw-page skip, or the report-only filter each fails its test; removing the controller wiring fails the controller test.Docs: new
rules/security/csp-violations, security hub row and counts (32 to 33) in README, docs index and rules index, CSP glossary term. Skill: none (no agent behaviour changes).