Skip to content

Reject inbox pagination cursor minted under a different filter (CL-7206) - #486

Merged
TheGreatAxios merged 2 commits into
mainfrom
cl-7206-inbox-cursor-filter
Aug 30, 2026
Merged

TheGreatAxios merged 2 commits into
mainfrom
cl-7206-inbox-cursor-filter

Conversation

@TheGreatAxios

Copy link
Copy Markdown
Contributor

Stacking

1 of 3 in a stack on packages/inbox/src/routes.ts: CL-7206 (this PR) → CL-7207 → CL-7208. Base branch is main; CL-7207 branches off this PR's tip.

Summary

@corbits/mailbox embeds the view/sort/filter a pagination cursor was minted under directly in the cursor, specifically so a caller can reject a cross-set replay — its own mount.ts route already performs this cross-check. packages/inbox/src/routes.ts's GET / decoded the cursor but never performed it, so paging ?group=action, then replaying that nextCursor under ?group=mention, returned a 200 seeking into the wrong result set — silently skipping every newer mention.

  • Added packages/inbox/src/cursor.ts: cursorScopeMismatch(), a pure function reusing @corbits/mailbox's exported canonicalMailboxFilter and mirroring its mount.ts's exact error vocabulary ("cursor does not match inbox view/sort/filter"), so the two routes answer identically to the same condition.
  • GET / now rejects a scope-mismatched cursor with 400 before any DB access, and pins sort: "date" as const on its listUserMailbox call explicitly (previously relied on the mailbox package's internal default) since the new check asserts against that literal.

Tests

  • packages/inbox/test/routes.test.ts (new): HTTP-level regression test via Hono app.request — a db stub that throws if touched proves the rejection happens before any DB access. Verified by hand that this test fails (500, not 400) against pre-fix routes.ts.
  • packages/inbox/test/cursor.test.ts (new): pure unit tests of cursorScopeMismatch (match, view/sort/filter mismatch, check ordering).
  • Full @corbits/inbox suite: 29 pass / 3 skip / 0 fail.

Verification

  • WORKBENCH_CHECK_SINCE=origin/main bun run typecheck — clean
  • bun run check:structural — clean
  • bun run lint — clean
  • bunx prettier --check on touched files — clean
  • Reviewed by Greybeard (approach) and Critique (implementation) before opening; both passes clean, no must-fix findings.

Known follow-ups (not blocking this PR)

  • The view/sort/filter comparison now exists in two places (@corbits/mailbox's mount.ts and this new cursor.ts). Filed as a follow-up to upstream the check into @corbits/mailbox itself rather than duplicate it a third time if another caller needs it.
  • Whether the consuming UI drops a stale cursor and refetches on the new 400 (vs. surfacing a raw error) wasn't investigated — this PR is backend-only per the ticket's scope.

Closes CL-7206.

Reproduces CL-7206: GET / decodes a caller's pagination cursor but
never checks it was minted under the same group/status filter as the
current request. Paging ?group=action, then replaying that
nextCursor against ?group=mention, currently reaches the mailbox
store and 500s on the stubbed db rather than being rejected before
any DB access.
@corbits/mailbox embeds the view/sort/filter a cursor was minted
under specifically so a caller can reject a cross-set replay --
GET / decoded the cursor but never performed that check, so a
mention-tab fetch reusing an action-tab cursor silently seeked into
the wrong result set and served a 200 with newer mentions skipped.

cursorScopeMismatch() (packages/inbox/src/cursor.ts) reuses
@corbits/mailbox's own canonicalMailboxFilter and mirrors the error
vocabulary its mount.ts route already uses ("cursor does not match
inbox <field>"), so the two routes answer identically. GET /'s
listMailboxOpts now pins sort: "date" explicitly rather than relying
on @corbits/mailbox's own default, since the new check asserts
against that exact value.
@TheGreatAxios
TheGreatAxios merged commit 1964daa into main Aug 30, 2026
5 checks passed
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