Skip to content

fix(v1/submitDatum): malformed bodies are 400s, not 500s; callbackUrl optional as documented - #451

Open
QSchlegel wants to merge 1 commit into
preprodfrom
claude/daily-2026-11-23-submit-datum-validation
Open

QSchlegel wants to merge 1 commit into
preprodfrom
claude/daily-2026-11-23-submit-datum-validation

Conversation

@QSchlegel

@QSchlegel QSchlegel commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

What

POST /api/v1/submitDatum (bot/JWT route that creates a signable with the caller's signature already attached) now validates its body before using it:

Input Before After
key missing passed the check (it tested signature twice), then checkSignature threw → 500 400 key is required and must be hex
signature/key hex but not COSE (e.g. abcd) checkSignature throws RangeError → 500 400, error logged
signature/key not hex, odd length, or not a string 500 400
walletId / datum / description not a string Prisma or checkSignature throws → 500 400
callbackUrl absent 400 Missing required field Datum! (wrong field; OpenAPI lists it as optional and the row stores null) accepted, stored null
callbackUrl given any truthy value must be an http(s) URL of at most 2048 characters

The 500s were verified against the real @meshsdk/core-cst: checkSignature throws not enough bytes (missing key), fromHex expects an hexadecimal string and Trying to access beyond buffer length instead of returning false.

Why

Caller-controlled input should never produce a 500, and the documented contract (callbackUrl optional) disagreed with the code. Validation is a pure parseSubmitDatumBody exported for tests, in the style of parseIssueReport.

Behaviour changes to be aware of

  • Field validation now runs before the 403 address-mismatch check, so a malformed body gets a 400 first. The 400 messages are reworded. No in-repo caller matches on the old text.
  • A callbackUrl that is not an http(s) URL is now refused. Nothing in the app reads Signable.callbackUrl today, so the only risk is an external caller that sent a non-URL string.
  • The CI scenario (scripts/ci/scenarios/steps/datum.ts) sends hex from signData() and an https callback, so it is unaffected. MCP does not reach this route (mcpTools.test.ts lists it as forbidden).
  • botApi.integration.test.ts: the fixture signature: "sig", key: "key" is now hex. checkSignature is mocked there.

No changes to signing, witnesses, or what is stored for valid requests.

Tests

npx tsc --noEmit ✅
npx jest src/__tests__/submitDatum.bot.test.ts 24/24 ✅ (was 3). New tests: missing key, 9 wrong-type/non-hex cases, COSE decode error → 400, the real library throwing, optional/invalid callbackUrl, null handling, address mismatch still 403
node scripts/run-tests.mjs (full unit run, final commit) 2373 passed, 2 skipped; ESM 140/140 ✅
RUN_BOT_API_INTEGRATION=true jest botApi.integration.test.ts (local Postgres) ⚠️ 1/2. It fails at line 151, on the addTransaction step before submitDatum runs, and fails the same way on unmodified preprod. This suite is opt-in and not part of CI. Not addressed here.

A separate review agent read the diff without context. It found nothing blocking. Following its review, decode errors are now logged and the hex check requires whole bytes.


Generated by Claude Code

…red, callbackUrl optional as documented

- The required-field check tested `signature` twice and never `key`, so a
  missing key reached checkSignature.
- checkSignature throws (not false) on a signature/key that is not
  decodable COSE; that surfaced as an unhandled 500. Now 400, logged.
- Non-string walletId/datum/description reached Prisma or checkSignature
  and threw; now rejected with 400 up front (signature/key must be hex).
- callbackUrl was rejected when absent, with an error naming "Datum",
  although the OpenAPI spec lists it as optional and the row stores null.
  It is optional again; when given it must be an http(s) URL <= 2048 chars.
- OpenAPI: document the 400/401/403 cases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017rkSXFzqacGdQ1YXPo25ZC
@vercel

vercel Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
multisig Ready Ready Preview Nov 23, 2026 6:07am UTC

Request Review

This branch was successfully deployed

1 active deployment
Preview — e31a821c Deployed Nov 23, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants