chadtmiller.com/group-host
atmosphere group host
A group publishes a website, served sandboxed at its handle
MergedThis pull adds group websites. A fyi.opensocial.site record is served sandboxed at the group's handle, and putSite / deleteSite publish and remove it, with matching MCP tools and CLI commands. The sandbox design looks sound. The CSP sandbox header goes on every answer, the /.well-known/ paths are left alone, and the folder redirect can only target a path whose file exists, so it can't be an open redirect.
Must fix: a record written through putRecord can crash the serve path. check() validates paths, duplicates, and fallback / notFound, but not that each file has a well-formed blob. site_file then does Cid::parse(link).expect("a blob the host checked as it kept the site"). That holds for putSite, but not for the com.atproto.repo.putRecord path the PR says is held to the same rules. A member with group.configure can put {"files":[{"path":"index.html"}]}, or a file whose blob isn't a blob. The record is accepted, and every later request to the group's handle then panics. Make check() require, for each file, a blob object whose ref.$link parses as a CID. Also make site_file return an error or a 404 instead of expecting. Add a test for the putRecord case.
Check failing (not blocking on its own): the test workflow fails in group-host-mcp/tests/protocol.rs, names_each_tool_for_its_command. The expected tool list there doesn't include site_publish / site_delete, so update it.
Minor: the 301 Location is built from the decoded path without re-encoding. A file named with ? or # redirects to the wrong URL.
I read the Rust source for the host (sites.rs, and the wiring in lib.rs and token_writes.rs) and its tests (tests/sites.rs). I did not read the remaining files in the diff: the MCP and CLI changes, the lexicons, the docs, and the drisl helper.
crates/group-host/src/sites.rsline 205Outdated
return Ok(None); | |
}; | |
let link = file["blob"]["ref"]["$link"].as_str().unwrap_or_default(); | |
let cid = atproto::Cid::parse(link).expect("a blob the host checked as it kept the site"); |
This expect is reachable. A site record written with putRecord and a file lacking a valid blob.ref.$link passes check(), then panics here on every request to the handle. Validate the blob ref in check() and return an error here rather than panicking.
crates/group-host/src/sites.rslines 58 to 80Outdated
let path = file["path"].as_str().unwrap_or_default(); | |
if !is_path(path) { | |
return Err(invalid(format!( | |
"{path:?} is not a path a site's file may be at" | |
))); | |
} | |
if !paths.insert(path) { | |
return Err(invalid(format!("{path} is given more than once"))); | |
} | |
} | |
for key in ["fallback", "notFound"] { | |
let named = site[key].as_str(); | |
if let Some(path) = named.filter(|p| !paths.contains(p)) { | |
return Err(invalid(format!( | |
"{key} is {path}, which is none of the files" | |
))); | |
} | |
} | |
Ok(()) | |
} |
check() should also require each file's blob to be a blob object with a parseable CID link, since site_write relies on it for records an app writes itself.
The test check now passes, but the must-fix from round 1 is not done. In sites.rs at this head, check() still doesn't validate blob. site_file still does Cid::parse(link).expect(...). A member with group.configure can write {"files":[{"path":"index.html"}]} through com.atproto.repo.putRecord. site_write only calls check(), so the record is accepted. Every later request to that group's handle for that path then panics. The expect message says the host checked the blob as it kept the site, which is only true for putSite.
Please do two things:
- Make
check()require, for each file, ablobobject whoseref.$linkparses as a CID. Add aputRecordtest for it. - Make
site_filereturn an error or a 404 for an unparseable link instead ofexpecting.
Still open, minor: the 301 Location is built from the decoded path with no re-encoding, so a file named with ?, # or % redirects to the wrong URL.
I read only sites.rs this round, not the rest of the diff.
crates/group-host/src/sites.rsline 76Outdated
if !paths.insert(path) { | |
return Err(refused(format!("{path} is given more than once"))); | |
} | |
} |
Also require each file's blob to be a blob object whose ref.$link parses as a CID. Without that, a putRecord write can store a file with no valid blob.
crates/group-host/src/sites.rsline 211Outdated
return Ok(None); | |
}; | |
let link = file["blob"]["ref"]["$link"].as_str().unwrap_or_default(); | |
let cid = atproto::Cid::parse(link).expect("a blob the host checked as it kept the site"); |
This expect panics on any record written via putRecord with a missing or malformed blob. Return an error or a 404 here, and have check() reject such records.
crates/group-host/src/sites.rsline 247Outdated
.site_file(did, &site, &format!("{path}/index.html"))? | |
.is_some() | |
{ | |
return Ok(moved(&format!("/{path}/"), StatusCode::MOVED_PERMANENTLY)); |
path is decoded here and not re-encoded, so a file name containing ?, # or % gives a wrong Location. Percent-encode it.
Fixed in 85da452. check() now refuses a file whose blob is not a blob with a CID link (InvalidSite), with putRecord tests for a missing and a malformed blob. site_file no longer expects: a file naming no blob is served as missing, which also covers a site record copied in a move or import, never checked here (test: a_site_copied_from_elsewhere_with_no_blob_serves_nothing_there). The folder redirect's Location is percent-encoded (/why%3F redirects to /why%3F/). The tool-list test was fixed in 8f6054b.
The must-fix is done. check() now requires each file to have a blob object with $type: "blob" and a ref.$link that parses as a CID, and refuses the site as InvalidSite ("names no blob") otherwise. The Cid::parse(...).expect(...) is gone from the serve path, and the design doc says a file with no blob is served as if it weren't there. A record written through putRecord can no longer crash requests to the group's handle.
I only searched sites.rs this round, so I did not confirm the putRecord test I asked for, or whether the redirect Location is now percent-encoded. I'm approving on the crash being fixed, and please check those two yourself. If a file named with ?, # or % still redirects to the wrong URL, that is a minor bug to fix separately.
What changes
A group has a website.
fyi.opensocial.site, atselfin the group's public repo, lists static files (each a path, a blob, and optionally a content type), with an optionalfallbackfor single-page apps andnotFound. The host serves it at the group's handle,https://<handle>/, keeping/.well-known/there for itself:/andx/serve theindex.htmlunder them,/xredirects to/x/when it is a folder, thenfallbackfor pages, thennotFound. GET and HEAD only; ETag by CID,max-age=60. A group with no site redirects/to its console page.Sandboxed by how it is served. A handle is a name under the host's domain, so a browser counts every site as the same site as the console. Every answer for a site carries
Content-Security-Policy: sandbox allow-scripts allow-forms allow-popups allow-popups-to-escape-sandbox, giving each page an opaque origin: no cookies or storage, and its requests to the host go cross-site, without the console'sSameSite=Laxsession.Access-Control-Allow-Origin: *keeps its own scripts, fonts and fetches working from that origin;nosniffkeeps each file to its type.Publishing.
fyi.opensocial.putSitetakes every file inline, as text or bytes, keeps each as a blob of the group's (reusing one it holds), and replaces the record;deleteSitetakes it down. Both needgroup.configure. They are the MCP toolssite_publishandsite_delete, and the commandsopensocial site publish <group> <dir> [--fallback] [--not-found](which reads a folder, leaving out dotfiles) andsite delete. An app writing the record itself throughcom.atproto.repo.putRecordis held to the same rules: atself, by a member holdinggroup.configure, every path valid and distinct,fallbackandnotFoundnaming files.Refusals by name.
putSiteanswers a site it would not serve (a bad or repeated path, a file giving both or neither oftextandbytes, afallbackornotFoundthat is none of the files) asInvalidSite, listed in its lexicon; the token path answers the same. AGENTS.md now says a method's lexicon lists each error it answers by name beyond the ones any method may.A site's input is as large as an upload. The lexicons' check read every
fyi.opensocial.*input up to 2 MiB before its handler; it now readsputSite's up toBLOB_UPLOAD_LIMIT, refusing more asPayloadTooLarge.atproto::drisl::Value::into_bytesis new, besideinto_map.Why
Groups want at least a page saying who they are, which an AI connected over MCP can write. Fixes at://did:plc:bcgltzqazw5tb6k2g3ttenbj/space/dev.knotless.space/group-host/did:plc:bcgltzqazw5tb6k2g3ttenbj/dev.knotless.issue/3mzlhxmmtidqn
Static files over templates or server rendering: nothing runs on the host, and a page wanting live data asks the host's public methods. Served at the handle rather than on a separate domain, so a group's address is its site with no new domain, certificate or Public Suffix List wait; the sandbox header, not checks at publish time, is what keeps a page from acting as a signed-in member, since anyone with the role can write the record from any app.
How it was checked
crates/group-host/tests/sites.rs: publishing and serving (types by extension and as given, index, folder redirect, percent-decoding, fallback and notFound, 304, HEAD, 405), every answer's sandbox headers, the host's own name and/.well-known/untouched, blobs reused on republish, no site and a switched-off group, who may publish, refused sites, take-down, and the token path with and withoutgroup.configure.crates/opensocial/tests/commands.rspublishes a folder and takes it down; it needs the reference PDS, so it is left to CI.Shortcomings
SameSiteis the browsers' documented behaviour, not checked here. Safari and Firefox to be checked by hand once deployed.__Host-, and not every cookie-authenticated POST checksOrigin: separate hardening, as the issue says.BLOB_UPLOAD_LIMIT(50 MB by default).Review
The design is in
docs/design/sites.md; the code incrates/group-host/src/sites.rs.🤖 Generated with Claude Code