Repository navigation
[CHA-7277, CHA-7274] fix(api): reserved user ids and thread-shaped device session ids (behind switches) - #2460
Merged
Merged
Conversation
…vice session ids, behind switches CHA-7277: a backend acting for a user id Stream reserves (!) is refused on session create, the socket, fork, resume, run, task and connection create, and a voice session's call.id that would become the agent id is refused, behind ROUTER_SECURITY_CHA7277_RESERVED_USER_IDS. A reserved guest id is taken as naming no guest. CHA-7274: a device's session id shaped like a thread channel's is answered as taken whether or not the thread exists, behind ROUTER_SECURITY_CHA7274_DEVICE_THREAD_SESSION_IDS. Both switches are off by default and count every request they apply to in router_security_would_change_total (internal/transitional). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…kend acting for a user is no device Review fixes: a device's thread-shaped session id is counted only when no thread has it, endUserKind leaves out a backend acting for a user, and the acting-for check on tasks and connections runs after the customer is known. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Two follow-ups from the reviews of #2395 (CHA-6986) and #2393 (CHA-6998).
CHA-7277: reserved (
!) user ids are still accepted in three places. Stream reserves user ids starting with!. #2395 refused them in request bodies, but three places still take them:X-Stream-User-Idor?user_id=becomesCaller.UserID. The router stores it as the owner of sessions, tasks and connections, and upserts it as a Chat user when a conversation opens. The Chat proxy refuses such an id (CHA-6973), but the router has no check of its own.POST /v1/agents/guestsbodyid.call.id. When the session names noagent_id, the call id becomes the agent id (Spec.KeyedAgentID), which gets past [CHA-6986] fix(api): refuse user ids Stream reserves (!) where a request names one #2395'sagent_idcheck.CHA-7274: a device can probe for thread channels. A device's session
idof the formthread-<uuid>answered 409 when a thread channel had that id, and opened a session when none did. So the answer said whether the thread exists, against the invariantthread_access_test.goprotects.Changes
transitionalpackage (new).transitional.Switchships a security change that a legitimate caller could feel, switched OFF. Unset, it keeps the old behaviour exactly. The env var takestruefor every app, or a comma-separated list of app ids. Every request the change applies to is counted inrouter_security_would_change_total{switch,app_id,outcome}and logged, whether the switch is on or off. It is the router's equivalent of chat'schat.security.*Release flags (CHA-7311). The same file is in [CHA-7261] fix(agent): a device's own tool is no source of a transfer number (behind a switch) #2458 (CHA-7261), so whichever lands second merges cleanly.ROUTER_SECURITY_CHA7277_RESERVED_USER_IDS(security.cha7277.reserved_user_ids):refuseReservedActingForanswers 400 to a backend acting for a reserved id on these writes: session create, the socket start frame (both viarefuseSessionRequest), fork, resume, run, scheduled-task create and connection create. Reads and deletes stay open, so what is already kept under such an id stays readable and erasable.call.idthat would become the agent id is refused the same way.id, no switch. A reservedidonPOST /v1/agents/guestsis taken as naming no guest, and a new guest is minted. No guest ever has such an id, so nobody is refused anything new.ROUTER_SECURITY_CHA7274_DEVICE_THREAD_SESSION_IDS(session.ThreadSessionIDsSwitch). InManager.Create, when an end user's device names a session id shaped like a thread channel's (thread-plus a UUID, case-folded), the id is answered as taken. The answer is the same for an existing thread and an unknown one, on REST and on the socket. Otherthread-…ids still open. The backend is unchanged.Validation
Every new test with the switch on fails on main and passes here:
TestABackendActingForAReservedUserIdOpensNoSessionandTestABackendsCallIdThatWouldBecomeAReservedAgentIdIsRefused.TestWithTheSwitchOff…IsLetThroughchecks the old answer is kept.ReservedActingForSuite: create, fork, resume, scheduled task and connection are refused. Listing still works. An app the switch isn't on for is let through.GuestsSuite:TestAReservedIDIsTakenAsNamingNoGuest.SlackChannelSuite: a device's session id on an existing thread versus an unknownthread-<uuid>gets the same reply, on create (including upper case) and on the socket. Athread-id that isn't a UUID still opens. With the switch off, an unknown thread id opens as before. A backend's unknown thread id opens.transitional: off by default, on via env, on for listed apps, and forced on for a test's app.ConnectionsSuiteandScheduledTasksSuite.Ticket
CHA-7277, CHA-7274 (Security · Chat API authorization & visibility audit)
Notes for review
user_id=!…, and zero requests on a/v1/agents/sessions/thread-…path. Bodies aren't logged, so the guestid,call.idand the session id on create can't be counted directly. The switch's counter covers that.recordUser/recordEmailstill record a users row for a reserved acting-for id on reads. Filed as CHA-7323.threadConversation's device branches, on the agent-id route, are left as defence in depth.endUserKindleaves out a backend acting for a user (Caller.ServerSide).app_id.idfrom the backend now gets a new guest (200) instead of the old 400 "not a guest of this app". No guest can have such an id.session_create.goandsessions.gotoo, but different hunks.🤖 Generated with Claude Code