1.3 KiB
1.3 KiB
PR checklist: validation and API safety
Use this for any change that adds or modifies user input, public endpoints, or tenant-scoped data.
- Server schema: Mutating handlers (
POST/PUT/PATCH/DELETE) that read JSON should validate with Zod (safeParse) and return structured400responses (seevalidationErrorResponseinsrc/lib/api-schemas/validate.ts). - Rate limits: Unauthenticated or abuse-prone endpoints should use
applyRateLimitfromsrc/lib/rate-limit.tswith an explicit window and max. - Authorization: For routes with
storeId,supplierId,connectionId,orderId, etc., confirm the authenticated user owns or is linked to that resource before mutating. - Client parity: High-traffic forms should mirror server limits (
maxLength, optional Zod pre-check) for UX; never rely on client checks alone for security. - HTML / XSS: If user content is rendered as HTML, sanitize or use
textContent/ escaped strings; seesrc/lib/sanitize/htmlPolicy.ts. - Tests: Add or extend Zod unit tests in
src/lib/api-schemas/schemas.test.tsfor new schemas; add route-level tests when authz behavior is non-obvious. - E2E (optional): With the dev server running,
PLAYWRIGHT_BASE_URL=http://127.0.0.1:3000 pnpm exec playwright test.