Skip to content

Bound what the public waitlist and heartbeat routes can write to Blob - #262

Draft
MaxGhenis wants to merge 1 commit into
mainfrom
fix/site-blob-write-bounds
Draft

MaxGhenis wants to merge 1 commit into
mainfrom
fix/site-blob-write-bounds

Conversation

@MaxGhenis

Copy link
Copy Markdown
Owner

Bounds what anyone can store through the public /api/waitlist and /api/heartbeat routes on openmessage.ai. This is finding 3 (medium) of the 2026-10-22 security review. The routes are live: GET /api/heartbeat answers {"ok":true,"schema_version":1}.

Before: the waitlist wrote a new Blob object at a fresh UUID path for every valid submission, with no cap on email length. The heartbeat wrote one object per caller-chosen install id (any 16-64 characters). Neither route had a server-side rate limit or storage budget, so a script could grow storage and billable Blob operations without limit.

Changes (site/lib/public-writes.mjs; the routes are now thin wrappers)

  • Request shape: bodies over 2 KiB get 413. Emails over 254 characters get 400. A heartbeat's install_id must be the app's format, 32 lowercase hex characters (internal/telemetry installID).
  • Per-address rate limit: 5 sign-ups per 10 minutes and 30 heartbeats per hour, keyed by the client address Vercel sets. The limit is held in each warm instance's memory, so it throttles bursts but is not a global guarantee.
  • Daily object budget (the hard bound): before writing, the route checks with list({prefix: <route>/<UTC day>/, limit: cap}) that the day's folder holds fewer than 1,000 objects. At the cap the waitlist answers 503 ("sign-ups are paused for today"), and the heartbeat answers {ok: true, persisted: false} so the app doesn't retry. Concurrent requests can overshoot the cap by at most their number.
  • No duplicate objects: the waitlist path is an HMAC of the address under WAITLIST_ENCRYPTION_KEY, so a repeat sign-up the same day replaces its object, and the path doesn't reveal the address (an unkeyed hash would). Heartbeats overwrite the install's object for the day (allowOverwrite); a second heartbeat used to fail with 502 because Blob refuses to overwrite by default.

The stored record format is unchanged (same encrypted waitlist envelope and heartbeat JSON, same waitlist/<day>/ and heartbeats/<day>/ folders), so anything that reads them keeps working.

Invariants (tested)

  • A day's folder never holds more than the cap. On the waitlist it holds exactly one object per distinct accepted address, and a refusal writes nothing. A randomized test checks this over 60 generated request sequences with small caps; the sequences do reach the cap.
  • No rejected request (bad shape, honeypot, rate-limited, unconfigured) writes anything.

Tests

site/lib/public-writes.test.mjs uses node:test against an in-memory Blob that keeps Vercel's overwrite and list semantics: 11 tests, all passing locally. The Site Build CI job now runs them. I used node:test rather than Vitest because the site's lockfile is npm's while this machine's tooling enforces bun, and adding a dev dependency would have put the lockfile out of sync with what CI installs.

Not covered here

The per-address limit is per instance. A global per-address limit needs shared state, either a Vercel Firewall rate-limit rule or a KV store. That is a dashboard change on the Vercel project, so it is not in this PR.

🤖 Generated with Claude Code

Both routes are live on openmessage.ai and anyone can POST to them. The
waitlist stored a new object at a fresh UUID path for every submission,
with no length cap on the email; the heartbeat stored one per
caller-chosen install id. Repeated requests grew storage and Blob
operations without limit (security review 2026-10-22, finding 3).

lib/public-writes.mjs now bounds both:
- bodies over 2 KiB get 413; emails over 254 characters and install ids
  that aren't the app's 32-hex format get 400;
- a per-instance rate limit by client address (5 sign-ups per 10 minutes,
  30 heartbeats per hour);
- a daily object budget per route (1,000), read from Blob with list(), so
  storage stops growing across all instances; at the cap the waitlist says
  sign-ups are paused and the heartbeat answers OK without persisting;
- a waitlist path that is an HMAC of the address under the encryption key,
  so a repeat sign-up replaces that day's object and the path doesn't
  reveal the address; heartbeats overwrite the install's object for the
  day, where a second one used to fail with 502.

Tests run with node:test (no new dependencies; the site's lockfile is
npm's and this machine's tooling requires bun), including a randomized
check that a day's folder never holds more than the cap or more objects
than distinct accepted addresses. CI's Site Build job runs them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MaxGhenis added a commit that referenced this pull request Nov 18, 2026
Both routes are live on openmessage.ai and anyone can POST to them. The
waitlist stored a new object at a fresh UUID path for every submission,
with no length cap on the email; the heartbeat stored one per
caller-chosen install id. Repeated requests grew storage and Blob
operations without limit (security review 2026-10-22, finding 3).

lib/public-writes.mjs now bounds both:
- bodies over 2 KiB get 413; emails over 254 characters and install ids
  that aren't the app's 32-hex format get 400;
- a per-instance rate limit by client address (5 sign-ups per 10 minutes,
  30 heartbeats per hour);
- a daily object budget per route (1,000), read from Blob with list(), so
  storage stops growing across all instances; at the cap the waitlist says
  sign-ups are paused and the heartbeat answers OK without persisting;
- a waitlist path that is an HMAC of the address under the encryption key,
  so a repeat sign-up replaces that day's object and the path doesn't
  reveal the address; heartbeats overwrite the install's object for the
  day, where a second one used to fail with 502.

Tests run with node:test (no new dependencies; the site's lockfile is
npm's and this machine's tooling requires bun), including a randomized
check that a day's folder never holds more than the cap or more objects
than distinct accepted addresses. CI's Site Build job runs them.

Cherry-picked from #262 onto the site rebuild. Conflict resolution: the
heartbeat route takes this version, and package.json keeps the rebuild's
Vitest test script.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@MaxGhenis

Copy link
Copy Markdown
Owner Author

This commit now rides in #283 (02a8e90 on its branch), with its authorship kept, since both PRs change the same two routes. #283 also moves these tests to Vitest with fast-check properties and drops the separate node --test CI step. I'll close this PR as superseded once #283 merges.

This branch has not been deployed

No deployments
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