Skip to content

fix(docs-config): allow blob: scripts and Hotjar's survey host with analytics on - #425

Merged
Jesswinters merged 2 commits into
mainfrom
fix/docs-csp-osano-worker-hotjar-zoominfo
Dec 2, 2026
Merged

Jesswinters merged 2 commits into
mainfrom
fix/docs-csp-osano-worker-hotjar-zoominfo

Conversation

@Jesswinters

@Jesswinters Jesswinters commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

Merge order

Merge this together with coder/coder.com-new#86, which makes the same change to coder.com's copy of the /docs policy. 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 a security-header-drift issue, 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/:

Violation Cause
worker-src blob: Osano starts its classification workers from blob: URLs. The policy has no worker-src, so a worker falls back to script-src.
script-src-elem blob: ZoomInfo's zi-tag.js writes its session code into a blob: script. The console blames osano.js because Osano wraps appendChild.
script-src-elem https://script.hj.contentsquare.net/survey-v2.*.js Hotjar now loads its surveys from Contentsquare's host.

ANALYTICS_SCRIPT_ORIGINS gains https://script.hj.contentsquare.net. A new ANALYTICS_SCRIPT_SCHEMES (["blob:"]) is added to script-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.md says that widening script-src needs sign-off. blob: adds nothing an injected script couldn't already do: script-src keeps 'unsafe-inline', and only a script that is already running can create a blob: URL. The docstring and ARCHITECTURE.md both say to revisit blob: if the hardening path replaces 'unsafe-inline' with hashes. The Hotjar host is one more vendor origin, the same kind of entry as static.hotjar.com.

QA

There's no visible change to any page. After this PR and the coder.com one both deploy:

  1. Open https://coder.com/docs/install/ with DevTools open, then accept the cookie banner if it asks.
  2. In the Console, expect no Content Security Policy errors that mention blob: or script.hj.contentsquare.net.
  3. Ad-blocker errors (ERR_BLOCKED_BY_CLIENT) and source-map (.map) connect-src errors only appear with extensions or DevTools in play, so they're out of scope.

Pages to compare

What to check Production Preview
Console on a docs page https://coder.com/docs/install/ n/a: coder.com's header rules replace the router's on /docs, so check this after both PRs deploy

Testing

  • @coder/docs-config: 107/107 pass. That includes a new test that blob: appears only with the tags on, and that every script-src entry is a keyword, an https:// source or blob:. The existing "widens script-src only" test now expects blob:.
  • @coder/docs-router: 218/218 pass, including the DOCS_ANALYTICS cases in archive-handler.test.ts and headers-check.test.ts.
  • vercel-config.test.mjs passes. The typecheck for docs-config and the router is clean, and pnpm lint is clean.
  • The script-src that docsContentSecurityPolicy({ analytics: true }) builds has exactly the same entries as the coder.com PR's built /docs policy, checked against its routes-manifest.json.
  • In a browser: Playwright loaded the production docs pages, once as served and once with each page's CSP header swapped for the coder.com PR's built policy. With the new policy, all three violations are gone on all three pages, and a test 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.

…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 nickvigilante left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

  1. Security sign-off is not recorded. AGENTS.md and ARCHITECTURE.md both say that widening script-src needs 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 for blob: is sound, since 'unsafe-inline' already lets an injected inline script run and only running script can mint a blob: 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.
  2. Merge order is the real risk. The weekly headers:check compares 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, a security-header-drift issue opens until the other lands.
  3. 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.
  4. 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.

@github-actions

Copy link
Copy Markdown

Docs preview deployment

Rendered 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.

@Lisa-Fiander Lisa-Fiander 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.

one change

Comment thread packages/docs-config/src/analytics.ts Resolved
…line' does

Removing 'unsafe-inline' now fails the test until blob: is reconsidered.
@Jesswinters
Jesswinters merged commit 9987b9f into main Dec 2, 2026
35 of 38 checks passed
@Jesswinters
Jesswinters deleted the fix/docs-csp-osano-worker-hotjar-zoominfo branch December 2, 2026 19:22

@nickvigilante nickvigilante left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

This branch is waiting to be deployed

1 waiting deployment
docs-preview — 61eeca73 Waiting Dec 2, 2026 by Jesswinters via preview / deploy preview #150
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.

3 participants