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

A group publishes a website, served sandboxed at its handle

Merged
Merged chadtmiller.com asked to merge into main from chadtmiller.com/group-host:host/sites

What changes

A group has a website. fyi.opensocial.site, at self in the group's public repo, lists static files (each a path, a blob, and optionally a content type), with an optional fallback for single-page apps and notFound. The host serves it at the group's handle, https://<handle>/, keeping /.well-known/ there for itself: / and x/ serve the index.html under them, /x redirects to /x/ when it is a folder, then fallback for pages, then notFound. 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's SameSite=Lax session. Access-Control-Allow-Origin: * keeps its own scripts, fonts and fetches working from that origin; nosniff keeps each file to its type.

Publishing. fyi.opensocial.putSite takes every file inline, as text or bytes, keeps each as a blob of the group's (reusing one it holds), and replaces the record; deleteSite takes it down. Both need group.configure. They are the MCP tools site_publish and site_delete, and the commands opensocial site publish <group> <dir> [--fallback] [--not-found] (which reads a folder, leaving out dotfiles) and site delete. An app writing the record itself through com.atproto.repo.putRecord is held to the same rules: at self, by a member holding group.configure, every path valid and distinct, fallback and notFound naming files.

Refusals by name. putSite answers a site it would not serve (a bad or repeated path, a file giving both or neither of text and bytes, a fallback or notFound that is none of the files) as InvalidSite, 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 reads putSite's up to BLOB_UPLOAD_LIMIT, refusing more as PayloadTooLarge.

atproto::drisl::Value::into_bytes is new, beside into_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 without group.configure. crates/opensocial/tests/commands.rs publishes a folder and takes it down; it needs the reference PDS, so it is left to CI.

Shortcomings

  • No browser test yet that a site page posting to the console carries no session; the sandbox's effect on SameSite is the browsers' documented behaviour, not checked here. Safari and Firefox to be checked by hand once deployed.
  • The console shows nothing of a site yet: no link to it, no way to publish from it.
  • The console's cookie is not yet __Host-, and not every cookie-authenticated POST checks Origin: separate hardening, as the issue says.
  • A whole site goes in one body, at most BLOB_UPLOAD_LIMIT (50 MB by default).

Review

The design is in docs/design/sites.md; the code in crates/group-host/src/sites.rs.

🤖 Generated with Claude Code

Asked for changes

This 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");
review.knotless.dev

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(())
}
review.knotless.dev

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.

Asked for changes

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, a blob object whose ref.$link parses as a CID. Add a putRecord test for it.
  • Make site_file return an error or a 404 for an unparseable link instead of expecting.

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")));
}
}
review.knotless.dev

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");
review.knotless.dev

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));
review.knotless.dev

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.

Approved

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.

Merged as 5c724d7
Merging this pull closed these issues