~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0

Hardening, second pass: SSRF everywhere, OAuth sign-in limits and 2FA, bounded OAuth and outbound state, account state on OAuth and spaces

Merged
Merged chadtmiller.com asked to merge into main from chadtmiller.com/monolith:harden2-s

A second security pass, from a review of everything built since the first. It covers OAuth, spaces, the proxy, lifecycle and email: 13 findings, plus X-Forwarded-For trust. Each finding became a rule in the page that owns it, probed on the reference where the reference can show it, with a check that fails on the code before this pull, then the fix.

What changes, by finding

  1. SSRF guard bypassed by spaces fetches. Every did:web document, client attestation, JWKS, managing-app and serviceEndpoint fetch goes through the one guarded client: no redirects, size caps, and no localhost or IP-address hosts while protection is on (PROXY.md "SSRF protection", referenced from the spaces pages). The spaces run restarts the server with protection on and counts connections to its own listeners.
  2. PLC request slots starved. did:web fetches have their own pool of 16, apart from the directory's 8. Calls authenticated by service auth, a delegation token or a credential pay their rate-limit points before anything is fetched.
  3. Email second factor skipped at OAuth sign-in. The OAuth sign-in API answers 401 second_authentication_factor_required and mails a code, as createSession does, with the reference's 30-day remembered device.
  4. OAuth sign-in as an unlimited password oracle.
    • The sign-in shares createSession's login buckets.
    • It answers no sooner than 400 ms, known and unknown identifiers alike.
    • It hashes on the shared hash pool.
  5. OAuth memory and disk growth.
    • Caps: PAR body capped at 100 KiB (as the reference), with field caps (state 1024 bytes, code_challenge exactly 43 characters, and others).
    • Pending requests: capped per address (IPv6 by /64) and in all; state is kept as a hash.
    • Disk: the free-space floor applies.
    • DPoP proofs: still spent first, as the reference does, but kept on disk only once their token passes, and otherwise in memory, bounded.
  6. Unbounded outbound reads. Body caps (16 MiB for forwarded answers), 256 outbound slots with a 10 s wait, and a call's rate-limit point paid before its target is resolved.
  7. OAuth and account state.
    • An approved code exchanged after a takedown is invalid_grant.
    • Deactivation or a takedown ends approved, unexchanged codes.
    • Silent sign-in gives login_required for taken-down and deactivated accounts.
    • getServiceAuth and forwarded calls refuse a taken-down account.
  8. Mixed-case chat methods. The chat.bsky. prefix is compared without regard to case, a departure from the reference listed in OAUTH-SCOPES.md.
  9. registerNotify fan-out. 64 registrations per space and 8 per credential key (TooManyRegistrations), with at most 1024 forwards waiting.
  10. Empty admin password. An empty PDS_ADMIN_PASSWORD means unset.
  11. Attacker-chosen lifetimes. Delegation tokens and attestations may be at most an hour ahead.
  12. Space calls and account state. Space writes, getDelegationToken and getSpaceCredential are gated on account state, as the alpha does.
  13. Recovery evicts. resetPassword ends the account's OAuth sessions, approved requests and device sign-ins, a departure from the reference. A sign-in renews the device cookies; the old ones name the device for 30 seconds, then end it.

X-Forwarded-For. It is read only from peers listed in PDS_TRUSTED_PROXIES, unset by default, so rate limits key on the connection's address. The harness sets it for the reference's network, so comparisons are unchanged.

Departures from the reference (findings 8, 11, 13, the DPoP storage, the OAuth caps the reference lacks) are listed in their pages, with the reason. The harness holds the server alone to them.

Not seen from outside, covered by the server's own tests: the hash pool, the outbound and did:web slot pools, the global PAR cap, DPoP proofs held in memory, and the waiting-forward bound.

Checked: --limits (with the new checks), plain seed 1, crash seed 21 with --firehose, --lifecycle, the spaces run, focused runs for the password-reset and device-cookie checks, and cargo test --workspace. The merge queue runs the full gates.

🤖 Generated with Claude Code

Approved

This pull hardens the PDS in a second pass: the SSRF guard now covers spaces fetches, OAuth sign-in gets the login limits, 2FA and a response floor, OAuth and outbound state are bounded, and account state is enforced on OAuth and spaces calls. X-Forwarded-For is now read only from PDS_TRUSTED_PROXIES.

What I checked against .knotless/review.md:

  • Spec: each behaviour change I read has a matching edit in the page that owns it. That covers LIMITS, OAUTH, PROXY, LIFECYCLE, EMAIL, OAUTH-SCOPES and the spaces pages, and the departures from the reference are listed.
  • README: the new text states only what is built, with no history in it.
  • Dependencies: the root Cargo.toml is untouched, so no atproto or MCP crates are added.
  • Harness: the diffs I read add checks and don't loosen any. The X-Forwarded-For change makes the harness set PDS_TRUSTED_PROXIES to the reference's own trust list, so comparisons are unchanged. The new server-only checks are wired into the limits run (harness/checks/limits.mjs).
  • Conformance excuses: harness/conformance.yaml is not touched.

I read the limits.rs, server.rs, lib.rs and dpop.rs diffs, the README, and the changes to harness/compare.mjs, harness/lib/env.mjs, harness/lib/services.mjs and harness/checks/oauth-limits.mjs. They look correct. The trusted-proxy parsing and matching, the shared password-hash path and the bounded DPoP memory set all hold up, and the new tests cover the edge cases.

I did not read the rest of the roughly 8,700-line diff: oauth.rs, oauth/page.rs, outbound.rs, proxy.rs, lifecycle.rs, the space_* modules, the other harness checks and most of the spec pages. I did not run the checks, and the pull says the merge queue runs the full gates.

Merged as 18cb1f5