Repository navigation
Enforce a Blog Content-Security-Policy Behind a Script Hash Gate - #514
Conversation
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
|
A recorded local strict-review pass covers head |
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #514 +/- ##
===========================================
+ Coverage 49.70% 50.85% +1.14%
===========================================
Files 10 11 +1
Lines 3058 3168 +110
===========================================
+ Hits 1520 1611 +91
- Misses 1538 1557 +19
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🟡 Changes recommended
Critical validation and test compatibility issues remain, and the CSP currently blocks the existing Google Maps shortcode.
3 open issues
What changed in this PR
This pull request adds an enforcing Content-Security-Policy for the blog and a release-time gate that synchronizes inline script hashes, external script origins, and deployed headers.
Changes:
- Adds the blog CSP to Caddy and
checks/security-headers.txt. - Adds
checks/check-csp-scripts.py, its tests, and release-build integration. - Documents CSP behavior and hash maintenance for deployments and theme updates.
| File | Summary |
|---|---|
themes/README.md |
Documents CSP hash updates when replacing the vendored theme. |
deploy/README.md |
Documents the blog CSP, hash maintenance, and release verification. |
deploy/make-release.sh |
Runs the CSP gate during release builds. |
deploy/Caddyfile |
Adds the enforcing blog CSP header; the current policy blocks the existing Google Maps shortcode. |
checks/tests/test_check_csp_scripts.py |
Adds CSP gate tests; contains f-strings that are invalid on supported Python 3.10/3.11 versions. |
checks/security-headers.txt |
Records the canonical blog CSP value. |
checks/README.md |
Adds the CSP validation check to the checks catalog. |
checks/check-csp-scripts.py |
Validates inline hashes and script sources; its MIME-type allowlist misses executable JavaScript MIME variants. |
Review effort: Lite
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
A recorded local strict-review pass covers head |
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…Scripts Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
A recorded local strict-review pass covers head |


Summary
The blog site block sends an enforcing
Content-Security-Policy, which #501 tracks:script-srclists them by hash rather than allowing'unsafe-inline'.checks/check-csp-scripts.py, runs inmake-release.shafter the URL contract, so it runs in validation, on every deploy, and on every local release. It hashes every inline script inpublic/and fails when a hash is unlisted or a listed hash is unused. It also fails on an inline handler, ajavascript:URL, or a script from an originscript-srcdoes not name. It requiresdeploy/Caddyfileto send the exact valuesecurity-headers.txtholds. A Hugo or theme update that changes a script's bytes therefore fails the build rather than a reader's page.img-src 'self'leaves out the two hosts that eight archived posts hotlink. Every one of those 95 images already answers404, and Settle the Dead Hotlinked Images on Eight Archived Posts #513 tracks them.layouts/shortcodes/googlemaps.htmlis deleted. It rendered an<iframe>from another host, which the policy blocks, and no post called it.deploy/README.md"Security headers" and "What the script asserts", thechecks/README.mdtable, thethemes/README.mdupdate procedure, the README's local build steps, theCONTENT.mdgate table, and aCheck: CSP Scriptseditor task.deploy/README.mdalso states that the policy blocks any script the proxy injects, so Rocket Loader, Email Address Obfuscation, and Web Analytics stay off on the host side.Verification
golden-urls.txt, plus/search/with a query typed. It also clicked the code-copy buttons and scrolled each page. It recorded everysecuritypolicyviolationevent. All 328 pages carried the header. The only violations were the 95 dead images.img-srcblocks and nothing else.check-live-urls.shpassed 1296 URLs, asserting the new header on every response.python3 -m unittest discover -s checks/testspasses 154 tests, including the Docker-backed case that holds the Caddyfile andsecurity-headers.txtequal. ruff, mypy, pyright on the new files, prose lint with sentence length, markdownlint, cspell, editorconfig, shellcheck, and shfmt are clean.Deferred findings, filed
Declined findings
expected_headers()inchecks/tests/test_check_live_urls_sample.py, consolidation. Each script underchecks/is standalone, and there is no shared module to put a parser in.www.elcolighting.comfigure stops loading underimg-src 'self'. That image already answers404.importlibloader onto a shared helper, consolidation. Each test underchecks/testsloads its own script, which matches the standalone-script convention above.javascript:test as over-hardening. URL schemes are case-insensitive and browsers strip leading spaces, so a hand-typedJavaScript:in a post is a realistic shape..github/actions/validate/action.ymlstep comment. The comment is not false, naming the gate would lengthen it, anddeploy/README.md"What the script asserts" is the list, which names the gate.🤖 Generated with Claude Code