feat: scope client tokens to specific browser origins#50
Merged
AdirAmsalem merged 1 commit intomainfrom May 3, 2026
Merged
Conversation
Adds `allowed_origins` to `tokens.create()`. When set, realtime sessions opened with the resulting token are accepted only if the browser's WebSocket `Origin` header matches one of the listed origins. Pairs with `allowed_models` to give server-side issuers tighter control over how a frontend-bound token can be used.
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.
Summary
Adds an
allowed_originsoption toclient.tokens.create()that scopes a short-lived client token to a specific list of web origins. When the token is later used to open a realtime session, the connection is accepted only if the browser-issued WebSocketOriginheader matches one of the listed origins.This complements
allowed_modelsto give server-side issuers tighter control over how a frontend-bound token can be used. When omitted, no origin restriction is applied.Usage
Combine with the existing options:
Notes
scheme://host[:port]), up to 20 entries.Originheader, so it raises the cost of stolen-token abuse from a different web origin but does not protect against attackers controlling a non-browser HTTP client.Test plan
uv run pytest tests/test_tokens.py— 10/10 pass, including newallowed_originsrequest-body test and updated all-options round-trip.examples/create_token.pyupdated to demonstrate the new field.Note
Low Risk
Low risk, additive change that passes a new optional field through to the token-creation API and expands the typed response shape; main risk is mismatched API expectations for the new
allowedOrigins/originsfields.Overview
Adds optional
allowed_originstoclient.tokens.create()and includes it in the POST body asallowedOrigins, allowing server-issued client tokens to be scoped to specific web origins.Extends
TokenPermissionsto optionally includeorigins, updates the create-token example to display allowed origins, and adds/updates tests to cover request serialization and permissions round-tripping. Also bumps the package version inuv.lock.Reviewed by Cursor Bugbot for commit 7de3f4d. Bugbot is set up for automated code reviews on this repo. Configure here.