Repository navigation
fix(api): allow the Turnstile token header through CORS preflight - #1085
Merged
Merged
Conversation
The Atlas widget sends every registration and issue report from the visitor's browser with an `x-turnstile-token` header. `cors.headers` appended only the live-preview secret to Payload's allow-list, so the preflight answered without the token header and the browser dropped the POST unsent. Every atlas registration and report has failed this way since the widget started sending the header, with nothing in this server's logs: production HTTP logs show only OPTIONS on /api/user-submissions, no POST. The header name moves to one constant, `TURNSTILE_TOKEN_HEADER`, read by both the CORS config and the write guard, so the two cannot drift apart. The int spec asserts the allow-list carries it (watched failing against the old config), and the e2e preflight spec replays the widget's own preflight against the preview. Refs sydevs/SahajAtlasWeb#259 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🚅 Deployed to the SahajCloud-pr-1085 environment in sahajcloud
1 service not affected by this PR
|
railway-app
Bot
temporarily deployed
to
sahajcloud / SahajCloud-pr-1085
November 5, 2026 23:08
Destroyed
Contributor
Ardnived
added a commit
to sydevs/SahajAtlasWeb
that referenced
this pull request
Nov 5, 2026
…g answered (#365) * fix(registration): blame the connection, not the captcha, when nothing answered Every atlas registration failed in production because SahajCloud's CORS preflight did not allow `x-turnstile-token` (fixed in sydevs/SahajCloud#1085). The browser dropped the POST unsent, and the form told the visitor "the security check needs doing again" — advice that could not help, since the captcha had passed — in the brand blue a refusal uses rather than the error colour. The generic failure now renders as `danger`. Its sentence follows whether anything answered: a request that got no HTTP response (offline, SahajCloud unreachable, a rejected preflight) never reached the captcha check, so it says `common.errors.offline` or `common.errors.server` by `classifyError`; an uncoded response may have spent the token, so it keeps the "wait for the check, then register again" sentence. Named refusals keep their blue alert. The report form already split this way and needs no change. A smoke case replays the widget's own preflight against the SahajCloud origin the bundle names, so the cross-repo contract fails a lane rather than every visitor. It is red against production until #1085 deploys. Refs #259 Co-Authored-By: Claude Opus 5.5 <[email protected]> * docs(testing): the smoke lane is 18 cases with the preflight check, not 19 CI counted 18, the new preflight case included: the lane was 17 before it, so the '18' in production-smoke.yml was already one ahead. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
sydevs-bot
pushed a commit
that referenced
this pull request
Nov 5, 2026
The smoke spec `cors-preflight.e2e.spec.ts` failed on
`expect(allowed).toContain('x-turnstile-token')`, reading back only
`…, x-sahajcloud-preview-secret` from the preview.
Nothing in this branch caused it, and nothing in this branch could fix it.
#1085 landed on main one commit ago, adding both the assertion and the
`TURNSTILE_TOKEN_HEADER` entry in `payload.config.ts` that satisfies it. The
two reach CI by different routes: Actions checks out the pull request's merge
ref, so the suite already ran main's new assertion, while Railway builds the
preview from the branch head, which predates the config change. The spec
therefore asked a server built without the header for that header.
Merging the base closes the gap — the next preview builds with the entry.
Refs #1084
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjWtNAKQrTJVjeBpXuQ
Ardnived
added a commit
that referenced
this pull request
Nov 6, 2026
* fix(api): accept an issue report from an API client Every atlas issue report was refused with "The following field is invalid: System > Form". The form-builder plugin proves a submission's form exists with `findByID` on the caller's req and no `select`; for an API client that read trips the select-required client gate, the plugin catches the 400, and reports the form as missing. Production logs show the gate's warning immediately before each refusal. It was hidden until now behind the CORS preflight that dropped every atlas POST (#1085). `perTypeForm` now runs its own existence check: the same `findByID` on the caller's req, so a client still cannot cite a form it may not read, with a one-column `select` that satisfies the gate. No spec could see this because the test harness registered `usagePlugin` before `formsPlugin`, the reverse of payload.config.ts, so `forms` and `user-submissions` never received the client read gates under test. The harness now mirrors production, and a new case submits a report as the atlas client through the write guard: it failed with the production error before the fix and passes after. Refs sydevs/SahajAtlasWeb#259 Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(api): hand the plugin's form check a trusted req The form-builder plugin already owns the form-exists check. Rebuilding it here duplicated the plugin's refusal string, the `extractID` cast and a bare `catch` that reported a dropped connection as a missing form. `asTrustedReq` is this repo's opt-out for an internal read forwarding the caller's `req` with no `select`, which five modules already use. The plugin stays the single owner of its check, and origin enforcement still applies to the forwarded read. Trade: the plugin's read passes no `select` and runs at the default depth, so it is heavier than a one-column one. Restores the `src/collections/AGENTS.md` pointer the earlier docblock rewrite dropped: supplying `validate` replaces Payload's default, which is why `relationshipValidation` is composed at all. Addresses #1089 (comment) Addresses #1089 (comment) Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjV2RHc4z2qB8cRpKq7 * fix(tests): assert the form refusal's own message `toThrow(/Form/)` matched the wrapper, `The following field is invalid: System > Form`, so it would pass on any refusal naming that field. The case now reads `data.errors` and pins the field's own sentence, as `user-submissions-create` and `forms-action-type` do. This does not make the case discriminate the defect, and nothing can: the plugin catches both a genuinely missing form and the select gate's 400, and returns the same sentence for each. The accept case beside it is the regression test — reproduced against the old validator, it fails with the production `System > Form`. Addresses #1089 (comment) Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Mg9rjV2RHc4z2qB8cRpKq7 --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
x-turnstile-tokenheader, andcors.headers(src/payload.config.ts) appended only the live-preview secret to Payload's allow-list. The preflight answers without the token header, so the browser drops the POST before it leaves the page.sahajatlas.com/uk/london/1326/register).OPTIONS /api/user-submissions 200, and noPOST.cors.headers. The name becomes one constant,TURNSTILE_TOKEN_HEADER(src/lib/turnstile/header.ts), read by both the CORS config and the write guard, so the two cannot drift apart.How long:
cors.headershas been unchanged since July (#579), and the widget has sent this header since sydevs/SahajAtlasWeb#184 (2026-08-31).Refs sydevs/SahajAtlasWeb#259 (criterion 4: a test sign-up and report from the live site). The widget's misleading error copy and colour are fixed separately in SahajAtlasWeb.
Test results
tests/int/cors-config.int.spec.tsasserts the allow-list carriesx-turnstile-token. I watched it fail against the old config (expected 'origin, x-requested-with, content-typ…' to contain 'x-turnstile-token'), and it passes with the fix.tests/e2e/cors-preflight.e2e.spec.tsadds a case that replays the widget's own preflight (POST,authorization, content-type, x-turnstile-token) on/api/user-submissionsagainst the preview.tests/int/atlas-submission-routing.int.spec.tsandtests/int/client-origin-enforcement.int.spec.ts(the write paths that read the header) pass: 26 tests..claude/skills/pr-prep/check.shpasses: lint, format, both typechecks, unit lane 239 files / 3,084 tests.Manual verification
curl -si -X OPTIONS <preview>/api/user-submissions -H 'Origin: https://sahajatlas.com' -H 'Access-Control-Request-Method: POST' -H 'Access-Control-Request-Headers: authorization,content-type,x-turnstile-token'. Confirm thataccess-control-allow-headersincludesx-turnstile-token.POST /api/user-submissionsshould appear in the Railway HTTP logs.🤖 Generated with Claude Code