fix(sync): bound what one POST /api/sync can cost the companion #156

Merged
maximus merged 1 commit from issue-147-bound-sync-post into master 2026-10-25 01:22:04 +00:00

1 commit

Author SHA1 Message Date
le king fu
d2289806a4 fix(sync): bound what one POST /api/sync can cost the companion
- validators: at most 200 operations per sync batch (SYNC_MAX_OPERATIONS),
  length checked before the elements (z.array(z.unknown()).max(n).pipe),
  idempotency keys must be UUIDs; same pre-check on reorder ids (1000) and
  task tag ids (100).
- parseBody: a 400 carries only the first zod issue, at most 200 characters.
- idempotency: per-account store in insertion order, 5000 keys per account
  (oldest evicted), cleanup drops expired keys and empty accounts; the sync
  route uses it instead of its unbounded Map.
- middleware.test.ts: every matcher covers /api/sync, the condition for
  Next's 10 MB body cut.
- REVIEW.md: idempotency.ts joins the high-level API row, new zone rules;
  scripts/review-levels.py follows.

Refs #147

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 14:13:40 -04:00