Skip to content

MEDIUM: API cursor ts/id not validated as date/UUID — invalid DB casts return 500 instead of 400 #76

Description

@walidboulanouar

Problem

apps/api/src/lib/pagination.ts lines 14–18:

export const cursorSchema = z.object({
  ts: z.string(),    // only validated as string, not ISO date
  id: z.string(),    // only validated as string, not UUID
});

In keysetCondition (list.ts line 53): const ts = new Date(cursor.ts) — a crafted cursor with ts: "not-a-date" produces Invalid DateNaN in the SQL expression (unhandled 500). A crafted id: "' OR '1'='1" is correctly parameterized by Drizzle but causes a DB UUID cast error (also 500).

Fix

export const cursorSchema = z.object({
  ts: z.string().datetime(),
  id: z.string().uuid(),
});

Then decodeCursor returns null for any malformed cursor and list routes safely start from page 1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions