chadtmiller.com/monolith
An atproto PDS
0
0
# Spaces: credentials
Reading a space takes a **space credential**: a JWT its authority signs,
bound to a key the reader holds, presented with an HTTP Message Signature
made by that key. This page is how the server takes part in that, as each
of the three parties:
- as a **user's PDS**, it mints the delegation token an app trades for a
credential: `com.atproto.space.getDelegationToken`;
- as a **space host**, it mints credentials for the spaces its accounts are
the authority of: `com.atproto.space.authorizeSpaceSync`, with the
delegation tokens and client attestations it is given, registering the
syncers that ask to be told of the space's updates;
- as a **repo host** and a space host, it verifies every credential a method
is called with, and refuses one its authority revoked:
`com.atproto.space.notifyCredentialsRevoked`.
Who takes part, the keys, and the HTTP Message Signature itself are in
[`SPACES.md`](SPACES.md); what every method shares in [`PDS.md`](PDS.md).
The protocol is `spaces/proposal.md`, "Access control" and "OAuth scopes";
where this page and the proposal say the same thing, this page is the one to
build from. The three methods' lexicons are in `lexicons/com/atproto/space/`,
as the pinned alpha has them (`spaces/README.md`).
## The tokens this server signs
A delegation token and a space credential are each a JWT (RFC 7519) in
compact form: the header and the payload, each JSON, base64url without
padding, joined by `.`, then `.` and the signature, base64url without
padding. The signature is ECDSA over secp256k1 with SHA-256 of the ASCII
bytes `<header>.<payload>`, by the signing key of the account named as
issuer (its `#atproto`, `ACCOUNTS.md`): 64 bytes, `r ‖ s`, each 32 bytes
big-endian, with `s` in the lower half of the order (low-S), as
`atproto/cryptography.md` requires. The header is
```json
{"alg": "ES256K", "typ": "<the token's type>", "kid": "#atproto"}
```
and the payload has exactly these claims:
| Claim | Delegation token | Space credential |
| --- | --- | --- |
| header `typ` | `atproto-space-delegation+jwt` | `atproto-space-credential+jwt` |
| `iss` | the user's DID | the space's authority |
| `sub` | the space, as asked for | the space, as asked for |
| `aud` | `<the space's authority>#atproto_pds` | none |
| `cnf` | none | `{"kid": <the credentialKey asked for>}` |
| `iat` | now, in whole seconds since the epoch | the same |
| `exp` | `iat` + 60 | `iat` + 600 |
| `jti` | 16 random bytes as 32 lower case hex digits | the same |
Every token has a `jti` of its own. The server keeps no record of the
credentials it mints.
## getDelegationToken
`com.atproto.space.getDelegationToken`, a query, `?space=<space-ref>`,
answers `{token}`, a delegation token for the space, signed by the token's
account, saying that whoever holds it acts for that account. It says
nothing of whether the account may read the space: that is for the space's
authority to decide when the token is traded. In this order:
1. `space` missing, or not a `space-ref` (`SPACES.md`): `400
InvalidRequest`, whatever the token.
2. The token, as `SESSIONS.md` says of a bearer token: none is `401
AuthMissing`, one the server did not give out `400 InvalidToken`, one
past its `exp` `400 ExpiredToken`, a refresh token `400 InvalidToken`,
and `Basic` or `Atproto-Space-Credential` `400 InvalidToken`.
3. Only a full session may mint one: an access token of scope
`com.atproto.access`, or an OAuth access token whose `space:`
permissions allow `read` of the space (`OAUTH-SCOPES.md`, "Spaces";
else `403 ScopeMissingError`). One of scope `com.atproto.appPass` or
`com.atproto.appPassPrivileged`, an app password's, is `400
InvalidToken`.
4. The token's account deactivated: `401 AccountDeactivated`; taken down:
`401 AccountTakedown` (`LIFECYCLE.md`, taken down before deactivated),
for as long as an access token made before lives. A taken-down
account's `allowTakendown` session is refused at step 2, as
`LIFECYCLE.md` says.
Any space is answered, whether or not its authority exists or is hosted
here. Called with `POST` it is `400 InvalidRequest`, as `PDS.md` says.
## authorizeSpaceSync
`com.atproto.space.authorizeSpaceSync`, a procedure, takes
`{space, credentialKey, delegationToken?, clientAttestation?, notify?}` and
answers `{credential, spaceRev?}`: a space credential bound to
`credentialKey`, and the space's current revision. With `notify`, `{endpoint,
token}`, it also registers that endpoint for the space's updates, or renews
its registration. It takes no authentication: an `Authorization` header,
whatever it holds, is ignored. In this order, the first that applies
answers:
1. The input checked against the lexicon (`PDS.md`): `space` a `space-ref`,
`credentialKey` a string, `delegationToken` and `clientAttestation`
strings if given, and `notify`, if given, an object with `endpoint`, a
string of the format `uri`, and `token`, a string of at most 512 bytes,
the empty string included (its other properties are ignored); else `400
InvalidRequest`. So is `GET`, and a body that is not `application/json`.
2. `credentialKey` not a P-256 `did:key`, as `SPACES.md` defines one (a
compressed point on the curve): `400 InvalidRequest`.
3. The space's authority not an account on this server: `400
SpaceNotFound`. An authority deactivated: `400 RepoDeactivated`; taken
down: `400 RepoTakendown` (`LIFECYCLE.md`, taken down before
deactivated), whatever the space, the token, the attestation and
`notify`, as `listWriters` refuses such an authority (`SPACES-SYNC.md`):
a suspended space's authority signs no credential. Nothing more is read:
a delegation token refused here is not spent.
4. The space deleted, as its lifecycle says (`SPACES-POLICIES.md`): `400
SpaceDeleted`, whatever the token, the attestation and `notify`, none of
which is read: a delegation token refused here is not spent.
*Note:* this is how a syncer that missed a deletion notice
(`SPACES-SYNC.md`) learns of the deletion, whether or not it may read
the space.
5. A `delegationToken` other than the empty string is verified (below):
`400 InvalidDelegationToken` if it fails. Then, if its `sub` is not
`space`, `400 InvalidDelegationToken`; the token is spent all the same.
The token's `iss` is the **user**. An empty `delegationToken` is as
none.
6. A `clientAttestation` other than the empty string is verified (below):
`400 InvalidClientAttestation` if it fails. Its `iss` is the **client**.
An empty one is as none.
7. A space the authority never created: `400 SpaceNotFound`. A delegation
token verified at step 5 is spent all the same, here and at every step
after.
8. The user perimeter: `authorize_read(space, user, client)` (below, "For
the other parts"), with no user when no delegation token was given.
Refused: `400 SpaceNotFound`.
*Note:* this is so that a refusal says nothing of whether the space
exists.
9. The app perimeter: `authorize_app(space, client)`, with no client when
no attestation was given. Refused: `400 AppNotAuthorized`.
Refused at step 8 or 9, a request with `notify` withdraws the
registration of its endpoint and token for the space, if there is one
(`SPACES-SYNC.md`, "Registering"): a syncer that has lost access is told
nothing more. A refusal at an earlier step leaves it as it was, and so
does a policy that cannot decide (a managedspace's app that does not
answer), which answers `502 UpstreamFailure` at step 8 or 9 as
`SPACES-POLICIES.md` says ("Asking a managing app: checkAccess").
10. With `notify`, a registration not yet made is confirmed with its
endpoint first (`SPACES-SYNC.md`, "Registering"): refused with `400
TooManyRegistrations` or `400 RegistrationNotConfirmed` there, nothing
is registered and no credential is minted. One registered already,
lapsed or not, is not confirmed again.
11. The credential, signed by the authority, `iss` the authority, `sub`
`space` and `cnf.kid` `credentialKey`, as above. With `notify`, the
registration is then made or renewed, to lapse when this credential
expires (`SPACES-SYNC.md`, "Registering").
12. The answer: `credential`, and `spaceRev`, the space's revision as it is
once the registration is made (`SPACES-SYNC.md`, "The writer set"), so
that every update after it is sent to the registration; `spaceRev` is
left out while the space's writer set is empty.
The lexicon's `AccountNotAuthorized` and `NotAuthorized` are never
answered: step 8 answers `SpaceNotFound` instead, as the lexicon allows.
### Verifying a delegation token
A delegation token fails, and step 5 answers `InvalidDelegationToken`, when
any of these holds, in no particular order, as all answer the same:
- it is not three parts joined by `.`, or its header or payload is not
base64url of a JSON object, or its signature not base64url;
- the header's `typ` is not `atproto-space-delegation+jwt`, its `alg` not a
non-empty string, or its `kid` not `#atproto`;
- the payload has no `iss`, `sub` or `aud`, an `exp` that is not a number,
or a `jti` that is not a non-empty string;
- `exp` is 5 seconds or more in the past (`now − 5 ≥ exp`, in whole
seconds): a token is taken for up to 5 seconds after its `exp`, for
clocks that differ;
- `exp` is more than 3600 seconds ahead (`exp − now > 3600`): a token
whose `exp` is a day off is refused. Nothing else bounds its life: `iat`
is not read;
*Note:* this is so that no token is kept long (below, "Single-use
values").
- `iss` is not a DID, or its DID document cannot be read, or names no
`#atproto` key (below, "Issuers' keys");
- the signature does not verify against that key (below);
- `sub` is not a `space-ref`, or `aud` is not exactly
`<sub's authority>#atproto_pds`: a bare DID, or another authority's, is
refused;
- it was taken before (below, "Single-use values").
Other claims, as `lxm` or `cnf`, are not read. A token is spent when it
passes all of these, before its `sub` is compared and steps 6 to 12: one
refused there is spent all the same.
### Verifying a client attestation
A client attestation is a `private_key_jwt` client assertion addressed to
the space host (proposal, "Client attestation"). It fails, and step 6
answers `InvalidClientAttestation`, when:
1. it is not three parts as above; its header's `typ` is not
`atproto-client-attestation+jwt` or its `alg` not a non-empty string;
its payload has no `iss`, `sub` or `aud`, an `exp` that is not a number
or is more than 3600 seconds ahead (`exp − now > 3600`), no non-empty
string `jti`, or an `iss` other than its `sub`. Nothing is fetched for
an attestation that fails here;
2. the client's metadata cannot be had: `iss` is the client's `client_id`,
an `https` URL, fetched with `GET` and `Accept: application/json`,
which must answer `200` with a JSON object that is client metadata as
`atproto/oauth.md` says. Its keys are its `jwks`, or, without one, the
JSON Web Key Set its `jwks_uri` answers, fetched the same way; with
neither, it fails. Each fetch goes through `PROXY.md`'s guard ("SSRF
protection"): with protection on, only to a public host name, no IP
address and no `localhost`, resolving only to public unicast
addresses. With protection on or off, it follows no redirect (a `3xx`
is as no answer), reads at most 524288 bytes (a longer answer is as
none), and is given up after 10 seconds;
3. its signature does not verify (RFC 7515) with the key of that set whose
`kid` is the header's `kid`, under the header's `alg`; or its `aud` is
not `<the space's authority>#atproto_pds`; or its `exp` has passed;
4. it was taken before (below, "Single-use values").
The client is then its `client_id`. The server may keep what it fetched for
up to an hour.
## Presenting a credential
A method that takes a space credential is called with the four headers
`SPACES.md` names ("HTTP Message Signatures"), the signature's label any
name, as in:
```
Authorization: Atproto-Space-Credential <credential>
Atproto-Space-Audience: <a DID>
Signature-Input: sig=("authorization" "atproto-space-audience");tag="atproto-space-credential"
Signature: sig=:<64 bytes, base64>:
```
The `Authorization` scheme is matched without regard to case, as
`SESSIONS.md` says of every scheme; a header that is not two words
separated by one space is `400 InvalidToken`. Each method says whether it
takes a credential and what audience it derives from its request: for a
method of a repo in a space, the repo's DID; for a method of the space
host, the space's authority. A method that takes a session token and no
credential answers the `Atproto-Space-Credential` scheme `400
InvalidToken`, as any scheme it does not take; one that takes no
authentication ignores it.
### Verifying a credential
`verify_space_credential(request, audience)` answers the credential's
space, `jti` and `cnf.kid`, or refuses the request. The checks are in this
order, the first that fails answering, each `401` with the error named:
| # | Refused when | Error |
| --- | --- | --- |
| 1 | the token is not three parts joined by `.`, its header or payload is not base64url of a JSON object, or its signature is not base64url | `BadJwt` |
| 2 | the header's `typ` is not `atproto-space-credential+jwt` | `BadJwtType` |
| 3 | the header's `alg` is not a non-empty string, or its `kid` not `#atproto` | `BadJwt` |
| 4 | the payload has no `iss` | `BadJwtIss` |
| 5 | the payload has no `sub` | `BadJwtSub` |
| 6 | `exp` is not a number | `BadJwt` |
| 7 | `cnf.kid` is not a DID | `BadJwtCnf` |
| 8 | `jti` is not a non-empty string | `BadJwt` |
| 9 | `iat` is not a number, `exp ≤ iat`, or `exp − iat` > 3600: no credential lives more than an hour | `BadJwt` |
| 10 | `iat` is more than 5 seconds ahead (`iat > now + 5`) | `BadJwt` |
| 11 | `exp` is 5 seconds or more in the past (`now − 5 ≥ exp`) | `JwtExpired` |
| 12 | `iss` is not a DID | `BadJwt` |
| 13 | `iss`'s DID document cannot be read, or names no `#atproto` key | `BadJwtIss` |
| 14 | the signature does not verify against that key, or its `alg` is not that key's | `BadJwtSignature` |
| 15 | `sub` is not a `space-ref` | `BadJwtSub` |
| 16 | `iss` is not `sub`'s authority | `BadJwtIss` |
| 17 | `Atproto-Space-Audience` is missing or not a DID | `BadSpaceSignature` |
| 18 | the HTTP Message Signature does not verify against `cnf.kid` as `SPACES.md` says, `cnf.kid` not a P-256 `did:key` included | `BadSpaceSignature` |
| 19 | the credential's space and `jti` are revoked here (below) | `CredentialRevoked` |
| 20 | `Atproto-Space-Audience` is not `audience` | `BadSpaceAudience` |
The credential may carry other claims, `aud` too: they are not read. Then
the method compares the credential's space with the space its request
names: another is `400 InvalidCredential`. Nothing here asks whether the
space exists, or whether its authority is active: a repo host knows
neither.
So a credential works at any host, for any audience, as many times as it is
sent, until it expires or that host has it revoked; and a request signed
for one audience is refused at another.
### Issuers' keys
A token's issuer key is the `#atproto` verification method of the issuer's
DID document: for a `did:plc`, the document the directory at `PDS_PLC_URL`
serves; for a `did:web`, its host's `/.well-known/did.json` (below). Its key is
`ES256K` for a secp256k1 key and `ES256` for a P-256 key, and a token whose
`alg` is the other's does not verify. The signature is 64 bytes, `r ‖ s`,
and must be low-S: a high-S signature, which `atproto/cryptography.md`
calls malleable, does not verify.
An issuer that is an account here, active, deactivated or taken down
(`LIFECYCLE.md`) but not deleted, has its token verified first against
the key the server holds for the account, with nothing read; a token that
does not verify against it is verified as any other issuer's is, below.
So the server reads no document for the tokens it signs itself, its
accounts' delegation tokens, credentials and service auth, however many
there are. A deleted account's DID is any other issuer's: its document is
read.
For any other issuer the server keeps the key it read, with when the read
began:
- A key read less than `PDS_DID_CACHE_SECS` ago (`LIMITS.md`) is used.
- A key read longer ago, but less than `PDS_DID_CACHE_MAX_SECS` ago, is
used too, and a token it verifies is answered at once, the document read
again after it: a key in use is renewed with no call waiting for it.
`PDS_DID_CACHE_MAX_SECS` below `PDS_DID_CACHE_SECS` is taken as
`PDS_DID_CACHE_SECS`.
- An issuer with no key kept, or one read `PDS_DID_CACHE_MAX_SECS` ago or
longer, has its document read before its token is verified.
- When a signature does not verify against a key kept, the document is
read again, and the token verifies if it verifies against the key read
then; so a token signed with a key the issuer has just rotated to is
taken at once.
- One issuer's document is read at most once at a time: a call that needs
it while it is read waits for that read, and takes the key it gave if
that key is kept as above and is not one its token failed against.
- It keeps at most one key for each 1024 bytes of `PDS_CACHE_BYTES`
(`STORE.md`): 262144 by default. Past that, the key used longest ago is
forgotten.
- The keys kept are written to `PDS_DATA_DIR/issuer-keys` at a shutdown
(`SIGTERM` or `SIGINT`, `OPERATIONS.md`) and at most once a minute while
they change, never synced: a cache, not state. A start reads it back in
the background, dropping any key read `PDS_DID_CACHE_MAX_SECS` ago or
longer; until it has, a token is verified as if no key were kept, and a
key read since the start is kept over the file's for the same issuer,
and counts as used later than any of the file's. A file that is
missing, cannot be read, or is not as the server writes it, is as none.
With `PDS_DID_CACHE_SECS=0` no key is kept, and every token's issuer's
document is read for it, but for the issuers that are accounts here.
*Note:* an issuer whose tokens come often, as a user's to an app that
syncs a space, would otherwise have every call that found its key expired
wait for the directory; and a server's start, every issuer at once. The
windows are the reference's: it keeps DID documents an hour, and serves
them while it reads them again for up to a day.
A `did:web` document is fetched as `PROXY.md`'s guard allows ("SSRF
protection"): with protection on, only over `https` from a public host
name, no IP address (`did:web:127.0.0.1%3A8443`, `did:web:10.0.0.5`) and
no `localhost`, resolving only to public unicast addresses; with it off,
from any host, and from `localhost` over `http`
(`did:web:localhost%3A2583` from
`http://localhost:2583/.well-known/did.json`). Either way it follows no
redirect (a `3xx` is as no answer), reads at most 65536 bytes (a longer
document is as one that cannot be read), and is given up after 10
seconds. It is fetched in the pool `LIMITS.md` keeps for `did:web`
documents, apart from the directory's slots, and a call that presents such
a token has paid its rate limits before it is fetched (`LIMITS.md`, "Rate
limits"). A document that cannot be fetched so is one that cannot be read:
the token's issuer has no key.
## Revocation
`com.atproto.space.notifyCredentialsRevoked`, a procedure, takes `{space,
credentials}`, one to a hundred `jti`s, each a non-empty string, and
answers `200` with no body. It is how a space's authority tells a repo host
to refuse those of the space's credentials before they expire. This server
never sends one; it takes them.
It is authenticated with service auth (`atproto/xrpc.md`, "Inter-Service
Authentication"): a bearer JWT signed by the authority. The token is checked
before the input, in this order, each `401` with the error named:
| Refused when | Error |
| --- | --- |
| no `Authorization` header, an empty one, or one whose scheme is `Basic`, `DPoP` or `Atproto-Space-Credential` | `MissingJwt` |
| it is not three parts joined by `.`; its header is not a JSON object with a string `alg`; or its payload is not a JSON object with a number `exp` | `BadJwt` |
| the header's `typ` is `at+jwt`, `refresh+jwt` or `dpop+jwt` (any other, or none, is taken) | `BadJwtType` |
| `exp` has passed (`now > exp`) | `JwtExpired` |
| `lxm` is not `com.atproto.space.notifyCredentialsRevoked` | `BadJwtLexiconMethod` |
| `iss` is not a DID, or a DID and a `#` fragment | `BadJwtIss` |
| `iss`'s DID document cannot be read, or names no `#atproto` key | `AuthenticationRequired` |
| the signature does not verify against that key (below) | `BadJwtSignature` |
A scheme the server does not know, or a header that is not two words, is
`400 InvalidToken`, as `SESSIONS.md` says. The signature is held to the
issuer's key as above ("Issuers' keys"), except that a high-S signature is
taken too. `kid`, `iat` and `jti` are not read, and the same token may be
sent again until it expires. Then:
1. The input checked against the lexicon: `400 InvalidRequest`.
2. `iss`, as written, not the authority of `space`: `403 Forbidden`.
3. `aud` not the DID, bare, of an account on this server: `403 Forbidden`.
A DID with a fragment, the server's own `did:web`, or an account
elsewhere, is refused.
4. Each `jti` is kept, with the space, as revoked: from then on any
credential of that space with that `jti` is refused here
(`CredentialRevoked`), whatever account `aud` named and whatever
audience it is presented to. A `jti` revoked in one space is not
revoked in another. The space need not exist.
A revocation is kept for at least 3610 seconds after it was last received;
receiving it again starts that time again. Revocation is per host: another
host, the space host too, takes the credential until it is told.
*Note:* 3610 seconds is an hour, a credential's longest life, and twice the
5 seconds a clock may differ by, after which no credential with that `jti`
can still be taken.
As a space host, the server revokes none of the credentials it issues: a
syncer's registration lasts until the credential of its latest
authorization expires (`SPACES-SYNC.md`, "Registering"), and is never
dropped for a revocation. A revocation it takes is a repo host's, as above,
and changes no registration.
## Single-use values
Delegation tokens and client attestations are each taken once: the server
keeps them in its record of single-use values (`OAUTH.md`, "Single-use
values"), which survives restarts and forgets each entry when its time has
passed:
| Namespace | Value | Kept until |
| --- | --- | --- |
| delegation tokens of an issuer | the token's `jti`, per `iss` | 5 seconds after the token's `exp` |
| client attestations of a client | the attestation's `jti`, per `client_id` | its `exp` |
A `jti` is single-use per issuer: another account's token with the same
`jti` is taken. As neither a delegation token nor an attestation is taken
with an `exp` more than 3600 seconds ahead, no entry is kept more than
3605 seconds.
## Durability
As `DURABILITY.md` says of the rest: a revocation the server answered `200`
to, a delegation token it spent and an attestation it took survive the
server being killed, for as long as each is kept.
## As tools and commands
The three methods are MCP tools and CLI commands as `COMMANDS.md` says:
`space_get_delegation_token` (`pds space get-delegation-token --space …`),
`space_authorize_space_sync` (`pds space authorize-space-sync`) and
`space_notify_credentials_revoked`, whose answer, none, is `{}`. Each
answers JSON, so each has a tool, with the hints of `COMMANDS.md`'s
"Hints": `getDelegationToken` and `authorizeSpaceSync` sign a token, the
latter keeping a registration too, and change nothing else, so neither is
read-only nor destructive; `notifyCredentialsRevoked` ends a credential, so
it is destructive. `notifyCredentialsRevoked`'s service-auth token is the
bearer token a tool or command is given (`PDS_TOKEN`), as any other.
## For the other parts
- **`verify_space_credential(request, audience) -> {space, jti, kid}`**:
every method that takes a credential calls it (above, "Verifying a
credential"), with the audience it derives, and then answers `400
InvalidCredential` when `space` is not the space its request names. The
space repo's read methods take it with the repo's DID as audience; the
space host's methods with the space's authority.
- **`authorize_read(space, user_did?, client_id?) -> bool`** and
**`authorize_app(space, client_id?) -> bool`** are the policies' (their
page says how each policy answers). `authorizeSpaceSync` asks the first
with the delegation token's user, or none, and the attested client, or
none; then the second, only when the first allowed.
- **Registrations** are the notifications' (`SPACES-SYNC.md`,
"Registering"). With `notify`, `authorizeSpaceSync` withdraws the pair's
registration when step 8 or 9 refuses; at step 10 has a new one
confirmed, or refused; and at step 11 makes or renews it, to lapse at the
credential's `exp`. Its `spaceRev` (step 12) is the writer set's.
- **OAuth.** `getDelegationToken` is the method a `space:` grant reaches
(proposal, "OAuth scopes"): an OAuth access token whose scope grants
`read` (not only `read_self`) of the space may mint a token for its
account, as a full session may. An app password's session may not.
## Where the reference departs from this page
- A client attestation that fails step 1 above (malformed, the wrong
`typ`, `iss` other than `sub`, or a claim missing) is `500
InternalServerError` from the reference; the server answers `400
InvalidClientAttestation`, as the lexicon names it.
- The reference forgets a spent delegation token at its `exp`, though it
takes the token for 5 seconds more; the server keeps it until then.
- The reference keeps spent tokens in memory: they are taken again after it
restarts. The server keeps them across restarts.
- The reference takes a delegation token or a client attestation whose
`exp` is any time ahead, a day or a year; the server refuses one more
than 3600 seconds ahead.
- The reference runs with no SSRF protection, and with it off fetches a
client's metadata over `http` from `localhost`; what the guard refuses is
the server's alone.
The harness does not compare these.
## How it is checked
The spaces run (`SPACES.md`) starts a second alpha PDS beside the first, the
**peer**, on the same directory. Each check is made twice, once with the
alpha in a role and once with the server in it, the peer or the first alpha
playing the other roles both times; the answers are compared as `PDS.md`
says (status and `error`; DIDs named by role), and each side is held to
this page. In this order:
- **The server as user's PDS**, the space host the first alpha. A member on
each side asks for a delegation token: its claims must be as above and
verify against the account's key, and the alpha must trade it for a
credential, once. Refused alike: no token, an app password's, a
privileged one's, a refresh token, `Basic`, a credential, input the
lexicon refuses. This needs nothing of the server but this page.
- **The server as space host**, the members' repo host the peer. On each
side an authority makes, with the policies' methods, a memberspace with a
member on the peer, who writes a record into it there, a public one, a
personalspace, one with `allowedApps`, and a deleted one.
The member's delegation tokens, from the peer, are traded with each side:
the credential's header and claims must be as above and verify against
the authority's key in the directory, low-S; the answer has a `spaceRev`
for the memberspace and none for the public space no one wrote to; and
the peer, as the member's repo host, must take the credential for the
member's records. Then each step of `authorizeSpaceSync` refused, on both
sides alike: replays, a token spent by a refusal (of the app perimeter,
of a space never made), the wrong space, no token, a non-member's token,
`credentialKey`s that are no P-256 key (one for a space not hosted, the
key answered first), input the lexicon refuses, a space not hosted,
missing or deleted, each with and without a token and with a token that
is no JWT (the deleted and the not hosted answered first; a token
presented for the deleted space not spent, and taken once the space is
created again), and delegation tokens the harness signs with the
member's key, each with one thing wrong (or, for those taken, one thing
unusual: no `iat`, issued 59 minutes ahead, an `exp` an hour ahead, an
extra claim, a `jti` another account used, `exp` 2 seconds past).
Attestations: one whose client cannot be fetched is compared; malformed
ones are held to this page alone (above); `allowedApps` with none is
`AppNotAuthorized`. Held to this page alone: delegation tokens whose
`exp` is 3610 seconds and a day ahead, refused; and an attestation whose
`exp` is a day ahead, of a client at `https://localhost:<port>`, a
listener the harness runs that counts connections: refused with no
connection, while one whose `exp` is a minute ahead connects there.
`notify` is checked with the notifications (`SPACES-SYNC.md`, "How it is
checked").
- **The server as repo host**, the space host the first alpha. A writer on
each side, a member, writes a record into the alpha's space with the space
repo's `createRecord`, and is read
with `com.atproto.space.listRecords`, presenting credentials the alpha
issued and ones the harness signs with the authority's key, each with
one thing wrong, row by row of the table above, and HTTP signatures each
with one thing wrong, or with a label of their own, or beside another
signature untagged (taken), or tagged twice (refused). Then the
authority's revocations, with service auth the harness signs, each with
one thing wrong; a revoked credential refused, another space's `jti` not;
and an authority whose key is rotated in the directory, after its old key
was used.
- **A restart** of the server: a revocation it took, and a delegation token
it spent, are refused after it.
- **Account states**, in the policies' stage 5 (`SPACES-POLICIES.md`), on
each side an account deactivated, then another taken down by the admin:
its `getDelegationToken` with its token from before is refused, a
`space` that is no `space-ref` answered first; and `authorizeSpaceSync`
of its space, it the authority, with no token, with a user's token from
the peer (which is not spent), with a token that is no JWT, and of a
space it never made, is `RepoDeactivated` or `RepoTakendown`, while a
`credentialKey` that is no key, and input the lexicon refuses, are
answered first. Compared once the server can put an account in each
state; until then the reference alone.
- **The guard** (`harness/spaces/ssrf.mjs`, near the end of the run), the server
alone. First as the run starts it, protection off: an issuer
`did:web:localhost%3A<port>` whose document a harness listener serves
over `http` is taken for a revocation; one whose host answers `302` to
another that serves it, and one whose document is 70000 bytes, are
`AuthenticationRequired`, the redirect's target never asked, while one
of 60000 bytes is taken. Then the server is started again without
`PDS_DISABLE_SSRF_PROTECTION`, and plain TCP listeners on `127.0.0.1`
count connections: revocations and `notifyRepoUpdate` with service auth
from `did:web:localhost%3A<port>` and `did:web:127.0.0.1%3A<port>`
(`AuthenticationRequired`), delegation tokens from them
(`InvalidDelegationToken`), attestations of clients at
`https://127.0.0.1:<port>` and `https://localhost:<port>`
(`InvalidClientAttestation`) and a credential from such an authority
(`BadJwtIss`) are each refused, and no listener sees a connection; so are
syncers' endpoints there (`SPACES-SYNC.md`, "How it is checked"). The
server is then started again as the run starts it.
- **Issuers' keys** (`harness/spaces/issuers.mjs`, after the guard), the
server alone: revocations with service auth from `did:web` issuers whose
documents a harness listener serves, recording each read. Started again
with `PDS_CACHE_BYTES=65536`, so that it keeps 64 keys: eight at once
from an issuer not read before, its document 400 ms slow, are each taken
with one read of it; then 65 more issuers, one revocation each, after
which one from the second of them reads nothing and one from the first
reads its document again; then shut down by `SIGTERM` and started again,
a second later one from that second issuer reads nothing and one from
the third, forgotten before, reads its document; then shut down by
`SIGINT` and started again, one from the third reads nothing. Started again
with `PDS_DID_CACHE_SECS=3` and `PDS_DID_CACHE_MAX_SECS=8`: from a new
issuer, one 3.5 s after its document was read, the document now 1.5 s
slow, is answered within 1 s, and the document is read once more after
it; and one 9 s after that read waits for a read of its own. The server
is then started again as the run starts it. That an issuer that is an
account here has nothing read is checked with the directory's requests
(`LIMITS.md`, "How it is checked").
What the reference cannot say: that the server's revocations last 3610
seconds, and that a token past 5 seconds after its `exp` is refused while
still kept, which would take the run that long; that the server signs only
low-S, beyond each token checked; an attestation that verifies, which
needs a client's metadata at an `https` URL the run cannot serve, and so
an attestation `jwks_uri` fetched through the guard, or past 524288 bytes;
that a fetch is given up after 10 seconds, and the `did:web` pool's bound,
which are time and load; and that a public host resolving to a private
address is refused, which needs a name the run does not control.