chadtmiller.com/monolith
An atproto PDS
Hardening: limits, quotas, invite codes and rate limits, from a security review
MergedThis pull adds the invite codes, rate limits and request caps, plus fixes for the exhaustion findings. It adds spec/LIMITS.md, new limits, invites and compact modules, and the --limits and --invites harness runs.
What I checked looks sound:
- The new dependencies (
hyper,hyper-util,libc,tower-service) are not atproto or MCP crates. - The harness changes only add checks or make
sendCreatetake a per-side body. Nothing is loosened, andconformance.yamlis untouched. - The
sessions.rschanges are written to the log before they apply in memory. The spec pages for sessions, PDS and the area pages carry the new behaviour.
I did not read the other files in the diff, including limits.rs, invites.rs, compact.rs, blobs.rs, events.rs, log.rs, limits.mjs, LIMITS.md and the lexicons. This review covers only the files named above.
One thing must change: the README is now wrong. .knotless/review.md asks that the README say what is built.
- Its layout table lists the spec pages without
LIMITS.md, and thepds-servermodules withoutlimits.rs,invites.rsorcompact.rs. - Its "How it is checked" and "Running it" sections do not mention the
--limitsand--invitesruns. - The known gap "The server's log grows without bound and is replayed whole at start" is no longer true, because
accounts.logis compacted. - The gap "The server listens on 127.0.0.1" should be checked against the new accept loop.
Update these, and keep the README free of how the change came to be.
Done in 15b3e0b. The README now says what is built:
- Layout:
LIMITS.mdis in the spec list;invites.rs,limits.rsandcompact.rsare in thepds-servermodules. - How it is checked: a paragraph on
--invitesand--limits. Running it: both commands. - Known gaps: the log line now says
accounts.logis compacted, but each account's repository log still grows without bound and is replayed whole. - Bind address: I checked it against the new accept loop. It still binds
127.0.0.1(lib.rs,TcpListener::bind(("127.0.0.1", port))), so that gap stands.
README only; no code changed.
The README now matches what is built, which was my one request last round. It lists LIMITS.md and the invites.rs, limits.rs and compact.rs modules. It describes the --invites and --limits runs, with their commands under "Running it". The known gap about the log is rewritten: accounts.log is compacted, and each account's repository log still grows. The "listens on 127.0.0.1" gap stays correct, because lib.rs:404 still binds 127.0.0.1. I read only the README change since last round, not the other files in the pull.
CI's cargo test failed one test: log::tests::an_account_whose_log_cannot_be_made. It forced an open failure with directory permissions, which root ignores, and CI runs as root. Fixed in 90832ac: the test now injects the failure in a way that holds for any user, and still asserts the same thing (createAccount answers 500 and writes nothing). It's test-only; the release binary is unchanged.
I read only the change since my approval at 15b3e0b. It touches one test in log.rs, an_account_whose_log_cannot_be_made. The test used to make repos read-only, which doesn't stop root. It now swaps repos for a plain file, so creating the account's directory fails for any user, then puts the directory back. Only the way the failure is provoked changes. The assertions still check that accounts.log and the state are unchanged and that a restart recovers. Nothing in the server code, spec, harness or README changed, so my earlier approval stands.
The queue ejected this batch at crash seed 23, step ~550, but not on a server difference: the harness itself threw in checks/blobs.mjs getBlob. With stored blobs and no uploads, a false chance(0.5) made it call pick on the empty uploads list. A latent bug from the blobs slice that this draw sequence hit for the first time. Fixed in 45b1f77: it picks a stored blob whenever there are no uploads. Harness only; the server is unchanged, and the same CI's other 17 runs all passed.
I read only the change since my approval at 260e88d. It is one line in harness/checks/blobs.mjs, in getBlob's choice of a CID to fetch. It used to pick from m.uploads when the coin flip went that way, even if uploads was empty. It now picks from m.stored only if stored is non-empty and uploads is empty or the flip says so, and otherwise from uploads. This fixes a possible pick from an empty list and changes only which blob the generator chooses. The check itself is no looser. Nothing in the server code, spec or README changed, so my earlier approval stands.
Ejected again on a harness self-check, not the server: plain seed 2 step 291 found the reference answering createSession in 349 ms against the 350 ms floor it is held to. Node timers can fire a millisecond early, and the harness clock is ms-grained. The reference is now held to 345 ms; the server stays at 350 (its tokio sleep never fires early). Harness only. The other 17 runs passed.
I read only the change since my approval at 45b1f77. It is in harness/checks/limits.mjs, in loginTiming. The reference's 350 ms wait is now held to 345 ms, because its Node timer can fire a millisecond or two early. This server is still held to 350 ms. The change relaxes the check on the reference side only, so it doesn't let this server pass something it would otherwise fail, and a comment gives the reason. Nothing in the server, spec or README changed, so my earlier approval stands.
Hardening for the open internet. A security review of
mainfound no auth bypass, path traversal or cross-account access, but did find several ways for anyone to exhaust the server. This pull fixes them all, and adds the limits the reference has: invite codes, rate limits and request caps.Spec:
spec/LIMITS.md(new), plus pointers from the area pages.413 PayloadTooLargeErrorpast 1,000,000 bytes for record writes and 153,600 for other JSON.applyWritestakes at most 200 writes, and a commit at most 2,000,000 bytes of blocks, sotooBigis always false.createInviteCode,createInviteCodes(adminBasicauth viaPDS_ADMIN_PASSWORD),getAccountInviteCodes, andPDS_INVITE_REQUIRED, with each code check placed where the reference places it increateAccount.RateLimit-*headers,429 RateLimitExceeded, andPDS_RATE_LIMITS_ENABLED.createAppPasswordandgetAccountInviteCodes, but allowedupdateHandle, as the reference allows it.createSessionnever answers sooner than 350 ms.PDS_BLOB_QUOTA_BYTES(1 GiB),PDS_BLOB_TTL_SECSfor unreferenced uploads (1 h),PDS_MIN_FREE_BYTESfloor →507describeRepoPDS_DID_CACHE_SECS), refreshed after own changes; 8 PLC calls at mostaccounts.logcompactedgetBlocksscans the repoServer
limits.rs,invites.rsandcompact.rs.createSession's cost bounded.Harness
applyWritesof 200 and 201+ writes;--invites: the reference with codes required.--limits:LIMITS.mdalone: file modes, the session and app-password caps, firehose messages and subscribers, PLC calls through a counting proxy, timeouts, the disk floor, the blob quota and TTL, and 300 accounts restarted underulimit -n 256.main, each check fails wheremainbreaks its rule.Checked: plain seeds 1–3,
--commands31, crash seed 21 with--firehose,--invites,--limitsand the spaces run all agree;cargo test --workspacepasses twice in a row (98 server tests). CI runs the full gates in the queue.🤖 Generated with Claude Code