chadtmiller.com/group-host
atmosphere group host
Methods' inputs and our own records are checked against their lexicons
MergedThis adds a lexicon validator to atproto, an XRPC middleware that checks every fyi.opensocial.* method's params and JSON input, and a record check on our own collections that apps write as a group. It replaces the hand-written checks and adds removeAvatar and removeBanner to updateProfile.
I found nothing that must change. In the files I read, the middleware reads the body once and hands it on, and it leaves wrong-method requests to the router. The handlers' .expect("its lexicon requires it") calls are only reached after the middleware has run. The record check runs after the token has allowed the write. The unpicture action now sends the remove* flag, and the handler gives it priority over a blob still present in the spread profile.
One thing to keep in mind: the expects turn into panics if a handler is ever mounted outside the layered router or its lexicon drops required. The test that holds FILES to the directory covers the first part of that.
I did not read these files:
crates/atproto/src/lexicon.rs- the interop and reference vector files
crates/atproto/tests/lexicon.rs- the rest of the per-handler deletions
- the test edits
My reasons: they are large, and the 246 reference vectors and the coverage gate check them. The author notes that the web check and e2e were not run, so the console's picture-clearing change is not exercised yet.
My earlier approval stands. Since the commit I reviewed (775a5eb), the head only gained two merges of main, which brought in the spaces, handles, deletes and invites pull. The pull's own changes are the same, and I found nothing new to ask for. I did not re-read the merged-in main changes, since they were reviewed on their own pull. The remaining caveat is the one the author lists: the web check and e2e were not run, so the console's picture-clearing change is still untested.
My earlier approval stands. Since a6b7f97 the head gained one merge of main. Its message says the ejection reason's hand-written length check was removed because the lexicon validator now covers it. The pull's own changes are the same, and I found nothing new to ask for. I did not re-read the merged-in main changes. The caveat the author lists remains: the web check and e2e were not run, so the console's picture-clearing change is still untested.
What changes
atproto::lexiconchecks a value against a def by its reference (nsid,nsid#name) over a set of lexicon documents: every field type,requiredandnullable, a string's length in UTF-8 bytes and in graphemes (withunicode-segmentation, a new dependency with none of its own), its format,constandenum, integer ranges, array lengths, a blob'sacceptandmaxSize, refs across documents, and open and closed unions by$type.knownValuesare not enforced. A failure says where and what:input.roles[2].role must not be longer than 64 bytes. It also reads a query string's values as their params' types.The host checks at the XRPC boundary, in one place. A middleware checks every
fyi.opensocial.*method's query parameters, and a procedure's JSON input, against the method's own lexicon before its handler runs, refusingInvalidRequestwith the path and message (andPayloadTooLargepast 2 MiB, as a handler'sJsonwould). The lexicons are read once, all of them, ingroup_host::lexicons; a test holds that list to the directory. A record of one of our ownfyi.opensocial.*collections that an app writes as a group (com.atproto.repo.*,com.atproto.space.*) is checked against its lexicon once the token is found to allow the write, and answeredvalidationStatus: "valid"; records of other collections stayunknown.Hand-written checks the lexicons now make are gone: the
at_mostlength checks the input-checks pull added (ingroup_config,group_spaces,group_join,group_invites,group_members,moderation, andgroup.rs's check of a new group), and the handlers'X is required,invitee is a DID,spaceType is an NSID, steward DIDs, a role's flags being booleans, a rule's order being 0 or more, and the profile's own language-tag check. Their tests stay, and now exercise the validator. The checks no schema can express stay: existing rule keys, defined roles, expiry to come (and a real date: the lexicon's datetime lets a 30 February through), a rule's URI in a space, a did:key that is a key, a CID the host keeps, a handle the host may take.An image is cleared by name.
updateProfiletooknullto clear an avatar or banner, which its lexicon could not say (goat refuses a field both nullable and optional); it gains optionalremoveAvatarandremoveBanner, and the console's settings send them.What the tests sent that their lexicons do not allow was fixed in the tests: a union member without its
$type,@before an actor, a rule record without itstext, a role record'snamefordisplayName, a profile without itsjoinPolicy, URIs that are none.Why
Each handler checked what it was sent by hand, and only as far as someone had thought to. The lexicons already say it all; one validator, checked against atproto's reference, says it the same way everywhere, MCP tools included (they call through the router).
The validator follows
@atproto/lexicon0.7.18, whose verdicts on lexicon.js's data, format and end-to-end cases, and 52 cases of this crate's own, are the vectors (crates/atproto/tests/reference/lexicon.json, fromlexicon.mjsbeside it: 246 vectors). It departs from the reference on 7 of them, each listed in the test and explained in the module: permissioned spaces' at-uris (3), which the reference does not know yet; a blob'sacceptandmaxSize(3), which it leaves unchecked; and a version 0 CID as acidstring (1), which atproto's interop vectors refuse. The formats follow the interop vectors (now also copied for at-uri, at-identifier, cid, datetime, language and uri) where the reference is laxer for old records' sake: a datetime always has its seconds and zone, a language tag's primary subtag is lower case, a uri is 8 KiB at most. DIDs, handles, NSIDs, TIDs and record keys reuseatproto::syntax.How it was checked
crates/atproto/tests/lexicon.rsruns every vector, the interop syntax files for each format, and the edges (paths, query strings, links, bytes, CIDs in base32 and base58).crates/group-host/tests/lexicons.rschecks the boundary itself: refusals before the handler, input that is not JSON, too large, a method asked the wrong way, one with no lexicon, and that every lexicon is held. Tokens' tests write a record of ours its lexicon refuses. The whole workspace passes under the coverage gate here, but for the tests that need the space alpha's PDS, which skip without it and are left to CI; clippy,just lexand the docs check pass.Shortcomings
🤖 Generated with Claude Code