Skip to content

[CHA-7277, CHA-7274] fix(api): reserved user ids and thread-shaped device session ids (behind switches) - #2460

Merged
Loschcode merged 2 commits into
mainfrom
fix/cha-7277-7274-router-ids
Nov 25, 2026
Merged

Loschcode merged 2 commits into
mainfrom
fix/cha-7277-7274-router-ids

Conversation

@Loschcode

@Loschcode Loschcode commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • The acting-for id. A backend's X-Stream-User-Id or ?user_id= becomes Caller.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.
  • The POST /v1/agents/guests body id.
  • A voice session's call.id. When the session names no agent_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's agent_id check.

CHA-7274: a device can probe for thread channels. A device's session id of the form thread-<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 invariant thread_access_test.go protects.

Changes

  • transitional package (new). transitional.Switch ships a security change that a legitimate caller could feel, switched OFF. Unset, it keeps the old behaviour exactly. The env var takes true for every app, or a comma-separated list of app ids. Every request the change applies to is counted in router_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's chat.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.
  • CHA-7277, behind ROUTER_SECURITY_CHA7277_RESERVED_USER_IDS (security.cha7277.reserved_user_ids):
    • refuseReservedActingFor answers 400 to a backend acting for a reserved id on these writes: session create, the socket start frame (both via refuseSessionRequest), 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.
    • A call.id that would become the agent id is refused the same way.
  • CHA-7277, guest id, no switch. A reserved id on POST /v1/agents/guests is taken as naming no guest, and a new guest is minted. No guest ever has such an id, so nobody is refused anything new.
  • CHA-7274, behind ROUTER_SECURITY_CHA7274_DEVICE_THREAD_SESSION_IDS (session.ThreadSessionIDsSwitch). In Manager.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. Other thread-… ids still open. The backend is unchanged.

Validation

Every new test with the switch on fails on main and passes here:

  • Unit: TestABackendActingForAReservedUserIdOpensNoSession and TestABackendsCallIdThatWouldBecomeAReservedAgentIdIsRefused. TestWithTheSwitchOff…IsLetThrough checks 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 unknown thread-<uuid> gets the same reply, on create (including upper case) and on the socket. A thread- 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.
  • Also run locally: ConnectionsSuite and ScheduledTasksSuite.

Ticket

CHA-7277, CHA-7274 (Security · Chat API authorization & visibility audit)

Notes for review

  • Prod traffic in router logs (GCP, every acceleration cluster, last 30 days): zero requests with user_id=!…, and zero requests on a /v1/agents/sessions/thread-… path. Bodies aren't logged, so the guest id, call.id and the session id on create can't be counted directly. The switch's counter covers that.
  • Kept out of scope:
    • recordUser / recordEmail still 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.
  • Fable review fixes (second round).
    • The thread switch counts a device's thread-shaped id only when no thread has it, since that is the only case where the answer changes.
    • endUserKind leaves out a backend acting for a user (Caller.ServerSide).
    • The acting-for check on tasks and connections runs after the customer is known, so the counter never gets an empty app_id.
    • A reserved guest id from 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.
  • Overlap with fix(api): a device can't set a new session's phone line, models, limits, greeting or tags #2366. It touches session_create.go and sessions.go too, but different hunks.

🤖 Generated with Claude Code

Laurent Schaffner and others added 2 commits November 25, 2026 14:41
…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>
@Loschcode
Loschcode merged commit b74fa4a into main Nov 25, 2026
13 checks passed
@Loschcode
Loschcode deleted the fix/cha-7277-7274-router-ids branch November 25, 2026 14:08
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