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

A space credential for another space is refused as InvalidCredential

Merged
Merged chadtmiller.com asked to merge into main from chadtmiller.com/group-host:spaces/invalid-credential

A sound space credential for a different space is now refused with 400 InvalidCredential; it was 401 BadJwtSub. That is what the spaces alpha's reference PDS answers, and it checks this last, after the signature, revocation and audience. Revocation is now looked up under the space the credential was issued for.

Claude Opus 5.5 · high effort

What changes

space_api::credential is the check behind the space reads and behind the authority's methods taken with a credential (as_authority, used by listWriters).

  • It no longer passes the requested space to space_auth::verify as the expected sub.
  • The credential's sub is now compared with the requested space last, and a mismatch gets 400 InvalidCredential.
  • store.revoked now takes the credential's own sub instead of the requested space.

A sub that is not a space URI still gets 401 BadJwtSub, as in the reference.

Why

In @atproto/pds 0.0.0-spaces-alpha-20261113224550, spaceCredentialAuth verifies the token without an expected subject and checks revocation under parseSpaceSub(payload.sub). The handlers then call assertCredentialSpace, which first throws 401 BadSpaceAudience and then 400 InvalidCredential ("Credential is not scoped to this space"). This follows on from the BadSpaceSignature and BadSpaceAudience pull (A space read's bad signature is BadSpaceSignature, and a wrong audience a 401).

How it was checked

just t -p group-host --test spaces --test authority passes: 14 and 15 tests. In reads_only_with_a_credential_the_authority_issued, the "another space of the same authority" case now expects 400 InvalidCredential.

Approved

This moves the sub check in space_api::credential to the end. The credential is verified without an expected subject, and revocation is looked up under the credential's own sub. A mismatch with the requested space then returns 400 InvalidCredential, after the signature, revocation and audience checks.

I read the whole function and found nothing wrong. The earlier SpaceRef::parse on token.sub still returns 401 BadJwtSub for a sub that isn't a space. The iss check still ties the issuer to the credential's own space authority. Revocation uses token.sub, the space the credential was issued for. The final comparison uses the same string form that verify compared before, so it behaves as before. The test case is updated to match.

I didn't run the tests. The change is small and the reasoning holds up.

One small thing: the doc comment on credential still says "for this space", which is still true, but it could mention that the space is checked last.

Merged as 09d2b75