chadtmiller.com/group-host
atmosphere group host
Apps sign in to a group with OAuth, approved by a member in the console
MergedThis pull adds the host's OAuth server: PAR, DPoP, PKCE and client metadata and assertions. It also adds opaque hashed grants, the approve/decline methods, scope narrowing and atproto::jose. The token and grant logic reads sound: codes are single-use, refresh rotation is atomic, and PKCE, key binding and same_auth are all checked. Two things need to change first.
- SSRF through client documents.
fetch_json(oauth_clients.rs:236) fetches any https URL. The URL comes from theclient_idof an unauthenticated PAR, or from ajwks_uri. It does not refuse loopback, private, link-local or metadata-service addresses, and redirects are off but the target is not filtered. Its errors also reach the caller (answered 404,too large,not a JSON object). That makes a blind probe of the host's internal network. @atproto/oauth-provider, which this claims to follow, refuses such hosts. Please check the resolved address before connecting and refuse non-public ones. In tests that use http on localhost, allow it only under the existinghttp_herecondition. Add a test. - The loopback redirect check is a prefix match.
loopback()(oauth_clients.rs:101) usesstarts_with("http://127.0.0.1").http://127.0.0.1.evil.example/cbpasses, so a client id ofhttp://localhost?redirect_uri=http://127.0.0.1.evil.example/cbis accepted as "An app on this device" while redirecting off the machine. Parse the URL and comparehost_str()to127.0.0.1or[::1], asregistered()does. Add a test.
Smaller points, not blocking:
same_authcompareskid, and a missingkidbecomes"".authenticate_clientthen tries every key in the set, so omittingkiddefeats "must keep to that key". Require akid, or compare the thumbprint of the key that verified.nonce_atHMACs with the PLC rotation private key. A key for another purpose is safer, such as one derived from it or a separate secret.- A grant keeps the scope it was approved with, through refreshes of up to 90 days. If a member's roles shrink, the scope does not narrow. Make sure the resource-side pull re-narrows on use, and say so in
signing-in.md. code_verifierlength (43–128 characters) is not checked.
I read the new source files in crates/atproto and crates/group-host/src (jose, oauth, clients, dpop, store, authorization). I did not read oauth_scope.rs, the tests, the docs or the reference fixtures. The test and check runs were still queued when I looked.
crates/group-host/src/oauth_clients.rsline 236Outdated
| |
/// The JSON at `url`, an https URL (or http, while this host is on | |
/// http itself, as a network of test servers is). | |
async fn fetch_json(&self, url: &str, what: &str) -> Result<Value, OAuthError> { |
Fetches any https host, including private and loopback addresses, and the errors reach the caller. Refuse non-public addresses before connecting.
crates/group-host/src/oauth_clients.rsline 101Outdated
return Err(invalid_metadata("the loopback client id names one scope")); | |
} | |
for r in &redirects { | |
if !r.starts_with("http://127.0.0.1") && !r.starts_with("http://[::1]") { |
starts_with accepts http://127.0.0.1.evil.example/…. Compare the parsed host instead.
crates/group-host/src/oauth_clients.rsline 179Outdated
/// Whether a later request authenticates as the first did: the same | |
/// method, and for a confidential client, the same key. | |
pub fn same_auth(first: &Value, now: &Value) -> bool { | |
first["method"] == now["method"] && first["kid"] == now["kid"] |
A missing kid becomes "" and matches any key in the set, so this does not hold the client to its first key.
Fixed in 23f6158:
- A client document or key set is fetched only from a public address: the name is resolved first, every address must be public (not loopback, private, link-local, shared, reserved, documentation or multicast, v4-mapped included;
oauth_clients::public), and the connection is pinned to those addresses, so a rebinding name is not followed elsewhere. Only a host on http itself (a test network) may fetch from anywhere. Tests:127.0.0.1,localhost,10.0.0.1,[::1]and169.254.169.254refused;knows_a_public_addressover each range. - A loopback client's redirects are parsed: http, and the host exactly
127.0.0.1or[::1].127.0.0.1.evil.example, https and a non-URL are refused in tests.
The smaller points:
- A confidential client is held to the thumbprint of the key that verified its assertion, not its
kid: a test signs with the other key naming no kid and is refused, and the first key naming none passes. - Nonces HMAC under a key derived from the host's secret for nonces alone.
- Re-narrowing on use: the resource-side pull will ask the member's roles again on each use;
signing-in.mdsays so now. - A
code_verifiermust be 43 to 128 unreserved characters.
Also: a database failure answers server_error (tested), and the races in approve and decline return without a branch nothing reaches.
Both blocking findings from round 1 are fixed, and so are the smaller points.
- SSRF:
fetch_json(oauth_clients.rs) resolves the host first and refuses the fetch unless every address passespublic().public()covers loopback, private, link-local, shared, reserved, documentation and multicast ranges, with v4-mapped v6 included. The client then pins the connection to the addresses it checked, so DNS rebinding can't redirect it. Redirects stay off. Plain http to any address is allowed only when the host's ownpublic_urlis http. Tests cover the refused addresses. - Loopback check:
registered()parses the URL and compares the host exactly. Theloopback()client-id check was reported as fixed with tests, but I did not re-read it. kidandsame_auth: it now compares the key thumbprint (jkt), so omittingkidno longer defeats it.- Smaller points: nonces use a derived key, the
code_verifierlength is checked, andsigning-in.mdnow says the resource side re-narrows on use. I did not re-read these.
All three workflows pass at 23f6158: test, check, and the two path-skipped ones. As in round 1, I did not read oauth_scope.rs, the tests or the docs.
What changes
The OAuth server. The host is the authorization server an app signs in to a group with, as atproto profiles OAuth (
oauth.rs): its metadata at/.well-known/oauth-authorization-serverand/.well-known/oauth-protected-resource; pushed requests at/oauth/par, required, with PKCE (S256) and a DPoP proof;/oauth/authorize, which sends the browser on to the console's/authorize(newCONSOLE_URL, the public URL by default);/oauth/tokenfor a code (once, within a minute) or a refresh token (a new pair, the old one ended); and/oauth/revokefor either token. Every endpoint answers any origin, as a browser app reaches them.Clients (
oauth_clients.rs) are known by their metadata documents (https, no redirects, at most 64 KiB, kept ten minutes, checked as @atproto/oauth-provider checks them), or are the loopback clienthttp://localhost. A confidential client signs each request with a key its metadata lists (private_key_jwt, inline or byjwks_uri) and must keep to that key.DPoP (
oauth_dpop.rs): ES256 or ES256K proofs; a nonce is an HMAC of the time, checked without being kept; each proof'sjti, like each client assertion's, is spent once.Grants (
oauth_store.rs): tokens are opaque and kept only as their SHA-256. A grant records the member who approved it, and ends when they are ejected or leave.Approving (
authorization.rs):getAuthorizationoffers the groups the caller may sign the app in as (the one the app named inlogin_hint, by handle or DID, or each active group where they hold a role), with what the app would get and not get in each;approveAuthorizationsigns it in as the chosen group, for a member holding a role there, and the group the app named if it named one;declineAuthorizationsends it back withaccess_denied.What a token may do (
oauth_scope.rs): the scope asked for is narrowed to the member's roles (repo collections and other services' methods by the permissions record's grants, the configure set for roles that configure, space scopes by each space's access record,space:*made one scope per space, blobs only beside a write), then made concrete: the configure set as its lexicon's space scopes,authority=selfas the group, and a space scope naming no collection as naming every one.atproto::jose: public keys as JWKs, RFC 7638 thumbprints, and ES256/ES256K JWTs signed and checked.
The design is in
docs/design/signing-in.md.Why
Step 6 of
docs/design/README.md: apps act as a group through tokens a member approves, never a password. This is its first part. What the tokens do (writes as the group, group tokens, app passwords, connected apps) and provisioning come next.What changed from the prototype:
getAuthorizationis itsgetSpaceBlobURL.How it was checked
crates/atproto/tests/jose.rs: the JWKs, thumbprints and proofs jose 5.10.0 makes of fixed P-256 and secp256k1 keys (tests/reference/jose.mjs→jose.json), RFC 9449's example thumbprint, and RFC 7636's PKCE example.tests/oauth.rs: metadata, CORS, the nonce handshake, each refused request and proof, the browser's way to the console, codes (once, from their own client and key, not lapsed), refreshing, revoking by either token, and grants ending when a member is ejected. These port the prototype'sauthorization.test.tssections on the pushed request, the token and the redirect.tests/oauth_clients.rs: a confidential client end to end, inline and byjwks_uri; each refused assertion; holding a client to its first key; each metadata rule; reading documents only where it should; the loopback client; the cache. These porta confidential clientandsameClientAuth.tests/authorization.rs: getAuthorization, approveAuthorization and declineAuthorization, porting their sections.tests/oauth_scope.rs: narrowing and making concrete, porting thenarrowScopeandselfauthority sections.CI runs the 100% gate, clippy, and
just lex.Shortcomings
/authorizepage comes with step 7, so for now a member approves only through the methods.space:*made concrete for a role granted*and a collection there lists both, the wider covering the narrower, as the prototype did.