chadtmiller.com/group-host
atmosphere group host
0
0
A space credential for another space is refused as InvalidCredential
.changeset/invalid-credential.mdnew+7−0
| @@ -0,0 +1,7 @@ | ||
--- | ||
default: patch | ||
--- | ||
| ||
# A space credential for another space is refused as InvalidCredential | ||
| ||
A space read or an authority's method called with a sound space credential for another space is refused with 400 `InvalidCredential`, as the spaces alpha's reference refuses it, where it was 401 `BadJwtSub`. It is checked last, after the request's signature, revocation and audience, and a credential is looked up as revoked under the space it was issued for. | ||
crates/group-host/src/space_api.rs+12−2
| @@ -71,9 +71,12 @@ pub(crate) async fn credential( | ||
"space credential issuer is not the space authority", | ||
)); | ||
} | ||
// The space it is for is held to the one asked for last, as the | ||
// reference does: a credential for another space is a bad request, | ||
// not a bad token. | ||
let expect = Expect { | ||
aud: None, | ||
sub: Some(space), | ||
sub: None, | ||
}; | ||
let check = | ||
|key: &atproto::PublicKey| space_auth::verify(Kind::Credential, jwt, key, &expect, now()); | ||
| @@ -87,7 +90,7 @@ pub(crate) async fn credential( | ||
})?; | ||
let cnf = token.cnf.as_deref().unwrap_or_default(); | ||
space_auth::verify_request(text, cnf).map_err(refused)?; | ||
let revoked = host.store.revoked(space, &token.jti, now() as i64); | ||
let revoked = host.store.revoked(&token.sub, &token.jti, now() as i64); | ||
if revoked.map_err(XrpcError::internal)? { | ||
return Err(unauthorized( | ||
"CredentialRevoked", | ||
| @@ -100,6 +103,13 @@ pub(crate) async fn credential( | ||
"the space audience is not the repo asked for", | ||
)); | ||
} | ||
if token.sub != space { | ||
return Err(XrpcError::new( | ||
StatusCode::BAD_REQUEST, | ||
"InvalidCredential", | ||
"the space credential is not for this space", | ||
)); | ||
} | ||
Ok(()) | ||
} | ||
| ||
crates/group-host/tests/spaces.rs+3−2
| @@ -815,13 +815,14 @@ async fn reads_only_with_a_credential_the_authority_issued() { | ||
(401, "BadJwtSignature"), | ||
), | ||
(bearing(&expired, &f.syncer.key), (401, "JwtExpired")), | ||
// For another space of the same authority. | ||
// For another space of the same authority: a sound credential, for | ||
// the wrong space. | ||
( | ||
bearing( | ||
&credential(&f.authority, &elsewhere, &f.syncer.key, &f.authority.did), | ||
&f.syncer.key, | ||
), | ||
(401, "BadJwtSub"), | ||
(400, "InvalidCredential"), | ||
), | ||
// For the space, but signed for another repo. | ||
( | ||