Repository navigation
Harden third-party JS: add CSP and pin MathJax with SRI - #9
Merged
Merged
Conversation
Defense-in-depth follow-up to removing polyfill.io. Dependabot only scans dependency manifests, so URL-loaded CDN scripts are an audit blind spot; this closes it for the whole site. - Add a Content-Security-Policy <meta> tag (overrides/main.html). The script-src/frame-src/connect-src origin allow lists were derived empirically from the built site (jsDelivr, cdn.plot.ly, utteranc.es, w.soundcloud.com, youtube.com, Google Fonts/Analytics). A rogue or newly-introduced external origin can no longer load scripts -- this would have blocked the polyfill.io payload even with the line present. - Pin MathJax to an exact version (3.2.2) and add a Subresource Integrity hash so a tampered CDN response is rejected. Injected via a raw <script> tag because mkdocs `extra_javascript` cannot set `integrity`/`crossorigin`. Config still loads before the library. CSP is delivered as a <meta> tag because GitHub Pages cannot set HTTP headers. 'unsafe-inline' is required for Material's inline bootstrap scripts/styles on static hosting, but the origin allow list (the part that matters here) is unaffected. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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
Defense-in-depth follow-up to #8 (removing polyfill.io). Dependabot only scans dependency manifests (
package.json,requirements.txt), so scripts loaded by raw URL — exactly the polyfill.io case — are invisible to it. This PR closes that blind spot for the whole site.Changes
1. Content-Security-Policy
<meta>tag (overrides/main.html)Restricts which origins may load executable resources. This would have blocked the polyfill.io payload even while that line was still present, because
polyfill.iowas never on the allow list.The
script-src/frame-src/connect-src/font-srcallow lists were derived empirically from the builtsite/, not guessed:script-srcframe-srcstyle-src/font-srcconnect-src2. MathJax pinned to exact version + SRI
mathjax@3(floating tag) →mathjax@3.2.2(latest v3 line).sha384Subresource Integrity hash (+crossorigin) so a tampered CDN response is rejected by the browser.<script>via the Materialscriptsblock because mkdocsextra_javascriptcan't setintegrity. Config (window.MathJax) still loads before the library.Verification (build-time)
mkdocs buildsucceeds; CSP meta present on every page; MathJax loads exactly once, pinned + SRI; floating@3tag andpolyfill.ioboth gone.CSP runtime effects can't be confirmed from the build alone. Please verify in
mkdocs serve(DevTools console should show no CSP violations):series/cpp/3)If any feature breaks, the offending origin just needs adding to the relevant directive. To roll out cautiously, the
http-equivvalue can temporarily beContent-Security-Policy-Report-Onlyto observe violations without enforcing.Notes
<meta>delivery (note:frame-ancestors/report-uriare ignored in meta form — not relied upon here).raw_html/; CSP now also restricts its origin. SRI on those generated files was left out to avoid churn on regeneration.🤖 Generated with Claude Code