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

A space read's bad signature is BadSpaceSignature, and a wrong audience a 401

Merged chadtmiller.com asked to merge into main from chadtmiller.com/group-host:spaces/bad-space-signature
.changeset/bad-space-signature.mdnew+7−0
@@ -0,0 +1,7 @@
---
default: patch
---
# A space read's signature and audience are refused as the reference refuses them
A space credential's request whose HTTP Message Signature fails, or whose `Atproto-Space-Audience` is missing or not a DID, is refused with 401 `BadSpaceSignature`, the spaces alpha's name, where it was `BadSignature`. A request signed for another repo than the one it reads is refused with 401 `BadSpaceAudience`, where it was 400, and only once its signature holds.
crates/group-host/src/space_api.rs+11−8
@@ -15,7 +15,7 @@ use atproto::space::{
read_accept_signature, record_header, star,
};
use atproto::space_auth::{self, CLOCK_SKEW, CREDENTIAL_MAX_AGE, Expect, Kind, TokenError};
use atproto::{Cid, drisl};
use atproto::{Cid, drisl, syntax};
use axum::Json;
use axum::extract::{Query, Request, State};
use axum::http::{HeaderMap, HeaderName, HeaderValue, Method, StatusCode, header};
@@ -81,13 +81,10 @@ pub(crate) async fn credential(
let checked = checked
.ok_or_else(|| unauthorized("BadJwtIss", format!("no signing key for {}", token.iss)))?;
checked.map_err(refused)?;
if text("atproto-space-audience") != Some(repo) {
return Err(XrpcError::new(
StatusCode::BAD_REQUEST,
"BadSpaceAudience",
"the space audience is not the repo asked for",
));
}
let audience = text("atproto-space-audience").filter(|a| syntax::is_did(a));
let audience = audience.ok_or_else(|| {
unauthorized("BadSpaceSignature", "missing or invalid space audience DID")
})?;
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);
@@ -97,6 +94,12 @@ pub(crate) async fn credential(
"space credential has been revoked",
));
}
if audience != repo {
return Err(unauthorized(
"BadSpaceAudience",
"the space audience is not the repo asked for",
));
}
Ok(())
}
crates/group-host/tests/spaces.rs+17−4
@@ -823,17 +823,30 @@ async fn reads_only_with_a_credential_the_authority_issued() {
),
(401, "BadJwtSub"),
),
// For the space, but sent for another repo.
// For the space, but signed for another repo.
(
signed(&f.syncer, "did:plc:other", &f.kem, COMMIT_MAC).0,
(401, "BadSpaceAudience"),
),
// An audience changed after the request was signed, gone, or not a DID.
(
with("atproto-space-audience", "did:plc:other".into()),
(400, "BadSpaceAudience"),
(401, "BadSpaceSignature"),
),
(
without("atproto-space-audience"),
(401, "BadSpaceSignature"),
),
(
with("atproto-space-audience", "nobody".into()),
(401, "BadSpaceSignature"),
),
// The request signed with a key the credential is not bound to.
(
bearing(&f.syncer.credential, &other_key),
(401, "BadSignature"),
(401, "BadSpaceSignature"),
),
(without("signature"), (401, "BadSignature")),
(without("signature"), (401, "BadSpaceSignature")),
(without("accept-signature"), (400, "InvalidSpaceMac")),
// Asking for a MAC of a record of a read that vouches for a commit
// asks for none of what it can give.
Cargo.lock+3−3
@@ -65,9 +65,9 @@ checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0"
[[package]]
name = "atproto"
version = "0.3.0"
version = "0.3.1"
source = "sparse+https://knotless.dev/cargo/did:plc:bcgltzqazw5tb6k2g3ttenbj/3mzr5vldibtui/"
checksum = "13ce204ed0ba7aaf46dc4f54ea6553252cb856d28eced00bed82b5de8f2824af"
checksum = "1e429768e66c5615c072c9a0a7ab2e41e3e353c0be86518a93a8b38b6643b071"
dependencies = [
"base64 0.22.1",
"blake3",
@@ -1848,7 +1848,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd"
dependencies = [
"fastrand",
"getrandom 0.4.3",
"getrandom 0.3.4",
"once_cell",
"rustix",
"windows-sys 0.61.2",
Cargo.toml+1−1
@@ -16,7 +16,7 @@ publish = false
unsafe_code = "forbid"
[workspace.dependencies]
atproto = { version = "0.3", registry = "atproto" }
atproto = { version = "0.3.1", registry = "atproto" }
group-host = { path = "crates/group-host" }
group-host-mcp = { path = "crates/group-host-mcp" }
anyhow = "1"