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

The host asks no host a DID or handle names at a private address

Merged
Merged chadtmiller.com asked to merge into main from chadtmiller.com/group-host:host/identity-guard

What changes

The hosts identity data names are guarded. A did:web's /.well-known/did.json, a handle's own /.well-known/atproto-did, the PDS a DID document names (told of a write in a space by notifyRepoUpdate or of revoked credentials by notifyCredentialsRevoked, read by the index for a writer's repo, or for a file by getSpaceBlob) and a group's own domain (checked by putGroupDomain when DOMAIN_CHECK_AT is unset) are now asked only over https, at public addresses, the connection pinned to the addresses checked, with no redirect followed. A host whose PUBLIC_URL is http, a network of test servers, asks them over http too, at any address, as it already did for client metadata, syncer endpoints and proxied services.

One guard, in its own module. crates/group-host/src/guard.rs holds what oauth_clients.rs already had, moved there whole rather than written again: public(ip), pinned_client(url, http_here) and Host::pinned, plus Host::at_pds(doc, nsid), a pinned client for a method at the PDS a document names. identity::Resolver takes http_here(bool) (set from PUBLIC_URL in Host::open) and asks a did:web's own host and a handle's through pinned_client, within LOOKUP (3 s). public now takes an IPv6 address as public only in global unicast (2000::/3, less documentation's), so an address carrying an IPv4 one (NAT64 64:ff9b::/96, IPv4-compatible ::a.b.c.d) and site-local fec0::/10 are no longer taken as public.

What stays as set. The PLC directory, the HANDLE_RESOLVERS services, the addresses DID_WEB_HOSTS sets, DOMAIN_CHECK_AT and the other configured services are the operator's settings and are asked as they are set. DID_WEB_SCHEME=http now reaches a did:web's own host only from a host on http.

Why

The resolver fetched a did:web's document from whatever host the DID names and a handle's /.well-known/atproto-did from whatever name, and the host then called whatever PDS the document named, all with the plain client (redirects followed for PDS calls, any address). Anyone controlling a did:web or a handle could point the host at its own network (a cloud metadata service, an admin port). grain already guards this the same way (https only, public addresses only, no redirects, local only when configured); this applies those rules here and keeps the shape grain has (guard.rs), so both can later move to a shared crate.

The "explicit configuration" for local networks is the one this host already had: PUBLIC_URL on http. Client metadata, syncer endpoints, app logos and the service proxy were already held to it, and docs/design/signing-in.md already said so; a second switch would have been a second convention for the same thing. The e2e harness runs the host on http://localhost:<port>, so it reaches the reference PDS as before.

How it was checked

  • tests/identity.rs: knows_a_public_address (moved from tests/oauth_clients.rs, with NAT64, IPv4-compatible, site-local and discard-prefix cases); asks_a_host_others_name_only_on_https_at_a_public_address (public IPs allowed; loopback, private, link-local, localhost refused; http refused; anything allowed with http_here); asks_no_did_web_or_handle_that_points_inward (a host on https refuses a did:web at 127.0.0.1, at localhost, over http, and a handle's well-known on either scheme; DID_WEB_HOSTS read as set; a host on http reads both); follows_no_redirect_and_reads_no_more_than_a_document now counts hits on the redirect target, for a did:web and a handle, and asserts none.
  • tests/spaces.rs: tells_no_authority_whose_pds_is_not_at_a_public_address, a host on https leaving a PDS on this machine untold and the notice still owed.
  • tests/domain.rs: a_domain_pointing_inward_is_not_asked, for a host on https and on http.
  • Tests whose host on https://host.test reached PDSes on this machine now run on http://host.test (spaces, authority, index, invites, members, interop's space test), as authority.rs and group_spaces.rs tests already did.
  • Locally: clippy with warnings denied across the workspace, and the identity, spaces, domain, authority, index, invites, members, proxy, oauth_clients, group_handle, import, migration, console_login, account_move and actors tests. The 100% coverage gate, interop, firehose (both need the node packages) and e2e are left to CI.

Shortcomings

  • A request is pinned to the addresses resolved when it is made, as the existing pinned clients are; each guarded request builds its own client, so it reuses no connection.
  • DID_WEB_SCHEME=http on a host on https now reads no did:web's own host. Only test networks set it.
Approved

This moves the pinned-client guard into guard.rs and applies it to did:web hosts, handle /.well-known/atproto-did, and the PDS a DID document names. That covers the notify calls, the index reads, getSpaceBlob and the group-domain check. It also tightens public for IPv6 to global unicast only. I read the code changes and found no bug. Redirects are off, and the pin is applied before each request. The operator-configured services (PLC, handle resolvers, DID_WEB_HOSTS, DOMAIN_CHECK_AT) are exempt, as the body says. I read the source files and the guard's logic. I did not read the test files, docs or changeset, and I did not run the checks.

Two non-blocking notes:

  • console_login.rs:402, import.rs:175 and migration.rs:532 still call did::pds on a DID document. I did not check whether they then call that PDS with the plain client. If they do, they are the same kind of hole, and a follow-up should guard them or the body should say why not. permission_sets.rs is already guarded through public_json.
  • Host::at_pds and Host::pinned return Result<_, String>, so each caller converts with anyhow::Error::msg. This is fine as it is.
Merged as 0f69b8b