Repository navigation
fix(api): return 400 for a malformed list cursor instead of page one - #222
Merged
Merged
Conversation
decodeCursor returned null for an undecodable cursor and the callers treated
null as "no cursor", so GET /v1/templates, GET /v1/templates/pull and
GET /v1/email/logs answered 200 with the first page. A client following a
stale or corrupted cursor looped over page one with no error.
- decodeCursor (packages/db) now accepts only a value encodeCursor could
produce: the decoded date must re-encode to the input. This rejects
lookalikes such as "5|abc", which new Date() parses as a valid date.
- apps/api/src/lib/cursor.ts parseCursorParam: absent cursor is the first
page; a present but invalid cursor sets 400 and throws, which the standard
error handler reports as { error, code: "BAD_REQUEST" }.
- The three cursor-paginated routes use it.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GxJAQNUP4FKZHL1yzPDsGd
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
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
A malformed
cursoron the list routes returned 200 with page one again, so a client following a corrupted cursor looped silently.decodeCursorreturnednulland callers treatednullas "no cursor"; it was also lenient (new Date("5")parses, sobase64("5|abc")was accepted).On
/pullthe parse runs before the unpaginated branch, so a bad cursor is a 400 with or withoutlimit.Evidence
%%%, empty, base64 of JSON,5|abc, non-canonical timestamp) -> 200 with page one.After: all 400. Pagination still walks every page with
limit=1, no row repeated or dropped.The no-
limit/pulltest passes but was added after the fix and not run against the old code. The CLI needs no change:apiFailuremaps 400 toVALIDATION_FAILEDand prints the API message (that mapping lands with #219).Merge Danger
Door: two-way
?cursor=(empty) used to count as absent and now returns 400. Any cursor the API did not issue is rejected, including hand-edited ones.Blast Radius: API clients that paginate
GET /v1/templatesandGET /v1/email/logsshare the decoder and change too.apps/web/src/lib/aws/ses-suppression.tshas its own lenientdecodeCursor, left alone.🤖 Generated with Claude Code
https://claude.ai/code/session_01GxJAQNUP4FKZHL1yzPDsGd