Skip to content

feat(atlas): serve the Turnstile challenge page, pinned to an allowed parent - #1076

Merged
Ardnived merged 7 commits into
mainfrom
feat/1072-atlas-challenge
Nov 3, 2026
Merged

Ardnived merged 7 commits into
mainfrom
feat/1072-atlas-challenge

Conversation

@Ardnived

@Ardnived Ardnived commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • GET /api/atlas/challenge serves the Turnstile challenge the Atlas widget frames. This service now holds both halves of the key: TURNSTILE_SITE_KEY joins the secret.
  • The page renders only for an allowed parent origin, 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: the frame-src directive, or the domain to list.
  • Allowed parents: every published client's allowedDomains (same matcher as API origin enforcement), the two first-party frontends and their subdomains, our Cloudflare Workers preview subdomain, and loopback.
  • Open question 1 → A. An empty allowedDomains contributes nothing here.
  • In production, a Cloudflare test site key is refused (Support for screenshot links in translation schema #259's guard, moved here with the key).

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 proposed

  • Next would drop the header. It keeps a route's own Content-Security-Policy only when next.config.mjs hasn't already set one, and it has, on /:path* (next/dist/server/send-response.js). So the route's frame-ancestors would never be sent.
  • The admin's global frame-src would block Turnstile inside this page. For the same reason, it now admits challenges.cloudflare.com.
  • It checks every ancestor. An iframe embed puts the widget on sahajatlas.com inside 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.
  • A refused frame is silent to its parent. The widget could only fail at its 10 s timeout.

Configuration after merge

Where Change
Railway production set TURNSTILE_SITE_KEY (the real 0x… site key paired with TURNSTILE_SECRET_KEY)
Cloudflare Turnstile dashboard the widget's hostname list becomes cloud.sydevelopers.com only
Client records any client whose embed host is on no client's allowedDomains list gets the captcha-blocked screen, and the widget's console names the host to check
SahajAtlasWeb Workers Builds delete VITE_TURNSTILE_SITE_KEY (the widget no longer reads it)

The tracked .env carries Cloudflare's always-passes test pair, so PR previews and local dev need nothing.

Test results

  • Lean gate: ✓ lint, format, typecheck, typecheck:tests, test:unit (235 files, 3040 tests)
  • tests/unit/atlas-challenge.spec.ts (49): runs the page's inline script in a vm context against a fake window. Watched fail with messages posted to '*', with reset accepted 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.
  • Not verified in a browser. The widget's earlier same-origin page was watched solving; this one is the same protocol on a new origin and has not been.

Manual verification (needs this PR's preview, or production after merge)

  1. curl -s "$PREVIEW/api/atlas/challenge?parent=http://localhost:5174" | grep sahaj-atlas-turnstile: expect the page and 200.
  2. curl -s -D - -o /dev/null "$PREVIEW/api/atlas/challenge?parent=https://www.example.org": expect 403 and cache-control: no-store. ⚠ A GET with -D -, never curl -I — no Payload route answers HEAD, so a HEAD is 404 whatever the parent. Measured on this PR's preview.
  3. After both PRs deploy: register on https://shrimataji.org/test/kn/meditation-centers-in-uk/ and submit the report form on https://wemeditate.com/map.
  4. On SahajAtlasWeb#355's own Workers preview, the widget's captcha should render rather than show the blocked screen — that path exists only since the preview subdomain was listed.

Notes for reviewer

  • The preview subdomain is a judgement call worth checking: *.contact-c66.workers.dev is 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 *.host and 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.allowedDomains changes 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 no validate, so a future entry like *.pages.dev would let any tenant of that suffix harvest real visitors' tokens. Matching is host-only, so http:// 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.
  • feat(atlas): serve the Turnstile challenge, gated by client domains #1072's acceptance criteria 1-3 and most of its verification checklist still describe the frame-ancestors header 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

Devindra and others added 2 commits November 3, 2026 10:05
… 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]>
@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-1076 November 3, 2026 17:17 Destroyed
@railway-app

railway-app Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

🚅 Deployed to the SahajCloud-pr-1076 environment in sahajcloud

Service Status Web Updated
SahajCloud 🕒 Building (View Logs) Web Nov 3, 2026 at 9:44 pm UTC
1 service not affected by this PR
  • mailpit

@sydevs-bot

sydevs-bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

🤖 no session running

recent dispatches
  • 17:46Z address-review · attempt 1 · session · done
  • 17:46Z address-review · attempt 1 · session
  • 17:34Z review-pr · attempt 1 · session · done
  • 17:34Z review-pr · attempt 1 · session

Written by the sydevs dispatcher. Sessions never edit this comment.

@sydevs-bot sydevs-bot moved this from Awaiting to Working in SYDevelopers Technical Roadmap Nov 3, 2026

@sydevs-bot sydevs-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧐 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 -sI sends HEAD, which no Payload endpoint answers, so it returns 404 for any parent, never the documented 403. A GET does.
  • consider — parentOrigin states originOf'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 → 403 no-store, {"refusal":"origin"}, no site key. Neither carries X-Frame-Options or a route frame-ancestors.
  • Consumer SahajAtlasWeb@claude/fix-343-turnstile-frame: channel, the four message types, both reason values, reset and all four query parameters agree; it pins event.source and event.origin.
  • Ladder: originOf found (flagged); isProductionDeployment has four non-storage callers; isTestSiteKey replaces 431 deleted consumer lines.
  • clients carries versions.drafts, so the _status filter is real, and is excluded from usagePlugin.

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


Generated by Claude Code

@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 3, 2026
@sydevs-bot sydevs-bot moved this from Working to Pending in SYDevelopers Technical Roadmap Nov 3, 2026
@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 3, 2026
@sydevs-bot sydevs-bot moved this from Pending to Working in SYDevelopers Technical Roadmap Nov 3, 2026
`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
@sydevs-bot

Copy link
Copy Markdown
Contributor

Both critic threads addressed, pushed for relay.

  • Preview hosts (thread) — *.contact-c66.workers.dev joins the built-in parents (45218b4). Narrowing it is yours to call — see Notes for reviewer.
  • originOf (thread) — parentOrigin parses through the helper (dbfed17).
  • Body, verification step 2 — curl -sI sends HEAD, which this route answers 404 for any parent. Measured on the preview; replaced with a GET.

tests/int/atlas-challenge.int.spec.ts ran here, 9 passed — the body said CI would be its first run.

Security review: no high or medium findings. Two sub-threshold notes on allowedDomains are in the body.

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


Generated by Claude Code

@sydevs-bot sydevs-bot removed the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 3, 2026
@sydevs-bot sydevs-bot moved this from Working to Awaiting in SYDevelopers Technical Roadmap Nov 3, 2026
@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-1076 November 3, 2026 18:08 Destroyed
@sydevs-bot
sydevs-bot enabled auto-merge November 3, 2026 18:25
Devindra and others added 2 commits November 3, 2026 14:43
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]>
@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-1076 November 3, 2026 21:44 Destroyed
@Ardnived
Ardnived merged commit 29a5dff into main Nov 3, 2026
8 of 9 checks passed
@Ardnived
Ardnived deleted the feat/1072-atlas-challenge branch November 3, 2026 21:45
@sydevs-bot sydevs-bot moved this from Awaiting to Done in SYDevelopers Technical Roadmap Nov 3, 2026
sydevs-bot pushed a commit that referenced this pull request Nov 3, 2026
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
sydevs-bot pushed a commit that referenced this pull request Nov 3, 2026
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
Ardnived pushed a commit that referenced this pull request Nov 5, 2026
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

This branch was successfully deployed

No deployments
sahajcloud / SahajCloud-pr-1076 — 97a3439a Deployed Nov 3, 2026 by railway-app[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

feat(atlas): serve the Turnstile challenge, gated by client domains

3 participants