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

Bound what a report says, and take up the other reviews' notes

Merged chadtmiller.com asked to merge into main from chadtmiller.com/group-host:review/notes
crates/group-host/src/import.rs+7−1
@@ -517,7 +517,13 @@ pub async fn complete_import(
"the signed operation does not give the account to this host",
));
};
let sent = host.plc.publish(did, &signed).await;
// The directory may have it already: sent by the account's server, or
// by a try of this that failed after sending it. It is not sent again.
let last = host.plc.last_op(did).await.ok().map(|op| op.cid());
let sent = match last == Some(signed.cid()) {
true => Ok(()),
false => host.plc.publish(did, &signed).await,
};
sent.map_err(|e| {
refused(
"InvalidOperation",
crates/group-host/src/moderation.rs+29−8
@@ -171,18 +171,28 @@ fn not_found() -> XrpcError {
}
/// The space a record's URI is in, `at://<authority>/space/<type>/<skey>`,
/// and its authority, for a URI of a record inside one.
/// and its authority, for a URI of a record inside one, each of its parts
/// what it says: so a URI anyone sends is bounded, as its parts are.
pub fn space_of(uri: &str) -> Option<(String, String)> {
let parts: Vec<&str> = uri.strip_prefix("at://")?.split('/').collect();
match parts[..] {
[authority, "space", kind, skey, _repo, _collection, _rkey] => Some((
format!("at://{authority}/space/{kind}/{skey}"),
authority.to_string(),
)),
_ => None,
}
let [authority, "space", kind, skey, repo, collection, rkey] = parts[..] else {
return None;
};
let dids = syntax::is_did(authority) && syntax::is_did(repo);
let names = syntax::is_nsid(kind) && syntax::is_nsid(collection);
let keys = syntax::is_record_key(skey) && syntax::is_record_key(rkey);
(dids && names && keys).then(|| {
let space = format!("at://{authority}/space/{kind}/{skey}");
(space, authority.to_string())
})
}
/// The longest reason a report gives, as `createReport`'s lexicon has it.
const REASON_MAX: usize = 20_000;
/// The longest reason type a report gives: one of the known ones, or
/// another as long.
const REASON_TYPE_MAX: usize = 256;
/// A subject as a label holds it, and as the queue keys it: an account's
/// DID, or a record's URI.
fn subject_of(asked: &Value) -> Result<(Value, String), XrpcError> {
@@ -459,6 +469,17 @@ pub async fn create_report(
let reason_type = body["reasonType"]
.as_str()
.ok_or_else(|| invalid("reasonType is required"))?;
if reason_type.len() > REASON_TYPE_MAX {
return Err(invalid(format!(
"reasonType is {REASON_TYPE_MAX} bytes at most"
)));
}
if body["reason"]
.as_str()
.is_some_and(|r| r.len() > REASON_MAX)
{
return Err(invalid(format!("reason is {REASON_MAX} bytes at most")));
}
let uri = body["subject"]["uri"].as_str();
let uri = uri.ok_or_else(|| invalid("a report here is of a record, by its uri"))?;
let space =
crates/group-host/tests/import.rs+14−0
@@ -644,6 +644,20 @@ async fn sends_the_operation_switches_it_on_and_makes_a_group_its_mover_runs() {
);
}
#[tokio::test]
async fn takes_an_operation_the_directory_has_already() {
let w = world().await;
let dana = &w.people[0];
let (_, out) = w.start(dana, json!({})).await;
let operation = w.signed(&out["recommendedCreds"], |_| {}).await;
// Its server sent it itself, as submitPlcOperation does.
let signed = Signed::from_json(&operation).unwrap();
w.h.host.plc.publish(&w.did, &signed).await.unwrap();
let (status, done) = w.finish(dana, operation).await;
assert_eq!(status, 200, "{done}");
assert!(w.h.host.deactivation(&w.did).unwrap().is_none());
}
#[tokio::test]
async fn refuses_an_operation_that_does_not_give_the_account_to_this_host() {
let w = world().await;
crates/group-host/tests/moderation.rs+15−3
@@ -107,8 +107,8 @@ async fn takes_a_report_from_anyone() {
json!({"handle": "hikers.groups.test", "displayName": "Hikers"}),
)
.await;
let elsewhere = json!({"uri": format!("at://did:plc:elsewhere/space/{CALENDAR}/rides/{}/c.d/e", carol.did), "cid": "x"});
let not_ours = json!({"uri": format!("at://{other}/space/{CALENDAR}/none/{}/c.d/e", carol.did), "cid": "x"});
let elsewhere = json!({"uri": format!("at://did:plc:elsewhere/space/{CALENDAR}/rides/{}/c.d.e/f", carol.did), "cid": "x"});
let not_ours = json!({"uri": format!("at://{other}/space/{CALENDAR}/none/{}/c.d.e/f", carol.did), "cid": "x"});
for (subject, refused) in [
(json!({"did": carol.did}), (400, "InvalidRequest")),
(
@@ -117,6 +117,11 @@ async fn takes_a_report_from_anyone() {
),
(elsewhere, (400, "NotHosted")),
(not_ours, (400, "NotHosted")),
// Each part of its URI what it says, so none is unbounded.
(
json!({"uri": format!("at://{did}/space/{CALENDAR}/rides/{}/c.d.e/{}", carol.did, "r".repeat(513)), "cid": "x"}),
(400, "InvalidRequest"),
),
] {
assert_eq!(
error(&report(&h, &carol, subject.clone()).await),
@@ -133,6 +138,13 @@ async fn takes_a_report_from_anyone() {
)
.await;
assert_eq!(error(&said), (400, "InvalidRequest"));
for body in [
json!({"subject": record, "reasonType": "x".repeat(257)}),
json!({"subject": record, "reasonType": "com.atproto.moderation.defs#reasonSpam", "reason": "x".repeat(20_001)}),
] {
let said = post(&h, lxm, &body, &[auth(&h, &carol, lxm)]).await;
assert_eq!(error(&said), (400, "InvalidRequest"), "{}", said.1);
}
assert_eq!(post(&h, lxm, &json!({}), &[]).await.0, 401);
}
@@ -216,7 +228,7 @@ async fn writes_a_label_beside_what_it_labels() {
)
.await;
let theirs =
json!({"uri": format!("at://{other}/space/{CALENDAR}/x/{}/c.d/e", bob.did), "cid": "x"});
json!({"uri": format!("at://{other}/space/{CALENDAR}/x/{}/c.d.e/f", bob.did), "cid": "x"});
for (body, refused) in [
(
json!({"group": did, "subject": {"did": "not a did"}, "val": "x"}),
crates/opensocial/src/lib.rs+7−1
@@ -236,7 +236,13 @@ pub async fn run(args: &[String], env: &Env) -> Result<String> {
inspect(&signed_in(env).await?, &host, group).await
}
"membership" => {
let a = parse(rest, &["reason", "message"])?;
// Each takes its own option: eject a reason, invite a message.
let known: &[&str] = match rest.first().map(String::as_str) {
Some("eject") => &["reason"],
Some("invite") => &["message"],
_ => &[],
};
let a = parse(rest, known)?;
membership(&signed_in(env).await?, &host, &a).await
}
"migrate" => {
crates/opensocial/tests/commands.rs+8−0
@@ -229,6 +229,14 @@ async fn says_what_is_wrong_with_what_it_is_asked() {
.await
.starts_with("no option --colour")
);
assert!(
fails(
&alice,
&["membership", "assign", "g", "m", "r", "--reason", "x"]
)
.await
.starts_with("no option --reason")
);
assert_eq!(
fails(&alice, &["create-group", "x", "--name"]).await,
"--name wants a value"
docs/design/moderation.md+4−1
@@ -41,7 +41,10 @@ resolved: labelling is the moderators acting, not someone asking them to.
`com.atproto.moderation.createReport` takes a report from anyone, member
or not, as their PDS sends it on: of a record in one of a group's spaces
here, into that group's queue. A report on a resolved subject opens it
again.
again. As anyone may write to a group's queue so, what a report
says is bounded: its subject a record's URI whose every part is what it
says, its reason 20,000 bytes at most (as the lexicon has it), and its
reason type 256.
## From the prototype
docs/design/moving.md+3−2
@@ -90,8 +90,9 @@ confirms it (an emailed code, on the reference PDS).
is what the PLC operation should name. Starting again, the one who
started discards what the first start copied; nobody else may.
3. **`completeImport`**, for whoever started: the signed operation sent
to the directory, once it gives the account to this host as step 2
said (this host its server, the keys made for it here, this host's
to the directory (unless it has it already, sent by the account's
server or by a try that failed after sending it), once it gives the
account to this host as step 2 said (this host its server, the keys made for it here, this host's
rotation key, and its handle); the account switched on, the relays
told who it is; and its group made, with its profile's name and
words, run by whoever moved it.
docs/design/recovery.md+6−0
@@ -23,6 +23,12 @@ The keys are the directory's to say: the host remembers only who added
which, to show. Once the host holds no key (a steward took the identity
elsewhere), it changes nothing.
Whoever configures the group may add a key, and take off any steward's,
not only one they added: the host asks the group's roles, not who holds
which key. A steward who must not be taken off by the group's other
admins keeps their key ranked above the host's, and so can undo, within
PLC's 72 hours, the operation that took it off.
Deleting a group ends its DID in the directory only if nobody but the
host could ever use it again. With a recovery key on it, the DID is its
steward's, to bring the group back elsewhere, and is left alone.
docs/reference/config.md+6−0
@@ -24,3 +24,9 @@ It stops on SIGTERM or ctrl-c, answering the requests under way first.
The console reads one: `GROUP_HOST`, the host it asks (default
`http://127.0.0.1:2600`).
The `opensocial` command reads its own: `OPENSOCIAL_AS` and
`OPENSOCIAL_PASSWORD` (who it signs in as), `PDS_URL` (where),
`OPENSOCIAL_HOST` and `OPENSOCIAL_HOST_DID` (the host it asks), and
`OPENSOCIAL_SEED_INVITE` (who `seed` invites): see
[the commands](cli.md#opensocial).
harness/e2e/flows.spec.mjs+2−0
web/src/lib/organisms/LabelForm.svelte+1−1
web/src/lib/actions.ts+16−2