Skip to content

Check Every Fetch on Both Sites Against Its Policy, and Refuse a Named Host - #533

Merged
ptr727 merged 5 commits into
developfrom
feature/csp-gate-every-fetch
Oct 25, 2026
Merged

ptr727 merged 5 commits into
developfrom
feature/csp-gate-every-fetch

Conversation

@ptr727

@ptr727 ptr727 commented Oct 25, 2026 •

Copy link
Copy Markdown
Owner

Summary

This is step 2 of #529. The release build now fails when either site loads anything from another host. Before, nothing caught the 95 dead hotlinked images that #513 restored. As decided on #529, this extends the existing CSP gate rather than adding a separate local-only check. checks/check-csp-scripts.py becomes checks/check-csp.py.

  • Every fetch. Beyond scripts, frames, media, and objects, the gate now reads:
    • images, srcset candidates, posters, and SVG <image>
    • each <link> that loads something, by rel and by as for a preload
    • CSS in stylesheets, <style> blocks, and style attributes, where @import is read under style-src, a url() in @font-face under font-src, and any other url() under img-src
    • preconnects and DNS prefetches, which no directive governs, so they are held to default-src
  • Both sites. The built blog and the committed family tree are each checked against their own policy. An absolute URL on the site's own origin counts as the site, with the origin read from the home page's canonical link through check-url-parity.py's site_origin.
  • No other host. A policy that names a host, or a network scheme such as https:, fails. That covers every -src directive, the navigation source lists such as form-action, and report-uri. A scheme such as data: names no host and stays allowed. Each policy is then the one statement of what its site may load, and it can name only the site itself.
  • Docs. deploy/README.md "Security headers" drops the old route of adding an embed's host to its directive, since the gate now fails on any such host. The README, CONTENT.md, checks/README.md, themes/README.md, check-csp-browser.py, make-release.sh, and the VS Code tasks name the new gate.

Part of #529, which closes when the promotion carrying this and #531 reaches main.

Verification

Run on server-2 at d4b1886, before 7195d75 added report-uri to the host rule, in a worktree holding this branch:

  • The checks/ suite: 198 tests pass, and ruff, ruff format, and mypy are clean.

  • deploy/make-release.sh against the local staging mirror: PASS - each site's policy allows every fetch its pages make, and names no other host, with the blog's 4 inline-script hashes matched. checks/check-live-urls.sh: PASS - 1296 URLs honored.

  • A negative run against the family tree and policy from before Serve Both Sites' Fonts From the Sites Themselves #531: the gate reports the four Google hosts in the policy and the four preconnect links on the two pages.

  • The hub prose gate, with this repository's excludes, reports nothing.

  • The local strict review ran three rounds. Its fixes cover:

    • @import with no space before its string
    • as="fetch" held to connect-src
    • non-source directives such as sandbox read as naming no host, and the navigation source lists read as naming one
    • a dead wrapper, a stale VS Code task dependency, and two doc rows

    It also raised the duplicated sibling loader, filed as Load a Hyphenated Sibling Check From One Shared Helper #532.

Declined findings

  • checks/check-csp.py:181, introduced, declined. The local review noted that a relative report-uri /path would fail with a message calling it another host. Neither policy carries report-uri, and that failure is loud on trusted input rather than a silent pass, so GOVERNANCE.md "Trust Boundaries and Hardening Effort" rules out a fix. The URL-bearing report-uri that Copilot raised is fixed in 7195d75.

Deferred findings, filed

  • Load a Hyphenated Sibling Check From One Shared Helper #532, a consolidation: the loader a check uses to import a hyphenated sibling script is now in three files, checks/fuzz-media-parsers.py, checks/tests/test_check_media_metadata.py, and this gate. Two of the three are in files this change does not touch, so the one-primitive rule moves them in a change of their own.

🤖 Generated with Claude Code

ptr727 and others added 4 commits October 25, 2026 15:35
…d Host

check-csp-scripts.py becomes check-csp.py. Beyond scripts, frames, media,
and objects, it reads images, srcset candidates, posters, SVG images, each
loading link, and CSS url() and @import in stylesheets, style blocks, and
style attributes. It runs over the built blog and the family tree, each
against its own policy, with the site's own origin read as 'self'. A policy
naming a host or a network scheme fails, so every resource either site
loads is its own.

Part of #529.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Read @import with no space before its string, hold a fetch preload to
connect-src, and read only fetch directives as naming a host. Drop the
unused script_sources wrapper behind one directives() parser. Fix the stale
VS Code task dependency, the CONTENT.md row, and the deploy README's remedy.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
base-uri, form-action, frame-ancestors, and navigate-to each list sources, so a host there fails like one under a -src directive. Split the deploy README's hash remedy into two sentences.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI lite review requested due to automatic review settings October 25, 2026 22:52
@coderabbitai

coderabbitai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: edd01bec-0e65-44ef-884b-5e9fe427a0d0
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ptr727

ptr727 commented Oct 25, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head d4b1886edf2c3e0e6a923e7e6d173280b82781c8, the content this pull request carries at that commit against develop, and it recorded 1 finding.

@codecov

codecov Bot commented Oct 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.25592% with 29 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (develop@071ce0c). Learn more about missing BASE report.

Files with missing lines Patch % Lines
checks/check-csp.py 86.25% 29 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             develop     #533   +/-   ##
==========================================
  Coverage           ?   53.24%           
==========================================
  Files              ?       12           
  Lines              ?     3418           
  Branches           ?        0           
==========================================
  Hits               ?     1820           
  Misses             ?     1598           
  Partials           ?        0           
Flag Coverage Δ
python-3.13 53.24% <86.25%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Two unresolved findings remain in checks/check-csp.py, including a critical gap in report-uri host validation.

1 open issue
What changed in this PR

This pull request expands CSP validation from scripts to all statically detectable fetches across both the built blog and committed family site, while rejecting policies that name external hosts.

Changes:

  • Replaces the script-only checker with check-csp.py.
  • Validates images, stylesheets, fonts, media, links, preloads, CSS URLs, scripts, and both site policies.
  • Updates release tooling, tests, documentation, browser-check guidance, and VS Code tasks.
File Description
themes/​README.md Updates theme guidance for the renamed CSP gate.
README.md Documents the expanded local CSP verification.
deploy/​README.md Describes the two-site CSP policy and release validation.
deploy/​make-release.sh Runs the new CSP gate during release builds.
CONTENT.md Updates content validation guidance and references.
checks/​tests/​test_check_csp.py Adds coverage for both sites, resource types, policies, and stylesheet parsing.
checks/​README.md Documents the expanded CSP check.
checks/​check-csp.py Implements policy loading, host validation, and HTML/CSS fetch analysis.
checks/​check-csp-scripts.py Removes the superseded script-only gate.
checks/​check-csp-browser.py Updates documentation for the new static gate.
.vscode/​tasks.json Renames and reroutes the CSP verification task.

Review effort: Lite

Comment thread checks/check-csp.py Resolved
Its value is the URL violation reports go to, so a collector on another host would otherwise pass the rule that neither policy names one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ptr727

ptr727 commented Oct 25, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head 7195d753ef91f665fae05ac9ed4d1930f48c891b, the content this pull request carries at that commit against develop, and it recorded 1 finding.

@ptr727
ptr727 merged commit aa0af50 into develop Oct 25, 2026
12 checks passed
@ptr727
ptr727 deleted the feature/csp-gate-every-fetch branch October 25, 2026 23:05
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.

2 participants