Repository navigation
feat(turnstile): treat Turnstile as essential — gate registration, and stop degrading to mailto - #184
Conversation
…op the mailto Registration is what the atlas exists for, and a registration cannot be sent without a Turnstile token. So a challenge that cannot load is a broken embed rather than a form that degrades, and the widget now says so. Three changes, in the order they matter: - `useTurnstileGuard` loads the challenge as soon as `FullInterface` mounts and throws `captcha-blocked` if it cannot. Eager but non-blocking: nothing waits on the probe, so a healthy embed pays nothing and a broken one is loud without a visitor having to try to register first. Mounted with the INTERFACE, never the shell — a collapsed compact card must not inject a third-party script into a host's page for a button nobody pressed. - `createRegistration` sends the solved token in the `x-turnstile-token` header, which is where SahajCloud's write-guard reads it (sydevs/SahajCloud#629). The form gates its submit on a solved challenge and resets it after any refusal — the token is single-use and the server redeems it before doing the work. - The report form's `mailto:` degradation is gone. It published [email protected] on every host page whose CSP blocked the challenge. `captcha-blocked` is a new `ErrorKind` rather than a `config` message override: it withholds the report CTA, because the report form is captcha-gated too and pointing a viewer at it would offer a second form the same failure disabled. It DOES retry — a blocked script and a failed script request are one verdict here, and the second recovers. Closes #182. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Deploying sahajatlas-design with
|
| Latest commit: |
81393dc
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://6ca76bd8.sahajatlas-design.pages.dev |
| Branch Preview URL: | https://claude-feat-turnstile-essent.sahajatlas-design.pages.dev |
The Native story now renders a Turnstile challenge and a Register button that stays disabled until it is solved. Say so, rather than leaving a reader to wonder whether the button is broken — and note that `.env`'s always-passes test key is what makes it solve itself in Ladle. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Deploying sahajatlas with
|
| Latest commit: |
81393dc
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://8125fb57.sahajatlas.pages.dev |
| Branch Preview URL: | https://claude-feat-turnstile-essent.sahajatlas.pages.dev |
…stem narration Review feedback on #184. - `REFUSAL_MESSAGE_KEYS` now spans every code a `RegistrationRefusedError` can carry, so `captcha_failed` reads as one code among the rest rather than a parallel concept. The synced-union totality check survives as `STATE_MESSAGE_KEYS`, which the merged record spreads. - `containerRef` -> `challengeRef` in `useTurnstile` and both call sites. - Story descriptions drop the header/env/issue-number detail. - Source comments narrating the removed `mailto` fallback are gone. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
All six threads addressed and resolved; green on Five were documentation — story descriptions trimmed to what a designer sees, and the comments narrating the removed Nothing here changes behaviour. Same copy per refusal code, same generic fallback, same challenge reset, same disabled conditions. The one thing I checked rather than assumedMerging the maps risked losing the const STATE_MESSAGE_KEYS: Record<EventRegistrationErrorCode, string> = { … }
const REFUSAL_MESSAGE_KEYS: Record<RegistrationErrorCode, string> = {
...STATE_MESSAGE_KEYS,
captcha_failed: 'registration.captcha_retry',
}Both halves verified by breaking them:
The second naming Also in this push: Locally: lint, typecheck, typecheck:tests, 1460 unit specs. On CI all five checks green on The judgement call from the original description still stands and still wants your eye: this PR makes a host page whose CSP blocks 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
Ardnived
left a comment
There was a problem hiding this comment.
Looks good, ready to merge
Resolves the CHANGELOG.md link-definition conflict left by #184's squash merge: both [#181] and [#184] definitions belong, in numeric order. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_018oiV3fKDoPhKcjhX39LvWp
Closes #182. Unblocks sydevs/SahajCloud#629, which is
Blocked by:this.This is a breaking change for hosts, deliberately. A page whose CSP blocks
challenges.cloudflare.comused to get a working atlas with a degraded report form; it now gets an error screen and no atlas. The argument for that is the whole ticket: every write the widget makes is captcha-gated, registration included — so on such a page a visitor could browse classes and then silently fail to sign up for one, while the site's owner had no reason to think anything was wrong. Failing loudly is worse for five minutes and better thereafter.The three pieces
1. The eager check.
useTurnstileGuardstarts the script load whenFullInterfacemounts and throwscaptcha-blockedif it cannot complete. Eager but non-blocking — your answer on the ticket — so nothing waits on a third-party script and only a negative verdict does anything.2. The token moves to the header.
createRegistrationsendsx-turnstile-token, which is where SahajCloud's write-guard reads it. The submit is gated on a solved challenge, and any refusal resets it — a token is single-use and the server redeems it before doing the work it gates, so re-sending it would fail for the rest of the form's life.3. The
mailto:is gone. It published[email protected]on every host page whose CSP blocked the challenge — the address in front of every scraper reading those pages, to solve a problem the host had caused.Two judgement calls I'd like checked
captcha-blockedis a newErrorKind, not aconfigmessage override. It needed a policyconfigcannot express: no report CTA, because the report form is captcha-gated too, so offering it hands the viewer a second form the same failure has already disabled. Exactly the callofflinemakes about the network, one layer along, andREPORTED_KINDSmirrors it.It does retry, which looks wrong beside
config. I setretry: falsefirst;Fallbacks.test.tsx's "never leaves a viewer with no way out" invariant went red and was right to.probeTurnstilereturns the same verdict for a CSP block and for a script request that simply failed on the network, andloadTurnstileclears its cached promise on failure — so a second attempt is a real one, and the transient half genuinely recovers. A CSP block re-fails identically, costing one press.What the eager probe can and cannot see, and why the form keeps its blocked state
The probe is strictly weaker than a real render, and that gap is deliberate rather than overlooked.
Visible from a script load: no site key · a
script-srcrefusingchallenges.cloudflare.com· a script that loads without defining the API (a content blocker or enterprise proxy answering 200 with a stub).Not visible: a
frame-srcblocking the challenge iframe, and a sitekey the embedding domain isn't registered for. Both only surface whenturnstile.renderactually runs.So
useTurnstile's ownblockedstatus stays as the backstop, andReportIssueFormkeeps its "the security check couldn't load" banner over a disabled submit — that state is now rare rather than gone, and its job there is to explain the dead button rather than route around it. Neither check replaces the other.The
captcha_failedcode is not in the synced type union, and cannot be yetEventRegistrationErrorCode(synced from SahajCloud) carries the four state refusals the endpoint raises itself.captcha_failedis thrown a layer above it by the write-guard plugin, which gates every client-originated write.It is also not in that union yet, and the ordering is why: #629 is blocked on this landing — the widget must send the header before the server may start requiring it — so no SahajCloud build emits the code today and a
pnpm types:cmswould not produce it.mutate.tstherefore declaresRegistrationErrorCode = EventRegistrationErrorCode | 'captcha_failed', which is what lets the client be ready first. When a later re-sync folds it into the synced union, that extra member becomes redundant and can go; nothing breaks either way.Deliberately kept out of
REFUSAL_MESSAGE_KEYS, which is a totalRecordover the state codes — its totality is what makes a re-sync fail the build there, and folding in a code from a different layer would break that.Specs, and each defect reintroduced to watch it fail
Per
.claude/rules/tests.md, every new assertion was made to fail at the site that would really cause it, then restored.src/hooks/use-turnstile-guard.test.tsx(jsdom — the verdict arrives from a promise after first paint, so SSR would assert the healthy frame and pass regardless):CompactEmbedView.mount.test.tsxgains the fifth candidate for the four-bug pattern that file exists to catch — and the first whose cost is outside our own page. Reintroducing it as<>{children}<Expandable>{children}</Expandable></>(the interface mounting alongside the card, which is the shape it would really take): 2 red, the new case included.mutate.test.tsgains the header assertion and the unsynced-code refusal.Gate: lint · typecheck · typecheck:tests · 1460 unit (was 1455) · build ·
assert:css·assert:maps·ladle:build.pnpm size: embed 300.5/308 KiB, standalone 297.9/308 — identical tomain, since the guard lands in the lazy interface chunk rather than the eager graph.Host-facing docs
docs/embedding.md:challenges.cloudflare.commoves from "degrades" to fatal across thescript-src,connect-srcandframe-srcrows; the load-bearing list goes from five entries to six; the troubleshooting row that described themailto:degradation now describes the error screen.CHANGELOG.mdleads with the breaking change and what to do about it.Both reference
[#184], which had to be written before this PR had a number — it landed on 184, so the guess held and no follow-up commit is needed. (#181 hit the same wrinkle less luckily:[#164]was already taken in that file by a PR carrying the number of the issue being closed.)