Skip to content

fix(api): accept an issue report from an API client - #1089

Merged
Ardnived merged 3 commits into
mainfrom
fix/client-report-form-validation
Nov 6, 2026
Merged

Ardnived merged 3 commits into
mainfrom
fix/client-report-form-validation

Conversation

@Ardnived

@Ardnived Ardnived commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Every atlas issue report is refused with 400 The following field is invalid: System > Form, reported 2026-11-05 right after fix(api): allow the Turnstile token header through CORS preflight #1085 unblocked the atlas forms. The widget shows "Your report wasn't sent".
  • Cause: the form-builder plugin's form validator proves the form exists with payload.findByID({ collection: 'forms', id, req }), using the caller's req and no select. For an API client, that read trips the select-required client gate (src/plugins/usage/hooks.ts). The plugin catches the 400 and calls the form missing.
  • Evidence from the production logs: each refusal is immediately preceded by Client query validation rejected: select missing or wrong shape for client 8.
  • Fix: perTypeForm (src/collections/UserSubmissions/fields.ts) hands the plugin's own validator a trusted req — asTrustedReq, this repo's opt-out for an internal read that forwards the caller's req with no select, which five other modules already use.
    • The plugin stays the single owner of its existence check, so a non-existent id is still refused with its wording.
    • asTrustedReq relaxes the query-shape gate only: origin enforcement still reaches the forwarded read, and the shared count cell keeps the create at one metered request.
    • Neither version gates read access on the form. payload.findByID defaults overrideAccess: true, so forwarding req never enforced it — this body claimed otherwise before 2eb5ad9.
  • Why no test caught it: the test harness registered usagePlugin before formsPlugin, the reverse of payload.config.ts. A plugin only wraps collections that exist when it runs, so forms and user-submissions never got the client read gates under test. tests/utils/testHelpers.ts now mirrors production.
  • The registration path was never affected: its event field has no existence check that reads as the client.

Refs sydevs/SahajAtlasWeb#259 (criterion 4: a test report from the live site).

Test results

  • tests/int/atlas-report-issue-form.int.spec.ts adds two cases that submit a report as the atlas client through the write guard: one accepts the configured form, one refuses an unknown form id.
    • With the harness fixed and the old validator, the accept case fails with the production error (ValidationError: The following field is invalid: System > Form). With the fix it passes, 13/13.
    • Before the harness fix it passed against the old validator, which is how the reorder was found.
    • The refusal case reads data.errors and asserts the field's own sentence. It cannot discriminate the defect under any assertion — the plugin returns that sentence for the select-gate 400 as well — so the accept case is the regression test and this one pins the wording.
  • Re-run after 2eb5ad9 and 88d5112, one command at a time: atlas-report-issue-form 13/13, user-submissions-create + forms-action-type 68/68, usage-tracking-dedup + client-query-validation 72/72.
  • Lean gate .claude/skills/pr-prep/check.sh passes: lint, format, both typechecks, 239 unit files / 3,084 tests.
  • Security review not triggered: no changed path matches securityReview.triggerPattern.

Manual verification

After deploy: send an issue report from sahajatlas.com. It should show the thank-you screen and arrive at the general contact inbox.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Mg9rjV2RHc4z2qB8cRpKq7

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]>
@railway-app

railway-app Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

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

Service Status Web Updated
SahajCloud ✅ Success (View Logs) Web Nov 6, 2026 at 1:24 am UTC
1 service not affected by this PR
  • mailpit

@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-1089 November 6, 2026 00:48 Destroyed
@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 6, 2026
@sydevs-bot

sydevs-bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

🤖 no session running

recent dispatches
  • 01:08Z address-review · attempt 1 · session · done
  • 01:08Z address-review · attempt 1 · session
  • 01:00Z review-pr · attempt 1 · session · done
  • 01:00Z 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 6, 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 diagnosis is right, and the harness reorder is the most valuable part — it is why the next such regression fails a spec. Scope is clean: three files, nothing smuggled in.

The fix writes own code where the repo already holds the mechanism. asTrustedReq lets an internal read forward the caller's req with no select, and five modules call it. Using it keeps the plugin the single owner of its existence check, and deletes the duplicated string and the catch-all.

The docblock rewrite also dropped the src/collections/AGENTS.md pointer: supplying validate replaces Payload's default. That is why relationshipValidation is composed at all.

Findings

  • should-fix — fields.ts:260: rebuilds the plugin's existence check. Pass the plugin's validator a trusted req instead.
  • should-fix — atlas-report-issue-form.int.spec.ts:223: toThrow(/Form/) matches the wrapper message, so the negative case passes against the bug too.
  • consider — fields.ts:270: the bare catch reports any failure as a missing form, and logs nothing.

What was checked

  • Read whole: UserSubmissions/fields.ts, plugins/usage/hooks.ts, the spec, tests/utils/testHelpers.ts.
  • Ladder: extractID is the platform's. FORM_MISSING duplicates the plugin's string, and the findByID duplicates its validator.
  • Traced the gate. validateClientQueryParamsHook returns on skipClientQueryValidation; validateClientOriginHook does not. A trusted req relaxes shape, not origin.
  • asTrustedReq callers: deliverRegistration, upsertUserByEmail, fullness, regionTree, atlas/sitemap.
  • No ## Preview links. The Railway preview reports Success. No contractSync consumer reads this field.
  • Not checked: the plugin's validator source. node_modules is absent in this clone, so its behaviour is taken from the PR body.

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


Generated by Claude Code

@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Nov 6, 2026
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
`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
@sydevs-bot

Copy link
Copy Markdown
Contributor

All three review threads addressed, in two commits, relayed for Actions to land.

Adopted

  • 2eb5ad9 — the plugin's validator now gets asTrustedReq(options.req). FORM_MISSING, the extractID cast and our catch are gone, so the fix is two lines against main. Settles both fields.ts threads.
  • 88d5112 — the spec case reads data.errors and pins the field's own sentence.

Corrected

  • That case cannot discriminate the defect under any assertion: the plugin returns the same sentence for the select-gate 400. I reproduced the old validator — only the accept case fails.
  • The body claimed forwarding req stopped a client citing a form it may not read. findByID defaults overrideAccess: true, so it never did. Body fixed; no behaviour change.

Docs checked, nothing stale.

🤖 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 6, 2026
@sydevs-bot sydevs-bot moved this from Working to Awaiting in SYDevelopers Technical Roadmap Nov 6, 2026
@railway-app
railway-app Bot temporarily deployed to sahajcloud / SahajCloud-pr-1089 November 6, 2026 01:21 Destroyed
@sydevs-bot
sydevs-bot enabled auto-merge November 6, 2026 01:37
@Ardnived
Ardnived merged commit 8ad2485 into main Nov 6, 2026
9 checks passed
@Ardnived
Ardnived deleted the fix/client-report-form-validation branch November 6, 2026 01:37
@sydevs-bot sydevs-bot moved this from Awaiting to Done in SYDevelopers Technical Roadmap Nov 6, 2026

This branch was successfully deployed

No deployments
sahajcloud / SahajCloud-pr-1089 — 88d5112d Deployed Nov 6, 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.

3 participants