Skip to content

fix(library): parse /uuids bodies up to 5 MB, like /status - #65

Merged
GianniCarlo merged 2 commits into
mainfrom
fix/uuids-body-limit
Nov 22, 2026
Merged

GianniCarlo merged 2 commits into
mainfrom
fix/uuids-body-limit

Conversation

@GianniCarlo

Copy link
Copy Markdown
Contributor

Problem

POST /v1/library/uuids accepts up to 1,000 path → uuid pairs, but it kept body-parser's default 100 KB limit. A 1% sample of production keys averages 72 bytes, so a full batch at the average path is about 114 KB. The API refuses it with a 413 that has no error code.

  • iOS and the web cut /uuids batches at 1,000 entries, whatever their size (SyncJobScheduler.matchUuidsBatchLimit, the web's MATCH_BATCH).
  • The missing-items pass sends every item the server doesn't know through /uuids inline, before registering them. So a first sync (after signing in, or after a lapse) with about 900 or more unknown items, where every file inside a folder counts, fails on every refresh, and that device's library never gets registered.
  • Android isn't affected: it already sizes batches under 96 KB (MatchUuidsBatching).

How many users this hit can't be counted. The API doesn't log 4xx responses, the load balancer has no access logs, and body-parser refuses the request before the router, so sync_operations never sees it.

Fix

/v1/library/uuids now parses its own body with the 5 MB limit, the same way /v1/library/status does: the global jsonBody skips the path, and the route runs largeJsonBody after checkSubscription and requireCloudData, so an anonymous request still can't make the server read a large body. The 1,000-pair cap per request is unchanged. This fixes the shipped iOS builds and the web without an app update.

recordSyncOperation reads req.body when the response finishes, after the route has parsed it, so the audit rows for match_uuids keep their params.

Testing

  • tsc --noEmit passes.
  • New test in jsonBody.test.ts: 1,000 pairs at 72-byte paths, asserted to be over 100 KB, parse on /v1/library/uuids. All 5 body-limit tests pass.
  • Mutation check: with /uuids taken off the route list, the new test fails with a 413.

🤖 Generated with Claude Code

POST /v1/library/uuids takes up to 1,000 path → uuid pairs, but kept
body-parser's 100 KB. Production paths average 72 bytes, so a full
batch is about 114 KB and was refused with an uncoded 413. iOS and the
web cut batches by count only, and the missing-items pass sends every
unknown item through /uuids inline, so a first sync with about 900 or
more unknown items failed on every refresh and the library never got
registered. The route now parses its own body with the 5 MB limit,
after checkSubscription and requireCloudData, as /status does.
Comment thread src/api/LibraryRouter.ts Resolved
@github-actions

github-actions Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

🟡 Claude PR Review — WARN

Raises the JSON body limit for POST /v1/library/uuids from 100 KB to 5 MB. It uses the same setup as /status: the global jsonBody skips this path, and the route runs largeJsonBody after checkSubscription and requireCloudData.

Auth and subscription checks: the large body is still only read after both checks, and nothing before the route (authMiddleware, checkVersion, checkSubscription) reads req.body. So an anonymous caller still can't make the server read a large body. The path match is case-insensitive and ignores a trailing slash, and the router is mounted only at /v1/library. The 1,000-pair cap and how library rows are scoped to the user are unchanged.

Audit rows: recordSyncOperation reads req.body when the response finishes, and sanitizeParams already shrinks any body over 8 KB to a size marker, so audit rows stay small.

Remaining risks: (1) the postLibraryUuids error path still logs the whole req.body and req.user, and a body can now be 5 MB instead of 100 KB; (2) the new test builds its own copy of the route, so it doesn't check that LibraryRouter really runs largeJsonBody.

Findings: 1 warn · 1 info

Model claude-opus-5-5 · run log · 2 new · 0 carried over · 0 resolved · advisory (a human should still review). Findings are de-duplicated across pushes; an earlier finding closes only when the verification pass judges it against the current code — fixed, no longer applicable, accepted by a maintainer, or a duplicate of a finding reported on this push.

Name /uuids in server.ts's note on the routes that parse their own body.
Comment thread src/api/LibraryRouter.ts Resolved
@GianniCarlo
GianniCarlo merged commit 3c34bd0 into main Nov 22, 2026
4 checks passed

This branch was successfully deployed

1 active deployment
reviewer — 58578925 Deployed Nov 21, 2026 by GianniCarlo via review #138
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