Repository navigation
fix(docs-config): allow blob: scripts and Hotjar's survey host with analytics on - #425
Conversation
…nalytics on Measured on coder.com/docs on 2026-11-30, three of the tags' scripts are refused by the analytics policy: - Osano starts its classification workers from blob: URLs. The policy names no worker-src, so workers fall back to script-src. - ZoomInfo's zi-tag.js writes its session code to a blob: script. - Hotjar loads its surveys from https://script.hj.contentsquare.net. ANALYTICS_SCRIPT_SCHEMES (blob:) joins script-src with the tags on, and the Hotjar origin joins ANALYTICS_SCRIPT_ORIGINS. blob: adds nothing an injected script could not already do while script-src keeps 'unsafe-inline'. coder.com restates this policy for /docs and gets the same two entries. Assisted-by: AI
nickvigilante
left a comment
There was a problem hiding this comment.
Approving. The change does what the PR body says, and the two policies line up: the script-src that docsContentSecurityPolicy({ analytics: true }) builds has the same entries as coder.com-new#86's DOCS_SCRIPT_ORIGINS. The tags-off policy (DOCS_CONTENT_SECURITY_POLICY, vercel.json) is untouched, and the new test pins that blob: appears only with the tags on and that no other scheme sneaks in. CI is green. Nothing here blocks the merge, but there are a few things to flag.
Flags, not blockers
- Security sign-off is not recorded. AGENTS.md and ARCHITECTURE.md both say that widening
script-srcneeds sign-off from Security (Lisa or JD), and this PR adds a new vendor origin (script.hj.contentsquare.net) plus a scheme (blob:). The PR's reasoning forblob:is sound, since'unsafe-inline'already lets an injected inline script run and only running script can mint ablob:URL. Even so, please get a one-line yes from JD (Lisa is out) in this thread before the PR merges, so the rule is met rather than argued around. - Merge order is the real risk. The weekly
headers:checkcompares this policy with coder.com's, so land this together with coder/coder.com-new#86 and don't let one sit. If one ships alone, asecurity-header-driftissue opens until the other lands. - The origin list is a snapshot. The new origin and the
blob:finding were measured on 2026-11-30 against GTM-NLLNT3K, and Marketing can change the container at any time. The docstring already says how to re-derive the list, so nothing to change, but expect this to recur. blob:is tied to'unsafe-inline'. The docstring and ARCHITECTURE.md both say to revisit it if the hardening path replaces'unsafe-inline'with hashes. That's the right place to record it, and it'd be worth keeping in mind when that work starts.
The new worker-src fallback note (no worker-src or child-src, so workers fall back to script-src) is correct per the CSP fallback chain.
Docs preview deploymentRendered with docs-engine 0417c61 from coder/coder at b911ed9782c807d521a21f6990697723b3562351: https://coder-docs-7xbf8wx0y.coderite.app The preview is behind Vercel authentication; sign in with your Coder Vercel account. |
…line' does Removing 'unsafe-inline' now fails the test until blob: is reconsidered.
nickvigilante
left a comment
There was a problem hiding this comment.
Approving again at 61eeca7. My first approval was on the first commit; the second commit only adds the guard test Lisa asked for, and I re-read the whole change from scratch.
The change does what the description says: with analytics on, script-src gains https://script.hj.contentsquare.net and blob: through ANALYTICS_SCRIPT_SCHEMES, and nothing else moves. The reasoning for blob: holds. script-src keeps 'unsafe-inline', so an injected script could already run arbitrary code, only a running script can mint a blob: URL, and with no worker-src or child-src workers fall back to script-src. The new test fails if 'unsafe-inline' is removed while blob: stays, so hardening the policy will fail CI until blob: is reconsidered. Lisa's change request is addressed and she approved this head, so the security sign-off the docs ask for is recorded.
Checked: the router builds its header only through docsContentSecurityPolicy (apps/router/lib/archive.ts), so there is no second copy of the list; the PR touches no workflow or vercel.json; and coder/coder.com-new#86 adds the same two entries in the same order with the same guard. build & check is green. I did not re-run the tests locally, and CodeQL, osv-scanner and the preview deploys were still pending when I looked.
Merge this together with coder/coder.com-new#86, or the weekly headers:check opens a security-header-drift issue until the second one lands. JD's review request is no longer needed now that Lisa has approved.
🤖 Built with AI assistance.
Merge order
Merge this together with coder/coder.com-new#86, which makes the same change to coder.com's copy of the
/docspolicy. The weekly production header check (headers:check) compares the two policies as sets of directives. If only one of the two PRs has shipped, the check opens asecurity-header-driftissue, and that issue closes on the next passing run once both have shipped.Summary
With analytics on, the tags on coder.com/docs run three scripts that the docs policy blocks. I measured this on 2026-11-30 with headless Chromium on
/docs/,/docs/install/and/docs/admin/templates/:worker-src blob:blob:URLs. The policy has noworker-src, so a worker falls back toscript-src.script-src-elem blob:zi-tag.jswrites its session code into ablob:script. The console blamesosano.jsbecause Osano wrapsappendChild.script-src-elem https://script.hj.contentsquare.net/survey-v2.*.jsANALYTICS_SCRIPT_ORIGINSgainshttps://script.hj.contentsquare.net. A newANALYTICS_SCRIPT_SCHEMES(["blob:"]) is added toscript-src, but only while the tags are on. The policy with the tags off (DOCS_CONTENT_SECURITY_POLICY,vercel.json) does not change.Security sign-off.
ARCHITECTURE.mdsays that wideningscript-srcneeds sign-off.blob:adds nothing an injected script couldn't already do:script-srckeeps'unsafe-inline', and only a script that is already running can create ablob:URL. The docstring andARCHITECTURE.mdboth say to revisitblob:if the hardening path replaces'unsafe-inline'with hashes. The Hotjar host is one more vendor origin, the same kind of entry asstatic.hotjar.com.QA
There's no visible change to any page. After this PR and the coder.com one both deploy:
Content Security Policyerrors that mentionblob:orscript.hj.contentsquare.net.ERR_BLOCKED_BY_CLIENT) and source-map (.map)connect-srcerrors only appear with extensions or DevTools in play, so they're out of scope.Pages to compare
/docs, so check this after both PRs deployTesting
@coder/docs-config: 107/107 pass. That includes a new test thatblob:appears only with the tags on, and that everyscript-srcentry is a keyword, anhttps://source orblob:. The existing "widens script-src only" test now expectsblob:.@coder/docs-router: 218/218 pass, including theDOCS_ANALYTICScases inarchive-handler.test.tsandheaders-check.test.ts.vercel-config.test.mjspasses. The typecheck fordocs-configand the router is clean, andpnpm lintis clean.script-srcthatdocsContentSecurityPolicy({ analytics: true })builds has exactly the same entries as the coder.com PR's built/docspolicy, checked against itsroutes-manifest.json.blob:script runs.Upstream
No. This is our own analytics policy, nothing in Fumadocs.
This PR was generated by Coder Agents on behalf of @Jesswinters.