Skip to content

docs(embedding): settle whether Turnstile needs 'unsafe-eval' in script-src #272

Closed

Description

@sydevs-bot

Summary

A host following docs/embedding.md's CSP block gets an EvalError in their console on every
page view. Turnstile evaluates a string as JavaScript, and the documented script-src carries no
'unsafe-eval'. The widget kept working in every run, so the recommended policy may well be
right — but the guide says nothing about the refusal, and nobody has checked whether a challenge
can actually be solved under it. Every write the widget makes is captcha-gated, so that gap
matters more than a console message.

Found incidentally while measuring style-src for #263.

Approach

What was observed (Chromium 141, 2026-10-10, a built map=false embed served from one localhost
origin under the exact policy in docs/embedding.md:789-798, SahajCloud stubbed per
docs/rules/mapbox.md):

  • A securitypolicyviolation with effectiveDirective: "script-src" and blockedURI: "eval",
    3 runs out of 3.
  • The console message: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'self' https://api.mapbox.com https://challenges.cloudflare.com https://cdn.usefathom.com".
  • The violation has source: null and no stack, which is what a cross-origin script produces.
    It fires once https://challenges.cloudflare.com/turnstile/v0/g/<id>/api.js has loaded, and it
    fires on a route where the place-search library never mounts — so the geocoder is ruled out.
  • grep -c 'new Function(\|[^.$a-zA-Z_]eval(' over every chunk in dist/assets/ is zero, so
    the call is not in our bundle.
  • The widget rendered, routed and read its data normally in every run. Nothing visible failed.

What was not established, and is the point of this ticket: whether the Turnstile challenge
completes and yields a token under that policy. The runs had no configured report form
(sy-atlas-config.reportIssueForm was null in the stub) and no registration path, so the captcha
was loaded but never solved.

Three places move depending on the answer:

  • docs/embedding.md:789-798 — the policy block, if 'unsafe-eval' turns out to be required.
  • docs/embedding.md:811 — the script-src / challenges.cloudflare.com row, whose "Blocked ⇒"
    column already says a blocked Turnstile stops the widget outright.
  • docs/embedding.md's troubleshooting table — a host who sees this EvalError and finds nothing
    about it in the guide has no way to tell a harmless refusal from the fatal one above it.

CHANGELOG.md gets an entry only if the recommended policy changes. A note about a refusal that
costs nothing is guide accuracy, not something a host can observe.

⚠ Do not answer this from the Turnstile docs alone. Cloudflare ships more than one challenge
mode and this repo pins the always-passes test site key in .env (VITE_TURNSTILE_SITE_KEY,
1x00000000000000000000AA), which may not exercise the same code path as the production key. The
question is what the production key does on a host page, under this policy.

Acceptance criteria

  • It is established, in a browser, whether a Turnstile challenge yields a token under the
    documented script-src with no 'unsafe-eval', using the production site key.
  • If it does: docs/embedding.md names the EvalError as expected and harmless, so a host
    does not mistake it for the fatal blocked-Turnstile row, and the policy block is unchanged.
  • If it does not: 'unsafe-eval' joins the script-src line in the policy block, the row
    says why, and CHANGELOG.md carries an entry — a host can observe this one.
  • Either way the claim is dated and names the browser, as the style-src note added in
    docs(embedding): re-measure what a missing style-src 'unsafe-inline' actually breaks #263 does.

Verification checklist

  • pnpm build, then serve dist/ and a host page from one origin with a
    Content-Security-Policy response header. pnpm review:embed sends no header, so front it
    with a proxy or a throwaway server.
  • Send the policy from docs/embedding.md:789-798 verbatim, with the production
    VITE_TURNSTILE_SITE_KEY built in, and a client key the backend accepts.
  • Open the report-issue form, solve the challenge, and record whether a token is produced and
    whether the submission is accepted.
  • Repeat with 'unsafe-eval' added to script-src and compare.
  • Record the securitypolicyviolation entries and console text from both runs.
  • grep -n "unsafe-eval" docs/embedding.md — every hit agrees with what was measured.
  • pnpm lint && pnpm typecheck && pnpm test:run pass.

Notes

No automated lane can hold this. The smoke lane reads deployed file content over fetch, so
it cannot observe a CSP decision made by a rendering engine — docs/testing.md states the same
limit. The guard is that the claim was observed once and dated.

Related: #182 made Turnstile essential and wrote the script-src and
frame-src rows this ticket would amend. #263 is the style-src half of the
same table, found by the same harness.

🤖 Written by the sydevs autonomous loop — see what this is

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    proposal

    Type

    Fields

    Priority

    Medium

    Hold Until

    None yet

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions