Skip to content

[AI-3959] A temporary allowlist lets one exact device identity through the identity refusal - #2502

Closed
kanat wants to merge 5 commits into
mainfrom
ai-3959-device-identity-allow
Closed

kanat wants to merge 5 commits into
mainfrom
ai-3959-device-identity-allow

Conversation

@kanat

@kanat kanat commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Why

The router prod release carries #2393, which refuses a browser client that sends agent_id, user_id or user_name (refuseDeviceAgentIdentity). A docs chat widget still sends them until GetStream/getstream.io#1264 is live on the prod site, so releasing now brings back its 403s (AI-3893).

This is a temporary and narrow exception: one env setting, set by an operator, that names the exact identity a device of one app may send. It is for text sessions only, and the sessions it lets through are not reached by Chat hooks. It is removed once getstream.io#1264 is live; AI-3900 (#2490) is the lasting fix. Unset or empty: no change.

How it works

ROUTER_DEVICE_IDENTITY_ALLOW="app|agent_id|user_id|user_name;app2|..."
        │ parsed once at start (bad value: the router refuses to start, naming the setting)
        ▼
 cmd/router -> Options.DeviceIdentityAllow -> Server.deviceIdentities
        │
        ├─ POST /v1/agents/sessions ── refuseSessionRequest(list)
        │                                 └─> refuseDeviceAgentIdentity
        │                     server-side caller ........... pass (as before)
        │                     an entry of the caller's app, text session
        │                     (no start_voice), not incognito, every
        │                     identity field sent equals the entry .. pass, session marked
        │                                                          Spec.ListedIdentity
        │                     anything else ................ the #2393 403s, unchanged
        │
        └─ socket start frame (always voice) ── refuseSessionRequest(nil): the #2393 403s, unchanged

 Spec.ListedIdentity: every device of the app may hold the listed agent_id, so the session is
 left out of every lookup by agent id:
   Manager.ByAgentWhere ........ skips it (liveSessionOn: retire, the kept-conversation settle)
   Directory.Hold .............. claims no agent for it (NodeByAgent / NodesByAgent forwarding)
 A message in agent:<listed id> is answered as though the session did not run; the session keeps
 its conversation on a channel of its own.

app is the Stream app id (what the gateway sends as X-Stream-App-Id and the dashboard shows). An empty user_id or user_name in an entry means the device may not send that field. The default user_id / user_name and a verified caller's own user id stay allowed as before. The router logs the number of entries at start, never the values.

Tests

Change Test that fails without it
Entries parse (trimmed, also after a ;); bad shapes refuse start without echoing the value TestDeviceIdentityAllowReadsEachEntryExactly
Passes only for the entry's app, exact fields, not incognito, not start_voice; every other case still refused TestAnAllowedIdentityPassesOnlyForItsAppAndEveryFieldExactly
createSession lets the listed identity open a text session (device, guest, anonymous); the socket start frame still refuses it SocketSessionSuite/TestADeviceMayHandOverAnIdentityTheOperatorListedForItsApp
One differing field, another app, incognito, start_voice: 403 on both paths, same errors SocketSessionSuite/TestAnIdentityNotListedForTheDeviceIsStillRefused
Options.DeviceIdentityAllow reaches the server SocketSessionSuite/TestARouterStartedWithTheListLetsTheDeviceThrough
Another user's message in agent:<listed id> does not retire the listed session ChatEpisodesSuite/TestAMessageInTheListedAgentsChannelLeavesADevicesSessionAlone
... and is handed out, not settled by the listed session ChatEpisodesSuite/TestAMessageInTheListedAgentsChannelIsHandedOutWhileADevicesSessionRuns
The listed session claims no agent in the directory; a backend's session under the same id still does ChatEpisodesSuite/TestADevicesSessionWithTheListedAgentIDClaimsNoAgentInTheDirectory
A bad value stops run naming the setting, not the value ChatInboundStartupSuite/TestADeviceIdentityAllowThatDoesNotReadStopsTheRouter
run logs the entry count, no values, and passes the list to the server ChatInboundStartupSuite/TestTheDeviceIdentityAllowIsLoggedByCountAndServed
Setting empty: the three #2393 refusals, unchanged (expected values probed on base e75990b7b) SocketSessionSuite/TestWithoutTheSettingADeviceIsRefusedAsBefore
Setting is one string (a name may hold a comma), empty by default ConfigSuite/TestTheDeviceIdentityAllowIsOneStringAndNothingByDefault

No API, spec, migration or SDK change. Documented in acceleration/README.md next to the other ROUTER_* settings, marked TEMPORARY.

Removal

Delete acceleration/internal/api/device_identity_allow.go, its tests, the allow parameter of refuseSessionRequest and refuseDeviceAgentIdentity, Spec.ListedIdentity and its two uses in internal/session/manager.go, the config key, the README row and the cmd/router lines, once getstream.io#1264 is live on the prod site.

🤖 Generated with Claude Code

… the identity refusal

ROUTER_DEVICE_IDENTITY_ALLOW lists entries app|agent_id|user_id|user_name. A device
of that app passes the identity refusal of createSession and the socket start frame
only when its session keeps its conversation and every identity field it sends
equals the entry's. Unset, nothing changes. Remove it once getstream.io#1264 is live.

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

@kanat kanat left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: NO-GO

[security R1] head 5825f76 (on current main).

  • [Blocker] S1.1 device_identity_allow.go:69: the allowance puts one shared agent id on many devices' sessions, and code that looks a running session up by agent id can then act on another user's session. Details and the attack test are in the private ticket. Fix: keep sessions admitted through the list out of lookups by agent id (they keep their conversation in a channel of their own), or an explicit, recorded risk acceptance for this temporary flag.
  • [Nit] S1.2 device_identity_allow.go:59: the exception also covers voice sessions; the intended use is a text widget.

Checked and fine: which app a request is of comes from the API key and its token (api_key mode) or the gateway's header (proxy mode), and a direct-port caller is already a backend on base, so the list adds nothing there; each sent field must equal one entry, byte for byte, else the #2393 errors; fields of two entries are refused; incognito is refused; reserved ids and the other device-refused fields are still refused; two devices with the listed identity cannot read, list or carry on each other's sessions (probed for signed-in, guest and anonymous); the error and the start log never carry the value; no migration, and an older build ignores the setting (fails closed). Mutations: 8 of the new guards checked, 0 survived. PostureSuite, SessionOwnershipSuite, auth and config pass.

agent, user, name := value(request.AgentId), value(request.UserId), value(request.UserName)
if (agent == "" || agent == entry.AgentID) &&
(user == "" || user == session.DefaultUserID || namesOwnUser(ctx, user) || user == entry.UserID) &&
(name == "" || name == session.DefaultUserName || name == entry.UserName) {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Blocker] S1.1 Every device of the listed app may now hold the same agent id on a session that keeps its conversation. Lookups that find a running session by agent id then reach whichever of those sessions is newest, whoever opened it, which lets one user's activity act on another user's session. On base a device cannot pick this id (403). Fix: mark a session whose identity this list let through and leave it out of lookups by agent id, since its conversation lives in its own channel; add a test that another user's activity leaves the first session untouched. The ready test is in the private ticket.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 32ab8de: a session the list let through is marked Spec.ListedIdentity (set in createSession from the refusal without the list, never by a request); Manager.ByAgentWhere skips it and Directory.Hold claims no agent for it. Tests: ChatEpisodesSuite/TestAMessageInTheListedAgentsChannelLeavesADevicesSessionAlone, .../TestAMessageInTheListedAgentsChannelIsHandedOutWhileADevicesSessionRuns, .../TestADevicesSessionWithTheListedAgentIDClaimsNoAgentInTheDirectory (all three fail on 5825f76).

// request sends that refuseDeviceAgentIdentity would refuse equals the entry's.
func (a DeviceIdentityAllow) lets(ctx context.Context, request CreateSessionRequest) bool {
app, _ := CustomerFrom(ctx)
if value(request.Incognito) {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Nit] S1.2 This also lets the identity through for a voice session (start_voice): the agent then joins the device's call as the listed user_id. That is the identity the operator listed, but the intended use is a text widget. Suggest if value(request.Incognito) || value(request.StartVoice) { return false } plus a unit case, or say in the README row that voice is included.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in d9463f4: text only. lets refuses start_voice, and the socket start frame (always voice) passes no list, so it refuses as before. Tests: TestAnAllowedIdentityPassesOnlyForItsAppAndEveryFieldExactly/start_voice, SocketSessionSuite/TestAnIdentityNotListedForTheDeviceIsStillRefused/start_voice/*, SocketSessionSuite/TestADeviceMayHandOverAnIdentityTheOperatorListedForItsApp (socket refused).

@kanat kanat left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: NO-GO

Reviewed 5825f76 (current main 51578aa is its parent). Two Should fix items, both test gaps with ready test rows; the code itself reads right.

Checked and sound:

  • Unset or empty setting: head equals base. A differential probe ran base's refuseDeviceAgentIdentity against head with a nil and an empty list over 82,320 combinations (server-side, kind, caller, app, agent/user/name values, incognito). Every result was equal. The #2393 tests (unit, SocketSessionSuite, SlackChannelSuite) only gained the nil argument, and they pass on head for both HTTP and the socket.
  • app is principal.AppID: the gateway's X-Stream-App-Id in proxy mode, the key's app in api_key mode. A caller on a direct router port could also send Stream-Auth-Type: server and skip the refusal entirely, so the list adds no new way in.
  • All three call sites pass the list (createSession, the socket start frame, the inner refuseDeviceAgentIdentity). Mutants of each are killed.
  • I ran run() with the setting in proxy mode. The listed app passed the identity refusal. Another app got the #2393 403. The log said entries=1 and held no values.
  • Unit and integration suites (SocketSessionSuite, SlackChannelSuite) pass. The new socket tests pass under -race. Generated files match their source. CI: draft, so go and integration are skipped and run at ready.

Mutations: 29 checked, 5 survived (R1.1: 4, R1.2: 1).

[Question] R1.3 (ticket, not blocking): voice passes too. The socket start frame is always voice (socketws.go:178), and createSession with start_voice is not excluded either. This matches the ticket, which asks for the socket alike. The agent's Stream token is minted on the router and is not returned to the device. If the docs widget is text-only, narrowing the exception to text sessions is Kanat's decision.


// TEMPORARY (AI-3959): a value that does not read is refused at start rather than ignored,
// since ignoring it would bring the refusal back for the device it was set for.
deviceIdentityAllow, err := api.ParseDeviceIdentityAllow(settings.DeviceIdentityAllow)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Should fix] R1.1 No test covers the start-time refusal, the count-only Warn log or the DeviceIdentityAllow: deviceIdentityAllow wiring (line 1568). These four mutants all survive go test ./cmd/router ./internal/api ./internal/config:

  • ignore the parse error;
  • drop the log;
  • log the values;
  • pass nil to Options.

run() needs no database: ChatInboundStartupSuite (cmd/router/chatinbound_test.go) already starts it that way. Add two tests there:

  1. Setting x-secret|x-secret: run returns an error that contains ROUTER_DEVICE_IDENTITY_ALLOW and not x-secret.
  2. Proxy mode, setting app-9|agent-secret|user-secret|Name Secret, a text logger:
    • The log has entries=1 and none of the three values.
    • POST /v1/agents/sessions with X-Stream-App-Id: app-9, Stream-Auth-Type: anonymous and the three fields is not the agent_id is sent server-side 403. On head it is a later 400 not_configured.
    • The same request for app-8 is the 403.

I checked that both tests pass on head and that each mutant fails one of them.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 3de09a1: ChatInboundStartupSuite/TestADeviceIdentityAllowThatDoesNotReadStopsTheRouter (kills M24) and ChatInboundStartupSuite/TestTheDeviceIdentityAllowIsLoggedByCountAndServed (kills M25, M26, M27).

}
var allow DeviceIdentityAllow
for i, entry := range strings.Split(setting, ";") {
fields := strings.Split(strings.TrimSpace(entry), "|")

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Should fix] R1.2 No test pins the per-entry strings.TrimSpace(entry): the mutant strings.Split(entry, "|") survives. An operator value with a space or a newline after ; would then read the app as " app-2". That entry never matches, and the widget's 403s come back. Add this row to the good map of TestDeviceIdentityAllowReadsEachEntryExactly:

"space after a separator": {"app-1|a|u|n;\n app-2|b|v|m", DeviceIdentityAllow{{"app-1", "a", "u", "n"}, {"app-2", "b", "v", "m"}}},

It passes on head and fails under the mutant.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in a37a250: TestDeviceIdentityAllowReadsEachEntryExactly/space_after_a_separator (fails under M12).

kanat and others added 4 commits November 25, 2026 18:19
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kanat

kanat commented Nov 26, 2026

Copy link
Copy Markdown
Collaborator Author

Closing: this temporary allowlist was only needed until getstream.io#1264 reached the prod site. It is live since 2026-11-25 23:59 UTC, and the docs widget no longer sends agent_id, user_id or user_name. The lasting fix is #2490 (AI-3900).

@kanat kanat closed this Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant