Repository navigation
[AI-3412] Refuse a userId on a device's connections calls in Python, Go, Ruby and Rust - #2156
Conversation
kanat
left a comment
There was a problem hiding this comment.
Reviewed #2156 at a7e82f8 merged onto main (2d236ed). CI: the draft runs no SDK jobs (#2130), so CI runs after gh pr ready.
[Nit] R1.1 sdks/ruby/lib/getstream/vision_agents/client.rb:52-82 (not in this diff): Client#get, post, put, patch, delete and socket take user_id: (#2102) and a device naming a user there is not refused. This does no harm: the router ignores X-Stream-User-Id from a verified user token (acceleration/internal/auth/auth.go:441-446) and answers a server-only operation with 403. JS has no per-call user on its generic request. Better handled as a ticket than in this PR.
Verdict: approve (no Blocker, no Should fix).
Checked and sound:
- Hard rules, base against head. The full request was compared: headers, body and query. In Python (8 client shapes) and Go (6 shapes), each call was made with no user, an empty one, and a named one. A device naming a user now gets the configuration error on all five calls, and nothing is sent. Every other case sends exactly what the base sent: a device naming no user or an empty one, a backend naming a user, and the customer-id client with or without
as_user/SetUser. In Ruby and Rust the path that is not refused sends what the base sent by construction:namedreturnsuser_id.to_s, andactingreturnsOkof the same client. All four SDKs' new control tests pass on2d236ed, and their refusal tests fail there. - Call sites. All five calls in each SDK go through the guard. 13 mutants were run and all were killed: guard off, guard inverted, guard refusing an empty or absent user, a predicate keyed on the secret, token or
ServerSide(), and Create, List and reach each bypassing the guard (Go and Rust). - Suites. Python
plugins/stream: 683 passed. ruff and mypy are clean. Go./client ./streampasses, as do vet and gofmt. Rubyrake: 259 runs, 0 failures. Rust:cargo test,clippy -D warningsandfmt --checkpass. - Go
Backend{APIKey, APISecret, UserID}. This client is now refused when it names a user. On the base it sent a token whose claim is that user, which the router reads as a device, so the call always got a 403. - CHANGELOG and skill note. The CHANGELOG has one entry and no stray blank lines. The skill note is the last line of
.claude/skills/sdk/SKILL.md, and the lines it cites are correct.
#2156 changes the Go behaviour this sentence described. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…call names A Backend with the API secret and a UserID naming another user on a connections call signed a token for its own user, which the proxy refuses (403). Like the other SDKs, the call now drops the client's own user and sends the app's token with X-Stream-User-Id. Only a client holding a user's Token (SetUser) is refused. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Round 1 fixes:
|
kanat
left a comment
There was a problem hiding this comment.
Delta round 2: GO (71e72b8, contains origin/main 8e68a6c via 07f5382, no conflicts)
- X0.1 fixed.
Connections.api(connections.go:189-201): a client holding aToken(SetUser) and naming a user is still refused. ABackend{APIKey, APISecret, UserID}without aTokendrops its ownUserIDfor that call and sends{server:true}plusX-Stream-User-Id: <named>, the wire of Pythonacting_for(_backend.py:457-463). A call naming no user, and the customer-id path, are unchanged (control test, claims{user_id: ada}, no acting header).sdks/go/streamis untouched, so Dispatch andclient.Agentare unchanged. - Mutations: dropping the
UserIDreset, both Token guard directions, the outer guard without the user check,ActingFor = backend.UserID, the outer guard withoutAuthenticate, and a leftoverTeamclaim each fail a test. One survivor,|| APISecret == ""on the Token guard, is equivalent: Resolve already refuses a backend with no secret and no token. - R1.1 withdrawn.
getSessionisx-client-accessible(openapi.yaml ~18795), so the Ruby generic verbs reach a call a device may make naming its own user; anamedrefusal would break it. No gap found, no ticket. - Suites on the head:
gofmt -l,go vet ./...,go test ./client ./streampass;-race -cpu 1 -count=3on the new and device tests pass. - CI: draft, so go/sdks/unit skip (#2130); not waited.
Why
The router answers every connections call made with a user token with
403 server_side_only: these operations carry nox-client-accessible, sorefuseClientSidestops them before the handler (acceleration/internal/api/server.go:1262). A device that names auserIdon a connections call therefore always failed, after a request, with a generic router error. The JavaScript and PHP SDKs already refuse it before sending. Python, Go, Ruby and Rust did not (AI-3412).Go had a second bug. A
Backendbuilt for one user with the API secret, naming another user on a connections call, signed a token for its own user plusX-Stream-User-Id: <named>. Stream's proxy refuses that pair with 403 (chat projects/stream-accelerate/proxy.go:425-431). The other SDKs act for the named user with the app's token.How it works
A device is a client holding a user's token. Python, Ruby and Rust key it on the SDK's own
server_side. Go keys it onAuthenticatewith aUserIDand aToken, becauseSetUserkeeps the API secret and sets the token (sdks/go/client/client.go:96-98).Left as they were, each with a control test:
as_userorSetUserwith a customer id and no API key): it sends no token, works against a dev router today, and is out of scopeChanges
Connections._clientValueError(asClient._acting)Connections.apiclient:error; a backend built for a user and naming another drops its ownUserIDfor that call and sends the app's token withX-Stream-User-IdConnections#namedConfigurationErrorConnections::actingError::Configuration;actingnow returnsResult<Client>, public signatures unchangedsdks/go/stream(backend.go, Dispatch) andclient.Agentare unchanged: the Go fix is a local copy of the backend insideConnections.api.Also: one CHANGELOG entry and one note at the bottom of
.claude/skills/sdk/SKILL.md. .NET follows in #2155 (AI-3410).Validation
plugins/stream:uv run --no-sync pytest plugins/stream -m "not integration": 683 passed.sdks/go:gofmt -lempty,go vet ./...,go test ./client ./streamok,-race -cpu 1 -count=3on the new and device tests ok.rakein Docker: 259 runs, 0 failures.cargo test,clippy --workspace --all-targets -D warnings,fmt --all --check: ok.acting_for.|| APISecret == ""on the Go token guard:Resolvealready refuses a backend with neither secret nor token,backend.go:229).71e72b8ef(CodeQL, go, sdks, unit Lint and Test "not integration", Analyze).Review rounds
a7e82f8adget,post,put,patch,delete,socket) do not refuse a device naming a user989bd9235. Fixer r1 disputed R1.1:getSessionis client-accessible and a device may name itself71e72b8efgetSessionisx-client-accessible, so a refusal would break a working call)Related
🤖 Generated with Claude Code