Skip to content

security(site): stage content policy reporting - #546

Closed
Ducksss wants to merge 1 commit into
devfrom
codex/csp-report-only
Closed

Ducksss wants to merge 1 commit into
devfrom
codex/csp-report-only

Conversation

@Ducksss

@Ducksss Ducksss commented Sep 1, 2026

Copy link
Copy Markdown
Owner

Summary

  • add a site-wide Content-Security-Policy-Report-Only header as the first rollout stage
  • preserve same-origin component/template previews with frame-ancestors and frame-src
  • allow only the analytics origins already declared by the site while blocking object embeds
  • pin the complete policy in the site-shell integration contract

Addresses #521. Add Closes #521 to the next dev → main promote PR after production reports have been reviewed.

Validation

  • pnpm exec vitest run tests/int/fumadocs-site.int.spec.ts
  • pnpm exec prettier --check next.config.mjs tests/int/fumadocs-site.int.spec.ts
  • pnpm build
  • production server smoke: / returned the full report-only CSP header
  • git diff --check

@vercel

vercel Bot commented Sep 1, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
payload-components Ready Ready Preview Sep 1, 2026 6:05pm UTC
payload-components-97bf Ready Ready Preview Sep 1, 2026 6:05pm UTC

Copilot AI lite review requested due to automatic review settings September 1, 2026 18:00

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@Ducksss

Ducksss commented Sep 1, 2026

Copy link
Copy Markdown
Owner Author

Closing after critical review: this draft does not provide the observable rollout it claims. The report-only policy defines neither report-uri nor report-to/Reporting-Endpoints, and the repository has no CSP report collector, so it cannot produce the production reports the PR says should be reviewed before enforcement; it only creates local browser-console diagnostics. It also hard-codes *.posthog.com even though NEXT_PUBLIC_POSTHOG_HOST supports custom hosts. Keep #521 open and revisit with a real reporting destination plus an environment-aware source policy (or a deliberately tested enforcement plan).

@Ducksss Ducksss closed this Sep 1, 2026
@Ducksss
Ducksss deleted the codex/csp-report-only branch September 1, 2026 18:31
Ducksss added a commit that referenced this pull request Oct 1, 2026
main has enforced a Content-Security-Policy since #554. This hardens it and
gives it the feedback loop a backend-free site can have.

- script-src-attr 'none' refuses inline event-handler attributes, the
  injection path that 'unsafe-inline' otherwise leaves open. React never
  renders them: all 318 prerendered routes contain none.
- frame-src 'self' drops six unused third-party embed origins. Only the
  same-origin component and template previews frame, and the Embed Basic
  catalog demo is a faux player.
- https://www.google-analytics.com is dropped; *.google-analytics.com
  already covers it.
- Script elements keep 'unsafe-inline'. Next streams build-specific inline
  RSC scripts into every static page (1,028 distinct hashes across 318
  routes, 999 of them on a single route, changing with each deploy), and
  nonces would force dynamic rendering. JSON-LD data blocks are not policed
  by script-src.
- The policy stays enforced rather than report-only. With no collector,
  report-only output would only reach visitors' consoles (see #546).
  tests/e2e/content-security-policy.e2e.spec.ts fails on any violation
  across the landing page, docs, catalog, both preview frames, templates,
  blog and case study, with consent declined and accepted. It also checks
  the served header on documents and preview frames.
- The int spec pins every directive exactly, plus the dev-only eval and
  Vercel debug allowances and the origin derived from
  NEXT_PUBLIC_POSTHOG_HOST.
- The stale CSP paragraph in docs/ai-discovery is refreshed, and AGENTS.md
  gains a gotcha for adding third-party origins.

Refs #521

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Ducksss added a commit that referenced this pull request Oct 1, 2026
#584)

* config(fix): tighten the enforced CSP and browser-test it on every run

main has enforced a Content-Security-Policy since #554. This hardens it and
gives it the feedback loop a backend-free site can have.

- script-src-attr 'none' refuses inline event-handler attributes, the
  injection path that 'unsafe-inline' otherwise leaves open. React never
  renders them: all 318 prerendered routes contain none.
- frame-src 'self' drops six unused third-party embed origins. Only the
  same-origin component and template previews frame, and the Embed Basic
  catalog demo is a faux player.
- https://www.google-analytics.com is dropped; *.google-analytics.com
  already covers it.
- Script elements keep 'unsafe-inline'. Next streams build-specific inline
  RSC scripts into every static page (1,028 distinct hashes across 318
  routes, 999 of them on a single route, changing with each deploy), and
  nonces would force dynamic rendering. JSON-LD data blocks are not policed
  by script-src.
- The policy stays enforced rather than report-only. With no collector,
  report-only output would only reach visitors' consoles (see #546).
  tests/e2e/content-security-policy.e2e.spec.ts fails on any violation
  across the landing page, docs, catalog, both preview frames, templates,
  blog and case study, with consent declined and accepted. It also checks
  the served header on documents and preview frames.
- The int spec pins every directive exactly, plus the dev-only eval and
  Vercel debug allowances and the origin derived from
  NEXT_PUBLIC_POSTHOG_HOST.
- The stale CSP paragraph in docs/ai-discovery is refreshed, and AGENTS.md
  gains a gotcha for adding third-party origins.

Refs #521

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

* test(fix): mount GA4 offline in the CSP walk now that the tag is host-gated

GA4 now mounts on the production hosts only (#586), so on localhost accepting
consent no longer attaches script#google-tag, and the Accept walk in
content-security-policy.e2e.spec.ts fails at its toBeAttached check.
watchPolicy now opts the host back in through mountGoogleTagOffline, which
stubs every Google origin before it sets the test hook. The Decline walk keeps
the hook too, so it also proves that declining mounts nothing on an allowed host.

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

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>

This branch was successfully deployed

2 active deployments
Preview – payload-components-97bf — 6fe23ad8 Deployed Sep 1, 2026 by vercel[bot]
Preview – payload-components — 6fe23ad8 Deployed Sep 1, 2026 by vercel[bot]
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