Repository navigation
feat(atlas): serve the Turnstile challenge page, pinned to an allowed parent - #1076
Conversation
… parent `GET /api/atlas/challenge?parent=<origin>&theme&language[&probe=1]` is the challenge the Atlas widget frames (sydevs/SahajAtlasWeb#343). Turnstile checks the hostname of the document that renders it, so serving it here means one hostname covers every partner page, and this service now holds both halves of the key: `TURNSTILE_SITE_KEY` joins the secret. The page renders only for a `parent` whose host is in some published client's `allowedDomains`, a first-party frontend (`SAHAJATLAS_URL`, `WEMEDITATE_WEB_URL` and their subdomains) or loopback, and posts every message to exactly that origin. The browser then delivers a token to no other parent, whatever the frame URL claims. A refusal posts `reason: 'origin'` so the widget fails at once and names the host to add. Matching is `originEnforcement.ts`'s own, with one deliberate difference: an empty `allowedDomains` contributes nothing here (question 1, option A), since this page is anonymous and "empty means any" would make it a token minter for every site. Not `frame-ancestors`, which the ticket proposed, for three reasons. Next 16 drops a route's own `Content-Security-Policy` once `next.config.mjs` has set one on `/:path*`, so the directive would never have been sent. It checks every ancestor, which breaks an iframe embed — the widget on the Atlas origin inside a partner page that no list names — although the token only ever reaches the immediate parent. And a frame refused that way is silent to its parent. The same Next behaviour means the admin's global `frame-src` reaches this page, so it now admits `challenges.cloudflare.com`. Closes #1072 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The widget's release guard (sydevs/SahajAtlasWeb#259) failed a production build whose site key was one of Cloudflare's dummies. The key lives here now, and the tracked `.env` carries the always-passes test pair, so a production service that picked up both halves would run a captcha that accepts everything with nothing failing to say so. On production, the challenge page now answers that key with the same 503 refusal as a missing one, and logs it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🚅 Deployed to the SahajCloud-pr-1076 environment in sahajcloud
1 service not affected by this PR
|
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 Adversarial review
The PR drops the ticket's frame-ancestors plan for a pinned parent, and the reasons hold — the preview's challenge response carries next.config.mjs's policy and no route policy of its own. Pinning is also the stronger property, since iframe embeds then need no listing. The diff matches the problem: the folder shape atlas/seo and atlas/sitemap use, and an allowlist reusing parseAllowedDomains / isHostAllowed / normalizeHost. Your sign-off is owed on the approach, not the code: acceptance criteria 1-3 and three of four verification items describe a header this PR deliberately never sends, and #1072 was not revised.
Findings
- should-fix — the built-in list misses the preview hosts its own comment names, so every SahajAtlasWeb preview gets the captcha-blocked screen (
challengeRequest.ts:70). - should-fix — PR body, manual verification 2:
curl -sIsends HEAD, which no Payload endpoint answers, so it returns 404 for any parent, never the documented 403. A GET does. - consider —
parentOriginstatesoriginOf's parse rule a second time (challengeRequest.ts:25).
What was checked
- Railway preview: allowed → 200
text/html,private, max-age=300, config pinned to that parent; refused → 403no-store,{"refusal":"origin"}, no site key. Neither carriesX-Frame-Optionsor a routeframe-ancestors. - Consumer
SahajAtlasWeb@claude/fix-343-turnstile-frame: channel, the four message types, bothreasonvalues,resetand all four query parameters agree; it pinsevent.sourceandevent.origin. - Ladder:
originOffound (flagged);isProductionDeploymenthas four non-storage callers;isTestSiteKeyreplaces 431 deleted consumer lines. clientscarriesversions.drafts, so the_statusfilter is real, and is excluded fromusagePlugin.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
`builtInParentHosts`' comment claimed the `*.` wildcard covered preview hosts. It does not: a SahajAtlasWeb or WeMeditateWeb PR preview lands on the Cloudflare account's Workers subdomain, under neither first-party host, and a preview build keeps `.env`'s `VITE_SAHAJCLOUD_URL`, so it frames production. Every Atlas preview was therefore refused `reason: 'origin'` and showed the captcha-blocked screen — in the one place a consumer PR is reviewable in a browser. The subdomain joins the built-in list, with loopback's reasoning: a page there is publishable only by someone who can deploy to our Cloudflare account, who already holds both halves of the Turnstile credential, so no token reaches a page in a stranger's visitor's browser. The wildcard's own claim is corrected to what it buys — each frontend's design playground. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjVcqUjptsqD2WQy41P
`parentOrigin` restated `@/lib/utilities/url`'s rule — parse with `URL.parse`, and treat an opaque origin as none — which that module's docblock says is stated once. Two rules here are genuinely the endpoint's: http(s) only, and `origin === raw`, since the widget sends a bare `location.origin`. Those stay; the parse is the helper's now, and its docblock names its third consumer. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjVcqUjptsqD2WQy41P
`docs/rules/api-clients.md` still described the allowlist as the clients' domains plus the frontends and loopback. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjVcqUjptsqD2WQy41P
|
Both critic threads addressed, pushed for relay.
Security review: no high or medium findings. Two sub-threshold notes on 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
SahajAtlasWeb#355 folds `src/lib/turnstile-frame.ts` into `src/hooks/use-turnstile.ts`, its only consumer once the challenge page moved here. The protocol is unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The widget no longer tells an origin refusal from any other failure: its console names both fixes, and the browser logs a CSP refusal itself beside that line. So `reason` had no reader (sydevs/SahajAtlasWeb#355). The refusal still goes to `'*'` at once, which spares the widget its handshake timeout. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Seven conflicts, all from main adding GET /api/atlas/challenge (#1076) and retiring test files (#1061) while this branch added the two Wix endpoints. Both sides kept throughout: - payload.config.ts: the endpoints array registers all five — atlasSeo, atlasSitemap, atlasChallenge, atlasWixRoute, atlasWixSitemap. - docs/rules/endpoints.md and src/AGENTS.md: the root-endpoint list now carries the challenge page and the two Wix serializers, each keeping its own rationale. The four count figures are re-measured rather than taken from either side: neither 243/3175 nor 235/3036 describes the merged tree. The lane is 244 files / 3224 tests, which is what perf-figures-pinned.spec.ts and conflict-markers.spec.ts both now pass against. Lean gate green: lint, format, typecheck (src), typecheck (tests), 244 unit files / 3224 tests, 117 s. Targeted integration: atlas-challenge.int.spec.ts and atlas-wix.int.spec.ts, 34 passed. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjXi1q6VpRKEejFsnr8
Both sides moved the figures `perf-figures-pinned.spec.ts` holds the docs to, from 234 / 2992: this branch's new spec made them 235 / 3003, #1076's made them 235 / 3036. The merged tree carries both specs, so neither number is right — measured here, and written as 236 / 3054. `docs/rules/testing-reqs.md` keeps this branch's sentence: a count inside a dated measurement is falsified by the next spec, so the live figure stays in the one bullet that describes the command. #1076's update to that sentence is carried forward there. `AGENTS.md` merged clean and the merge falsified it — it is the spec's fourth consumer, so its file count moves too. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjWPTLxgFvUSEMMjoBs
Seven conflicts, all from main adding GET /api/atlas/challenge (#1076) and retiring test files (#1061) while this branch added the two Wix endpoints. Both sides kept throughout: - payload.config.ts: the endpoints array registers all five — atlasSeo, atlasSitemap, atlasChallenge, atlasWixRoute, atlasWixSitemap. - docs/rules/endpoints.md and src/AGENTS.md: the root-endpoint list now carries the challenge page and the two Wix serializers, each keeping its own rationale. The four count figures are re-measured rather than taken from either side: neither 243/3175 nor 235/3036 describes the merged tree. The lane is 244 files / 3224 tests, which is what perf-figures-pinned.spec.ts and conflict-markers.spec.ts both now pass against. Lean gate green: lint, format, typecheck (src), typecheck (tests), 244 unit files / 3224 tests, 117 s. Targeted integration: atlas-challenge.int.spec.ts and atlas-wix.int.spec.ts, 34 passed. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjXi1q6VpRKEejFsnr8
Summary
GET /api/atlas/challengeserves the Turnstile challenge the Atlas widget frames. This service now holds both halves of the key:TURNSTILE_SITE_KEYjoins the secret.parentorigin, and posts every message to exactly that origin, so the browser delivers a token to no other page. A refusal is posted at once, so the widget fails without waiting out its handshake timeout, and its console names both fixes: theframe-srcdirective, or the domain to list.allowedDomains(same matcher as API origin enforcement), the two first-party frontends and their subdomains, our Cloudflare Workers preview subdomain, and loopback.allowedDomainscontributes nothing here.Merge together with sydevs/SahajAtlasWeb#355, which points the widget at this page and deletes its own copy.
Why not
frame-ancestors, as the issue proposedContent-Security-Policyonly whennext.config.mjshasn't already set one, and it has, on/:path*(next/dist/server/send-response.js). So the route'sframe-ancestorswould never be sent.frame-srcwould block Turnstile inside this page. For the same reason, it now admitschallenges.cloudflare.com.sahajatlas.cominside a partner page that no list names. The token only ever reaches the immediate parent, and parent-pinning checks exactly that, so iframe embeds need no listing.Configuration after merge
TURNSTILE_SITE_KEY(the real0x…site key paired withTURNSTILE_SECRET_KEY)cloud.sydevelopers.comonlyallowedDomainslist gets the captcha-blocked screen, and the widget's console names the host to checkVITE_TURNSTILE_SITE_KEY(the widget no longer reads it)The tracked
.envcarries Cloudflare's always-passes test pair, so PR previews and local dev need nothing.Test results
typecheck,typecheck:tests,test:unit(235 files, 3040 tests)tests/unit/atlas-challenge.spec.ts(49): runs the page's inline script in avmcontext against a fake window. Watched fail with messages posted to'*', withresetaccepted from any origin, and with the preview subdomain unlisted.tests/int/atlas-challenge.int.spec.ts: ✓ 9 passed, on the review run's container. The implementing machine had no PostgreSQL.Manual verification (needs this PR's preview, or production after merge)
curl -s "$PREVIEW/api/atlas/challenge?parent=http://localhost:5174" | grep sahaj-atlas-turnstile: expect the page and200.curl -s -D - -o /dev/null "$PREVIEW/api/atlas/challenge?parent=https://www.example.org": expect403andcache-control: no-store. ⚠ A GET with-D -, nevercurl -I— no Payload route answers HEAD, so a HEAD is404whatever the parent. Measured on this PR's preview.https://shrimataji.org/test/kn/meditation-centers-in-uk/and submit the report form onhttps://wemeditate.com/map.Notes for reviewer
*.contact-c66.workers.devis this Cloudflare account's, so only someone who can deploy there can mint a token, and they already hold both halves of the key. The matcher takes an exact host or*.hostand nothing finer, so a per-Worker pattern is not expressible — say the word and it comes back out, at the cost of the only browser-reviewable path for Password protect Sahaj Cloud docs website, and make sure it is prevented from being indexed #355.clients.allowedDomainschanges meaning here, and keeps its old validation: behind an API key it was a self-restriction, and on this page it is an anonymous grant. The field has novalidate, so a future entry like*.pages.devwould let any tenant of that suffix harvest real visitors' tokens. Matching is host-only, sohttp://and any port are admitted for a listed host. Both are sub-threshold today — every real record is one plain domain — and both are yours to decide on.frame-ancestorsheader this PR deliberately never sends. Left unrevised on purpose: that divergence is what your sign-off on the approach is for.Closes #1072
🤖 Generated with Claude Code
https://claude.ai/code/session_01Mg9rjVcqUjptsqD2WQy41P