Skip to content

fix(components): a required checkbox or select stops an untouched submit, and the submission proxy guards its input - #301

Merged
sydevs-bot merged 7 commits into
mainfrom
claude/fix-forms-required-fields-and-proxy
Nov 19, 2026
Merged

sydevs-bot merged 7 commits into
mainfrom
claude/fix-forms-required-fields-and-proxy

Conversation

@sydevs-bot

@sydevs-bot sydevs-bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • For a visitor: a required checkbox (a consent box, for example) or a required select no longer submits untouched. Before this change, an unticked required checkbox posted consent: false, and an untouched select posted its first option. Both now stop at the field with the usual "field required" message. Screen readers get the error through aria-describedby, the same way the other fields do. A select with no authored default now starts on its placeholder. An authored default is still kept.
  • For a developer: POST /api/submissions now answers three refusals itself and never calls SahajCloud for them:
    • a missing or empty x-turnstile-token gets 403 captcha_failed;
    • a body over the size bound gets 413 invalid_request, without being read;
    • a body not declared as JSON gets 415 invalid_request.
  • For whoever is on call: failures of both the submission proxy and the live-preview populate proxy now reach Sentry. Before, api-routes.ts imported no Sentry at all, so a form that stopped working was visible only to the visitor who lost their message. The event carries only the status, the refusal code and the error's name. It never carries the body, the token, the visitor's address or SahajCloud's message.

Nothing the visitor sees changes on a refusal. FormBuilder shows every non-ok answer as forms.general.submit_error and re-challenges the captcha.

Findings addressed

  • F2a — a required checkbox was never checked. components/organisms/FormBuilder/FormBuilder.tsx:118 gives the checkbox the same required rule as every other field. In the checkbox and minimal branch, the error <p> gets id=<name>-error, and the control names it through aria-describedby (FormBuilder.tsx:125). Checked on main in Chromium (HeadlessChrome 153): an unticked required checkbox posted consent=false. Pinned by FormBuilder.interaction.test.tsx › "stops an unticked one, and names the error on the control", which fails against main's FormBuilder.tsx, and by "posts a ticked one".

  • F2b — a select started on its first real option. Without an authored default, a select now defaults to the placeholder's '' (FormBuilder.tsx:161), so required can fail. Measured in Chromium. On main, an untouched required select read classes and the form posted it. With the fix, the value is '', the error shows and nothing is posted. An authored default (other) is kept. The server HTML marks the placeholder selected. Pinned by "starts a required one on its placeholder, so an untouched one is stopped" and by FormBuilder.test.tsx › "server-renders a select with no authored default on its placeholder". Both fail against main. "keeps an authored default" pins the authored case.

  • F2c — a tokenless submission was forwarded upstream. server/api-routes.ts:345 now answers a missing or empty token with 403 { ok: false, code: 'captcha_failed' }, the status the proxy already passes captcha_failed through with. The check runs after body validation, so a malformed body still gets invalid_request. Pinned by server/api-routes.test.ts › "the captcha token": "answers a tokenless submission as SahajCloud would, without calling it" and "reads an empty token as none". Both fail on main.

  • F2d — no proxy failure reached Sentry. Both proxies call reportProxyFailure (server/api-routes.ts:224):

    • A 5xx, a transport failure or a timeout is reported every time, at level error.
    • A 400 is reported once per distinct <proxy>:<code> per isolate, at level warning. This uses the capped-Set idea from reportedConfigGaps.
    • A 429 is not reported.
    • A 403 is unreported only when it is the intake's coded refusal on the submissions proxy (api-routes.ts:229). A refused API key gets an uncoded 403, not a 401. Checked against production with a GET:
      curl -g -H 'Authorization: clients API-Key not-a-real-key' 'https://cloud.sydevelopers.com/api/pages?limit=1&select[title]=true'
      → 403 {"errors":[{"message":"You are not allowed to perform this action."}]}
      
      So that outage is now reported every time. The populate proxy has already checked its caller's token, so every 403 there is reported.

    Pinned by "Both proxies — what reaches Sentry":

    • draft-read failure reported without the token;
    • a 5xx reported every time, and none of the email, message, token or IP in any call argument;
    • unreachable upstream reported;
    • an uncoded 403 reported every time;
    • a populate 403 reported;
    • a coded 403 and a 429 left unreported;
    • a 400 reported once per code.

    The positive cases fail against main, and the two bold ones fail against the branch's earlier reportProxyFailure.

  • F2e — an unbounded body of any type was parsed. Hono's bodyLimit is registered ahead of the handler (api-routes.ts:322) and refuses with 413 past SUBMISSION_BODY_LIMIT (server/validation.ts:96). The limit is 6 bytes per character, which is JSON.stringify's worst-case escape, taken over submissionSchema's own bounds, plus 4 KiB: 6 × (40 × (100 + 5000) + 254) + 4096 = 1,229,620 bytes. Before, there was no bound at all. A Content-Type other than application/json gets 415 (api-routes.ts:333). The check is case-insensitive and allows parameters. Pinned by "the body gate":

    • "refuses a body past the size bound unread" and "refuses a body not declared JSON" both fail on main;
    • "never refuses a body the schema accepts for its size" uses every bound at its maximum, filled with control characters;
    • "takes a JSON content type with parameters".
  • F12a (FormBuilder) — no interaction coverage. New jsdom file components/organisms/FormBuilder/FormBuilder.interaction.test.tsx (9 cases). It covers:

    • a successful submit (path, token header, body, thank-you);
    • a refusal (one submit_error, the widget remounted, and the second submit sending the fresh token);
    • required fields stopping the post;
    • the redirect path;
    • a javascript: redirect refused, with the confirmation shown instead.

    The Turnstile mock is solved inside act. With the earlier solve-on-mount mock, the refusal case failed 5 of 5 times in isolation and about 1 run in 5 of the full suite. It now passes 6 of 6 in isolation and 5 of 5 full runs, and it still fails when the widget is not remounted after a refusal.

Review follow-ups also in this PR:

  • the SUBMISSION_BOUNDS.email comment now says that bound is RFC 5321's, not SahajCloud's;
  • the FormBuilder README's Validation section now describes the noValidate form and the { ok, code } answer.

Not in this PR

  • F2f (.env.production and the Turnstile site key) belongs to feat(server): switch wemeditate.com over to the new site #288.
  • The upstream status for a missing token was not read from SahajCloud's source. 403 is the status this repo's proxy test already pins for captcha_failed. Nothing was POSTed to SahajCloud.
  • reportedRefusals should become createWarnOnce (server/warn-once.ts) once feat(components): a MeditationLibrary for the meditations index block #293 merges. That PR adds the shared "once per signature per isolate" helper. The level-error path stays separate.
  • An upstream 429 stays unreported. server/AGENTS.md notes that SahajCloud's edge rate-limit bucket keys on our egress address. If that is true, a 429 could mean every proxied submission is being limited, not one visitor. It deserves its own look once the bucket's key is confirmed upstream.
  • A required checkbox still shows no visible required marker. The Checkbox atom draws its own label, unlike FormField's *. Adding one needs a design decision, not a string, so no translation key is needed.
  • FormBuilder's siteKey JSDoc, types/vike.d.ts and .env.example still say SahajCloud refuses a tokenless submission. The proxy now gives that same captcha_failed answer on its behalf, so the outcome they describe is unchanged.

Reconciled with open PRs

Test results

.claude/skills/pr-prep/check.sh on the pushed head (f8761f0, based on current main 5ee6ded):

  • lint: 0 errors, 1084 warnings, equal to the main baseline of 1084. The changed files lint clean.
  • tsc --noEmit: clean.
  • vitest run: 130 files, 1243 / 1243 tests passed. Four more full runs also passed 1243 / 1243.
  • pnpm build: not run (this bundle is not marked BUILD).

🤖 Generated with Claude Code

https://claude.ai/code/session_01Mg9rjZcE8bs5uRJ6dsg6kw

An authored form's required checkbox was registered with no rule, so an
unticked one posted `false` and the author's "required" did nothing. It
now takes the same `required` rule as every other field, and its error
message is named by the control's `aria-describedby`, as FormField does
for the wrapped fields.

A select with no authored default left `defaultValue` unset. The browser
then selects the first enabled option (the placeholder is disabled), and
react-hook-form reads that value on registration, so `required` could
never fail and an untouched select posted its first option. Confirmed in
Chromium before and after. It now starts on the placeholder's empty
value, server render included; an authored default still wins.

The new jsdom file covers what a submit does end to end: a success, a
refusal that re-challenges instead of resending a spent token, the
redirect and its scheme gate, and both required fields.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjZcE8bs5uRJ6dsg6kw
…es any body

`POST /api/submissions` forwarded a submission to SahajCloud with no
`x-turnstile-token` header at all, spending an authenticated round trip
on a write SahajCloud refuses every time. The proxy now gives that answer
itself, the 403 `captcha_failed` envelope SahajCloud sends and the proxy
already passes through, so the form renders exactly what it rendered.

It also read the whole request body before validating it, whatever its
size or type. A body is now refused unread past SUBMISSION_BODY_LIMIT
(413) and unparsed unless declared JSON (415), both in the existing
`invalid_request` envelope. The limit is derived from submissionSchema's
own bounds at JSON.stringify's six-bytes-a-character worst case, so no
body the schema accepts is ever refused for its size; a test pins that
with every bound at its maximum.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjZcE8bs5uRJ6dsg6kw
Both same-origin proxies swallowed every SahajCloud failure into a 502
or a refusal, and api-routes.ts imported no Sentry at all, so a form that
stopped landing — an outage, a rotated key, a key the intake started
refusing — was visible only to the visitor who lost their message.

A failure that is not the caller's (5xx, transport, timeout, a key
SahajCloud refuses) now reports every time. Of the caller's, a 403 or
429 is the captcha or the rate limit working and stays unreported, and a
400 reports once per distinct code per isolate, the bound
`reportedConfigGaps` set: it is how a contract drift shows, but also what
a visitor with a disposable address earns.

The event carries the status, the intake's code and the error's name,
never SahajCloud's message, which may quote the body, the token or the
visitor's address.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjZcE8bs5uRJ6dsg6kw
The Sentry cases sat at the end of api-routes.test.ts and set up their
mock in the file-wide beforeEach. The related-route specs a sibling fix
adds land at that same end, so both branches would edit one hunk. The
cases now sit in one describe ahead of the refusal block, with their own
setup, and the populate case joins them, so the file's tail and shared
setup read as they do on main.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjZcE8bs5uRJ6dsg6kw
reportProxyFailure dropped every upstream 403 as the caller's. But
SahajCloud answers a key it does not accept (stale, rotated, or missing
its role) with Payload's own Forbidden: a 403 whose envelope carries no
data.code. Checked against production with a GET and a bogus key:
403 {"errors":[{"message":"You are not allowed to perform this action."}]}.
So the outage the reporting exists for still reached Sentry with
nothing, on both proxies.

A 403 is now the caller's only on the submissions proxy, and only when
it carries the intake's code (captcha_failed and its siblings). An
uncoded 403 reports every time at level error. The populate proxy has
verified its caller's token before it calls, so every 403 there is ours
and reports. A 429 stays unreported.

Also says where SUBMISSION_BOUNDS.email comes from (RFC 5321), since the
comment above it attributes the other bounds to SahajCloud.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjZcE8bs5uRJ6dsg6kw
The refusal case failed every time in isolation and about one full run
in five. The mocked widget solved itself from a mount effect. After a
refusal, the remounted widget's effect called onSuccess('token-2')
outside act, and the second submit fired before React committed it,
so react-hook-form ran the previous render's onSubmit with token null.

The mock now hands the test a solve() that delivers the current
mount's token inside act, so the token is committed before the next
submit. The refusal case waits for the remount and then solves the fresh
challenge. It passed 6 of 6 runs in isolation and 5 of 5 full suite
runs. It still fails when the widget is not remounted on a refusal.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjZcE8bs5uRJ6dsg6kw
The README said native HTML5 `required` validates on the client and
that the API returns field-level errors. The form is noValidate,
react-hook-form checks the authored `required` rules (now on a checkbox
and a select too), and /api/submissions answers { ok, code }. The form
renders every refusal as forms.general.submit_error and re-challenges.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjZcE8bs5uRJ6dsg6kw
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
wemeditate-web f8761f0 Commit Preview URL

Branch Preview URL
Nov 19 2026, 09:16 PM

@sydevs-bot
sydevs-bot added this pull request to the merge queue Nov 19, 2026
@sydevs-bot

sydevs-bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 no session running

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

@sydevs-bot sydevs-bot moved this from Awaiting to Pending in SYDevelopers Technical Roadmap Nov 19, 2026
Merged via the queue into main with commit 182fbb3 Nov 19, 2026
11 checks passed
@sydevs-bot
sydevs-bot deleted the claude/fix-forms-required-fields-and-proxy branch November 19, 2026 23:57
@sydevs-bot sydevs-bot moved this from Pending to Done in SYDevelopers Technical Roadmap Nov 19, 2026
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.

3 participants