Skip to content

404 instead of 500 for malformed ids on public routes - #304

Merged
Musiker15 merged 2 commits into
mainfrom
fix/status-page-invalid-id
Oct 29, 2026
Merged

Musiker15 merged 2 commits into
mainfrom
fix/status-page-invalid-id

Conversation

@Musiker15

Copy link
Copy Markdown
Member

Problem

A URL with something that isn't a UUID, like /s/not-a-uuid, answered 500 and wrote an error to the web log. Prisma passes the value to a uuid column and Postgres rejects it. Live today: /s/not-a-uuid → 500, /api/files/not-a-uuid → 500. The same path exists in api/submissions/[id] (delete), /export and /withdraw.

Fix

  • isUuid() in packages/shared/src/uuid.ts.
  • getSubmissionForStatus returns null for a malformed id, so the status page shows its normal 404.
  • api/files/[id], api/submissions/[id], /export and /withdraw answer with their existing 404 body before touching the database.

Tests

  • uuid.test.ts: canonical UUID in both cases accepted, the usual garbage rejected.
  • pnpm --filter @msk-forms/shared test, typecheck of shared and web, eslint on the changed files.

/s/not-a-uuid and /api/files/not-a-uuid answered 500: the id went straight
into a uuid column and Postgres rejected it with an error. The same applied
to fetching, exporting and withdrawing a submission.

isUuid() in packages/shared checks the id first. The status page lookup
returns null (notFound), and the four API routes answer with their usual
404 body.
…id-id

# Conflicts:
#	packages/shared/src/index.ts
@Musiker15
Musiker15 merged commit f0a8814 into main Oct 29, 2026
4 checks passed
@Musiker15
Musiker15 deleted the fix/status-page-invalid-id branch October 29, 2026 06:29
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.

1 participant