Skip to content

org: websocket origin check, bots stay in scope, and the hosted limits written down - #2913

Merged
AbirAbbas merged 14 commits into
org/mainfrom
org/test-followups
Nov 25, 2026
Merged

AbirAbbas merged 14 commits into
org/mainfrom
org/test-followups

Conversation

@AbirAbbas

@AbirAbbas AbirAbbas commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-ups from the server-side test round of the hosted organization line. Based on #2912's branch (org/test-round), so its commits show in this diff until #2912 lands in org/main; this PR's own commits are the four on top, and I will merge org/main in when #2912 lands.

What changed

  1. Websocket upgrades refuse another site's Origin. The only upgrade the organization server accepts is the hosted chat wire (/v1/hosted/sessions/<id>/wire, owner path and guest path). It authenticates with a bearer header or the SameSite=Strict sign-in cookie, never a query token. The command line and the desktop app's engine (codeaf app, same dialer) send no Origin; the desk webview opens no websocket to the organization server (it goes through the engine). So any upgrade that carries an Origin other than the server's own (the host the request was sent to, or the host of its public address) now answers 403 This page is from another site, so it cannot open a chat connection here., before a credential is read. No Origin is accepted. There is no allowed-origins setting because no client needs one. The event streams are plain GETs whose answers another site's page cannot read (no CORS headers), so they are not upgrades and not changed.
  2. A bot narrowed below run cannot start a chat. POST /v1/hosted/sessions as a bot now asks what the bot would hold on the chat it would own (creator's verbs, narrowed by scope and by the policy's agent scope) and answers 403 This bot's scope does not let it run chats, so it cannot start one. Ask the person who made it. without minting or making anything.
  3. Doc errors from the round corrected (manual and README): the busy sentence (four is only the in-flight limit; a model with no price holds half the chat's limit per call), access also ending when the operator removes the person, what stop/delete/start clear in the shared areas, and the reap sweep.
  4. The v1 limits are written down in the operator README's Known limits, docs/organizations.md (trust model) and the manual: the port fence filters by port, not address (the metadata address, with guardrails), no per-chat disk or memory quota, a removal while the chats' machine is down, the seccomp dependency, and a front proxy and a priced model not tested end to end.
  5. One small addition from the advisor: at start the sessionhost connects to the metadata addresses (sends nothing) and logs one warning line naming any that answer. Document-only was the advisor's call for the address gap; this is its no-privilege add-on.

Validation contract

  • A cross-origin upgrade is refused with one plain sentence and the chats' host is never asked; the same origin passes; no Origin passes; a request that is not an upgrade is untouched.
  • A bot whose scope leaves run out (or whose policy scope does) is refused with the server's sentence and no chat is made; a bot with run within its scope still starts one, owned by its creator.
  • The operator is told, in one log line, which metadata addresses answer; no warning and no delay when none does.

Tests

upgrade_origin_test.go, hosted_bot_start_test.go, internal/sessionhost/metadata_test.go, six new probes in internal/manual/chat_test.go. Run with the fixes disabled, the origin and bot tests fail. TestHostedRowVerbsOfABotAreItsScope used a view bot to start the chat it then read; a view bot can no longer start one, so an edit bot starts it and the view bot's rows are read from it (same contract, new vehicle; found by CI on the first push).

Gates: make test-focus on internal/factory/serve, internal/sessionhost, internal/manual; make pr-ready BASE=origin/org/main once: light gate and the touched serve, manual, sessionhost legs passed locally, and its cmd/codeaf leg timed out at 15 minutes in three shards because the box was at load 15 from other lanes (no test failed). CI at the head: light gate, touched codeaf (17m), touched rest, windows native tests, check and the CLA all pass.

Open calls

In the PR comment.

🤖 Generated with Claude Code

AbirAbbas and others added 14 commits November 24, 2026 23:34
…cess

DELETE /v1/people/{handle}/sessions ended sign-ins and bots, but a hosted chat
holds a minted bearer of its own, valid for seven days. A removed person's chat
kept spending the organization's model key and reaching git as them, and their
stored provider keys and chats stayed behind.

Removal now ends those bearers first, in this process, then forgets the
person's sealed keys, then deletes their chats on the chats' host. A registry
row is forgotten only once the host confirms the delete (or answers that the
chat is not there); a host that is down never blocks the removal. The
revoke-link loop does the same for the people it removes.

Found by the hostile-client round (a bearer replayed after its owner was
removed still got a 200 from the model door).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…next attach

finishWire cancelled the finished connection before taking the lock that
removes it from the chat's group. For as long as it waited for that lock the
connection was "cancelled and still in the group", which reserveWire reads as
"the chat is being stopped", so a reconnect in that window got 503 "This chat
is unavailable right now." (a guest saw "The place chats run on is not
answering.").

The cancel now runs after the removal.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
/tmp, /dev/shm and /var/tmp are writable by every chat by design, and the reap
helper cleared only the chat's own folder. After the 24 hour quarantine a new
chat on the same Linux user found the old chat's files, FIFOs, shared memory,
message queues and semaphores, owned by "itself".

Every mode of the reap helper (clear on delete, tmp on stop, init on start) now
also removes, as the chat's own user and without following links, everything
that user owns in those three areas and every System V segment, semaphore set
and message queue it owns or created.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Rows of GET /v1/hosted/sessions carry `verbs` since 527bf1f, and the smoke
test still asserted the old key set. A shared row now asserts the verbs
['view'], the operator's metadata-only row asserts none.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… to everyone

When the operator removed a person while the chats' host was down, the person's
chats were not listed, so their registry rows and shares stayed, and a guest
holding edit could still attach and wake one. Waking a chat mints a fresh model
bearer for its owner, which is the access the removal had just ended.

Every chat the registry still holds for a removed person now has its shares
ended and is made private, so every door answers "There is no such chat." The
row stays, so the chat is still tracked and removing the person again once the
host answers deletes it. The host calls also stop after the first transport
error, so a hung host does not make a removal wait once per chat.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… leftovers are cleared

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A WebSocket is exempt from the browser's same-origin policy, so a hostile page
could open the hosted chat wire as a person whose sign-in cookie the browser
sends. The cookie is SameSite=Strict, which does not cover a page on a sibling
name of the same site. Any request that upgrades the connection and carries an
Origin other than this server's own (the host it was sent to, or the host of its
public address) now answers 403 with one plain sentence, before a credential is
read. No Origin is accepted: the command line and the desktop app's engine send
none, and no client needs an allowed list.

Two existing tests sent a foreign Origin only as a stand-in for hostile
headers; they now send the server's own.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A bot narrowed to view could still POST /v1/hosted/sessions and make a chat it
could only watch. Starting a chat now asks what the bot would hold on the chat it
would own (its creator's verbs narrowed by its scope and the policy's agent
scope) and refuses a bot without run, before anything is minted or made.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ta address

The port fence cannot stop a chat reaching 169.254.169.254:80, so the operator is
told. At start the supervisor connects (and sends nothing) to the AWS, Google and
Azure metadata address, AWS's task-credentials address and AWS's IPv6 metadata
address, in the background, and logs one warning line naming any that answer.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…e test round corrected

Corrects the busy sentence (four calls in flight is the limit for a priced model;
a model with no price holds half the limit per call), the end of a chat's access
on removal of the person, what stop, delete and start clear in the shared areas,
and the reap sweep. Writes the v1 limits down in the operator README, the trust
model and the manual: the port fence filters by port and not address (with
guardrails for the metadata address), no per-chat disk or memory quota, a removal
while the chats' machine is down, the seccomp dependency, and the paths not
tested end to end (a front proxy, a priced model). Documents the websocket origin
check and the run requirement for a bot starting a chat.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
TestHostedRowVerbsOfABotAreItsScope used a view bot to start the chat whose row
verbs it then checked. A view bot can no longer start a chat (it needs run), so
the chat is started by an edit bot, whose own answer must be its scope alone (run
and what rides with it, never share or manage), and the view bot's rows are read
from it as before. The contract (a bot's rows hold what its person holds,
narrowed by its scope) is unchanged.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@AbirAbbas

Copy link
Copy Markdown
Collaborator Author

Open calls for the owner:

  1. Egress proxy door. The advisor's call: documenting the address gap (with guardrails) is defensible for v1 self-host, no Landlock or seccomp trick closes it, and the real follow-up is an egress proxy door on the org server (refuses private, link-local, loopback and ULA addresses at dial time; the fence then allows only the door's ports and chats get HTTPS_PROXY; ssh and 9418 git would need a ProxyCommand or be dropped). It becomes a v1 blocker if customers invite semi-trusted people. Not built here.
  2. Metadata guardrails and the startup warning are untested on a real cloud VM. One EC2 or GCE run (curl -m 2 from inside a chat, before and after the documented firewall rule) would settle both. Railway's docs say nothing about the metadata address either way.
  3. No allowed-origins setting for the websocket check; no client needs one. A future browser client has to be served from the server's own origin, or a setting added.
  4. Removal while the chats' machine is down still needs the operator to remove the person again; no retry loop (round open call 1).
  5. Round open calls 5, 9 and 10 (no audit row for refused frames, the unlogged 503, monthly-limit overshoot by one call per active chat) are untouched.

@AbirAbbas
AbirAbbas merged commit 0207f82 into org/main Nov 25, 2026
23 checks passed
@AbirAbbas
AbirAbbas deleted the org/test-followups branch November 25, 2026 07:15
AbirAbbas added a commit that referenced this pull request Nov 25, 2026
…ack (#2903)

The hosted organisation line: a team-mode org server deciding every request through one access model (verbs, roles, grants and policy in SQLite), hosted chats run by the sessionhost under a per-chat uid inside a Landlock fence with minted model bearers, sealed keys and a git helper, shared chats acting through verbs, bots owned by their creator, the Hosting and chats policy settings, and a self-hosting stack (deploy/org Docker Compose, published images behind a leak gate, a Railway path).

Consolidates #2894 #2895 #2896 #2898 #2899 #2900 and the follow-ups #2904 #2905 #2907 #2908 #2910 #2911 #2912 #2913 #2915 #2916 #2918 #2927 #2936 #2944. Proven by the full suite, a keyless Compose smoke, a hostile wire client, sandbox escape probes, a real-model run and a production-style install from the published images.

Co-Authored-By: Santosh kumar <29346072+santoshkumarradha@users.noreply.github.com>
Co-Authored-By: ZeroPoint95 <329227198+ZeroPoint95@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant