Skip to content

fix(csp): allow the Stripe and Turnstile scripts - #99736

Merged
trunk-io[bot] merged 1 commit into
masterfrom
csp/allow-stripe-and-turnstile
Sep 13, 2026
Merged

trunk-io[bot] merged 1 commit into
masterfrom
csp/allow-stripe-and-turnstile

Conversation

@Piccirello

Copy link
Copy Markdown
Member

Problem

Under enforcement, adding a payment method and the signup captcha would both fail. script-src lists no third-party host, so two scripts the app loads itself violate our own policy. The policy is report-only, so both still run today.

Over 24 hours, on documents carrying the current policy:

  • js.stripe.com, 90 reports across 52 documents, on /signup, the user-navigation settings page and the onboarding plans step. PaymentEntryModal.tsx calls loadStripe, which injects the script.
  • challenges.cloudflare.com, 14 reports across 7 documents, on /signup. signupLogic.ts drives the Turnstile widget, which loads the API.

The document counts are small because these are rare flows, not because the reports are noise. Each one is a person who reached checkout or a signup challenge.

Changes

  • Payment entry and the signup captcha keep working under an enforced policy. script-src gains https://js.stripe.com and https://challenges.cloudflare.com.
  • Neither host can be dropped by self-hosting, which is how the country flag font was handled in fix(csp): serve the country flag font ourselves #99625. Both vendors require the file to load from their own origin.
  • Only script-src needs them. frame-src 'self' https: already admits the iframes each vendor opens, and neither reported a connect-src violation across those 52 documents, which says their API calls happen inside those frames rather than from our page.

How did you test this code?

  • No new tests. No test asserts the app's script-src, and an assertion on the directive text would pin the exact string and fail on every later edit.
  • Not run: TestCSPMiddleware needs Postgres, which this sandbox does not have. CI covers it.
  • Both call sites were read in the tree rather than inferred: frontend/src/scenes/billing/PaymentEntryModal.tsx and frontend/src/scenes/authentication/signup/signupForm/signupLogic.ts.
  • The production signal is direct: after deploy, both buckets should fall to zero.

Automatic notifications

  • Publish to changelog?

Docs update

None.

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

  • Claude Code (Opus 5). Skills invoked: /writing-pr-descriptions, /writing-tests, /reviewing-with-coderabbit.
  • CodeRabbit CLI pass: paused, so this PR opened without a local pass.
  • No duplicate: searched open PRs for Stripe, Turnstile and CSP. Nothing related.
  • Patch coverage: the changed line is a policy string that no test asserts, so the patch is uncovered by design.
  • Found by sweeping every violation bucket on documents carrying the newest policy, after fix(csp): allow data: URL fonts and drop an unused CDN origin #99477 changed it. That sweep also turned up the Tailwind play CDN on the messaging preference pages, which is a separate change because the fix there is to stop loading a third-party script rather than to allow one.
  • Public artifact: nothing here draws on non-public material.

`script-src` lists no third-party host, so two scripts the app loads
itself violate our own policy. The policy is report-only, so both still
run. Under enforcement, adding a payment method and the signup captcha
would both fail.

Over 24 hours, on documents carrying the current policy:

- js.stripe.com, 90 reports across 52 documents, on /signup, the
  user-navigation settings page and the onboarding plans step.
  `PaymentEntryModal.tsx` calls `loadStripe`, which injects the script.
- challenges.cloudflare.com, 14 reports across 7 documents, on /signup.
  `signupLogic.ts` drives the Turnstile widget, which loads the API.

Neither can be self-hosted: both vendors require the file to load from
their own origin, so the approach used for the country flag font does
not transfer.

Only `script-src` needs the two hosts. `frame-src 'self' https:` already
admits the iframes each vendor opens, and neither reported a connect-src
violation across those 52 documents, which says their API calls happen
inside those frames rather than from our page.
@Piccirello Piccirello self-assigned this Sep 12, 2026
@trunk-io

trunk-io Bot commented Sep 12, 2026

Copy link
Copy Markdown

😎 Merged directly without going through the merge queue, as the queue was empty and the PR was up to date with the target branch - details.

@github-actions

github-actions Bot commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

🤖 CI report

⚠️ Trunk lane — backend Python lane

This PR is assigned to the backend Python lane. It runs backend Python tests and may merge in parallel with PRs in other lanes.

Duplication (Python) — clean

New Python code duplication introduced by this branch. Fails at 70+ tokens in app code, or 150+ tokens when both copies live in test files. Advisory while the gate proves itself: extract a shared helper instead of copying.

Duplication (TypeScript) — clean

New TypeScript code duplication introduced by this branch. Fails at 70+ tokens in app code, or 150+ tokens when both copies live in test files. Advisory while the gate proves itself: extract a shared helper instead of copying.

Playwright — all passed

All tests passed.

View test results →

@Piccirello
Piccirello marked this pull request as ready for review September 13, 2026 00:02
@Piccirello Piccirello added the stamphog Request AI approval (no full review) label Sep 13, 2026
@greptile-apps

greptile-apps Bot commented Sep 13, 2026

Copy link
Copy Markdown
Contributor
Prompt To Fix All With AI
### Issue 1
posthog/middleware.py:1336
**Missing CSP regression coverage**

The new allowlist entries are not covered by `TestCSPMiddleware`, so CI cannot detect either origin being removed before CSP enforcement breaks Stripe payments or Turnstile signup challenges. Add focused assertions that the app policy's `script-src` directive contains both exact origins; this avoids pinning the complete policy string.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Reviews (1): Last reviewed commit: "fix(csp): allow the Stripe and Turnstile..." | Re-trigger Greptile

Comment thread posthog/middleware.py

@stamphog stamphog Bot 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.

The review did not complete.

Stamphog hit an error and produced no verdict for this commit.

Push a new commit to try again.

@trunk-io

trunk-io Bot commented Sep 13, 2026

Copy link
Copy Markdown

Static BadgeStatic BadgeStatic Badge

View Full Report ↗︎Docs

@Piccirello Piccirello added stamphog Request AI approval (no full review) and removed stamphog Request AI approval (no full review) labels Sep 13, 2026

@stamphog stamphog Bot 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.

Approved.

CSP change is security-sensitive but narrowly scoped and well-justified; author has STRONG familiarity (100% of touched lines, 160 recent merged PRs in this path) which stands in for independent assurance, and Greptile's only comment was a non-blocking test-coverage suggestion.

  • Author wrote 100% of the modified lines and has 160 merged PRs in these paths (familiarity STRONG).
  • 👍 on the PR from greptile-apps[bot].
Gate mechanics and policy version
Gate Result
prerequisites all clear
deny-list no deny categories matched
size 10L, 1F substantive — within ceiling
tier T1-agent / T1a-trivial (10L, 1F, single-area, fix)
stamphog 2.0.0b4 .stamphog/policy.yml @ 127f1c0 · reviewed head 127f1c0

@trunk-io
trunk-io Bot merged commit 16b8582 into master Sep 13, 2026
420 of 429 checks passed
@trunk-io
trunk-io Bot deleted the csp/allow-stripe-and-turnstile branch September 13, 2026 02:24
@deployment-status-posthog

deployment-status-posthog Bot commented Sep 13, 2026

Copy link
Copy Markdown

Deploy status

Environment Status Deployed At Workflow
dev ✅ Deployed 2026-09-13 02:50 UTC Run
prod-us ✅ Deployed 2026-09-13 02:59 UTC Run
prod-eu ✅ Deployed 2026-09-13 03:02 UTC Run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stamphog Request AI approval (no full review)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant