Secure Studio: tokens, loopback and origins
Studio’s JSON API carries transcripts and, with the playground on, verbs that start runs and decide approvals. What guards it depends on the setup: without a token (setup A) only a loopback Host reaches it and cross-origin writes are refused; weft studio (setup B) adds a stable dev token; a hosted Studio (setup C) sets studio.Token and hands pages panel tokens scoped to one conversation. OTLP ingest has its own guard, studio.IngestToken.
| Setup | /api answers | OTLP ingest answers | CORS |
|---|---|---|---|
A · embedded, no Token | a loopback Host or an AllowOrigins host; no cross-origin unsafe method | loopback peers without proxy headers or a foreign Origin | none, unless AllowOrigins lists origins |
B · weft studio | the dev token as a bearer | loopback peers, as A (the binary has no ingest-token option) | http and https origins on localhost and 127.0.0.1, any port; fixed (the binary has no AllowOrigins option) |
C · hosted, Token(tok) | the server token or a valid panel token as a bearer; the Host does not matter | IngestToken’s bearer when set, else as A | AllowOrigins, else localhost and 127.0.0.1 |
Studio’s handler does not bind a port: you choose the address. Bind loopback, or set a Token, before you expose it wider. Studio does not terminate TLS; serve a hosted Studio behind your HTTPS listener or proxy.
Setup A without a token
Section titled “Setup A without a token”With no Token, the whole /api tree (reads, the live stream, the playground and debugger verbs, the runtime link) answers only a request whose Host is a loopback name: localhost, *.localhost, 127.0.0.0/8 or [::1], any port. A DNS-rebinding page (http://evil.example:7331 resolving to 127.0.0.1) is same-origin to the browser, but its Host is evil.example:7331, so it gets a 403 that names what to configure. Proxy headers (X-Forwarded-Host, Forwarded) are never read; behind a proxy, the Host it forwards is the one checked.
The loopback Host stops a rebound page, not a cross-site one: any site’s page can POST to localhost without a preflight. So setup A also refuses a cross-origin write. An unsafe method (anything but GET, HEAD or OPTIONS) is refused when its Origin’s host:port is not the request’s Host and not an AllowOrigins entry, or when it sends no Origin but Sec-Fetch-Site: cross-site. The 403 starts cross-origin write refused (setup A). Same-origin pages and clients that send neither header (curl, the runtime link) pass. Reads need no such rule: setup A sends no CORS headers, so the browser hides the answer from a foreign page.
To serve setup A on a real hostname, list that origin, studio.AllowOrigins("http://myapp.internal:8080"); its host:port must equal the request’s Host (Run Studio shows it in a program). "*" admits every Host and every origin. The UI shell and /panel.js carry no data and are served to any Host. The loopback Host rule arrived in weft 0.8.0; before it, a rebound page could start playground runs, approve parked calls and read transcripts. The cross-origin write rule arrived in 0.14.0.
The dev token
Section titled “The dev token”weft studio and weft dev protect the API with a token that is stable per database: <db>.token beside the SQLite file (.weft/weft.db.token), 32 random bytes in base64url, mode 0600, created on the first start and reused by every later one. It is never printed. --open hands it to the browser in the URL fragment (#token=), which never reaches a server; the UI reads it, and any other browser asks for it once (“This Studio needs its API token”). weft open --with-token prints a Studio link with the token in its fragment; the id is optional. The token is --token, else WEFT_STUDIO_TOKEN, else the token in the discovery file of the Studio it found. It never reads <db>.token. weft dev passes the dev token to your app as WEFT_STUDIO_TOKEN.
weft studio --rotate-token--rotate-token writes a new one before serving. --token or WEFT_STUDIO_TOKEN override the file without touching it. A database with no file (:memory:, ClickHouse) gets a per-process token, generated by studio.DevToken and printed at start. The dev token is a server token like any Token value, so it is also the signing key of the panel tokens minted against it. Since weft 0.11.0; before it, every start printed a fresh token.
Tokens and the wall
Section titled “Tokens and the wall”studio.Token(tok) walls the /api tree. Every request needs Authorization: Bearer <tok> or a panel token, compared in constant time; then the Host no longer matters. /panel.js and the UI shell stay static and unchecked.
A token is accepted from the Authorization header only. A ?token= query parameter is refused on every /api route, in every setup, whatever it holds: a 401 that starts a token in the URL is never accepted. A URL lands in logs, history and Referer headers. In weft 0.7.0 ?token= was the live stream’s way in, since EventSource cannot set headers; the live grant replaced it.
OTLP ingest (/v1/traces, /v1/logs) is checked against a different value:
- With
studio.IngestToken(tok), every ingest request needsAuthorization: Bearer <tok>, loopback included. Each route compares the bearer with its own token, so when the two differ the API token is not accepted there and the ingest token is not accepted on/api. Set them to the same value and each works on both. - Without one, ingest answers loopback peers only, and refuses even those when the request carries
Forwarded,X-Forwarded-FororX-Real-IP(behind a proxy on the same host every client is a loopback peer) or a browserOriginthat is not allowed. A proxied Studio setsIngestToken.
otel.Studio(url, token) sends one token as the ingest bearer, so an app exporting to a hosted Studio passes the ingest token there (Deploy).
AllowOrigins(origins...) is the CORS list for the API and ingest. With a Token and no list, localhost and 127.0.0.1 on any port (http or https) are allowed; setup A without a list sends no CORS headers. Allowed origins get GET, POST, PUT, DELETE, OPTIONS, the Authorization, Content-Type and Last-Event-ID headers, and X-Request-Id exposed; answers carry Vary: Origin whenever CORS is in play.
Check the wall from a shell:
curl -s -o /dev/null -w '%{http_code}\n' https://studio.example/studio/api/runscurl -s -H "Authorization: Bearer $WEFT_STUDIO_TOKEN" https://studio.example/studio/api/metaThe first prints 401. The example’s TestTokens checks the same rules offline: ingest without its bearer refused from loopback, the API token refused on ingest, ?token= a 401.
weft’s own TestAuthMatrix reads every route Studio registers and fails on a route with no row in its table of identities and answers, so a new route cannot ship unchecked. The OTLP receiver’s two routes are rows too: the ingest token opens them, and every API identity gets 401.
Panel tokens and handoff
Section titled “Panel tokens and handoff”The devtools panel runs in your app’s page, where the server token must never go. Your backend mints a panel token for the conversation the page shows, with the server token:
curl -s -X POST https://studio.example/studio/api/panel-tokens \ -H "Authorization: Bearer $WEFT_STUDIO_TOKEN" -H 'Content-Type: application/json' \ -d '{"public_id":"pub_jane","ttl":"15m"}'{"token":"weft_pt.…","public_id":"pub_jane","scope":"read","exp":"…"}POST /api/panel-tokens exists only when a Token is set, and only the server token may call it. A panel token is weft_pt.<payload>.<signature>: the claims {public_id, tags, scope, exp} signed with HMAC-SHA256 under the Token value, so changing the Token invalidates every panel token minted under it. ttl defaults to 1h and must be a positive duration; there is no maximum, so choose one. The public id is the one your runs carry as weft.public_id (thread.PublicID sets it on a session’s turns).
What a panel token may do:
| Access | read (default) | "playground": true |
|---|---|---|
| Runs, sessions, traces, the live stream of its public id | ✓ | ✓ |
| Anything outside its public id | 403 this token is scoped to public id … | 403 |
| Start runs, decide parked calls, steer | 403 this token is read-only | ✓ |
What carries system prompts, catalogs or app logs: /api/manifest, manifests/{hash}, a run’s requests, its app logs, exports with requests, fixtures | 403, with a hidden badge | ✓ |
The same inside a step, a diff’s system row, a playground preview; in /api/runtimes (200) each agent’s instructions, default tool-choice name and stop sequences | hidden or emptied | ✓ |
| Experiments | server token only | server token only |
The runtime link, breakpoints, DELETE, /api/live?all=1 | 403 | 403 |
/api/meta’s database path and size | omitted | omitted |
Since 0.20.0 a token can name a batch of runs by their run metadata instead of, or beside, a public id: {"tags": {"arena.batch": "cli-20261012-115753"}}. Such a token is read-only and held to its tags on every read, as a public id token is to its public id. Run metadata is written by your code, weft.Metadata on a run or thread.WithRunMetadata on every turn of a session, so a tag token is only as tight as that tagging; minting stays the server token’s (A tag-scoped token).
A run the token may read can have child runs with another public id, or none. Every route that reaches runs through another keeps the token’s own children and reports the rest as one hidden hole with a count, never by id, public id or prompt. An unknown run id answers 404 as for any identity, so scoping does not reveal whether another public id’s run exists. The example’s hostedStudio mints a token for pub_jane and gets 200 for its runs and 403 for another public id.
GET /api/panel-handoff?to=<path> opens Studio from the panel without pasting a token. Under a playground-scoped panel token it answers 303 to <base><to>#token= with a fresh read token for the same public id, valid 5 minutes and never past the caller’s own expiry; with Accept: application/json it answers {location, exp} instead. A read-scoped token gets 403: a scope never widens. Since 0.20.0 the server token hands off too: the location carries it in the fragment, as weft open --with-token does, so the panel’s ⤢ lands signed in. to must be a path under Studio’s base (no scheme, host, fragment, backslash or . segment), else 400, and every answer is Cache-Control: no-store with Referrer-Policy: no-referrer. The route exists only with a Token. Secure the devtools panel covers the page side.
Live grant
Section titled “Live grant”EventSource cannot send headers, and a token never goes in a URL, so the live stream opens with a grant. The page asks with its bearer, or, in setup A, with no credential:
POST /api/live-grantContent-Type: application/json
{"run":"r_1","kinds":"event,run"}The answer is {sig, exp}, Cache-Control: no-store. The page then opens GET /api/live?run=r_1&kinds=event,run&sig=<sig>. The signature binds the identity that asked, the selector, the kinds set and the expiry: 60 seconds from the grant, never past a panel token’s own expiry. Another selector, another kinds set, a tampered or expired sig is a 401.
A grant is a window, not a ticket: any number of streams may open with it while it lasts, because an EventSource reconnects with the same URL. A leaked grant URL is therefore live for 60 seconds; the token is never in it and Studio never logs the URL. Each stream opened in time runs until it is closed. A panel token’s stream ends at the token’s expiry with one event: expired frame; a server token’s does not. A panel token is granted only streams inside its public id, and the all selector is the server token’s or setup A’s loopback alone. Without a Token the signing key is random per process, so setup A can take the same path; it also opens a stream without a sig, as its open identity. The grant arrived in weft 0.12.0.
No external requests
Section titled “No external requests”Studio’s UI loads nothing from another origin. Every response carries Referrer-Policy: no-referrer, X-Content-Type-Options: nosniff and Content-Security-Policy: default-src 'self'; img-src 'self' data:; style-src 'self' 'unsafe-inline'; script-src 'self' plus one hash per inline script, never 'unsafe-inline' for scripts. Pricing is a local table and nothing is fetched. A Studio on an isolated network works the same as one on the internet.
What these tokens do not protect
Section titled “What these tokens do not protect”Studio’s tokens guard Studio’s API. They do not make an approval a security control:
- Approval is a policy seam, not a security boundary. A per-call prompt does not contain a compromised prompt or a malicious tool; an OS-level sandbox around the tool does (ADR 0007). See Require approval before a tool runs.
- A decision that crosses a process boundary should be signed. Sign approval decisions lists what signing guarantees and what it does not.
- Grants pre-approve.
s.Grantis an in-process, unsigned call, andthread.ApproveAlwaysmints a grant for the call’s exact arguments, so the next such call never parks (Grants). - The panel’s playground scope acts. A playground-scoped panel token can start runs and decide that conversation’s parked calls; mint it only for a page whose user may.
Best practices & gotchas
Section titled “Best practices & gotchas”- Set a
Tokenbefore Studio listens beyond loopback. Without one the API’s only guard is the loopbackHost, widened byAllowOrigins. (Source:studio.Handlergodoc,studio/studio.go:293-301;studio/auth.go:246-303) - Use two different secrets for
TokenandIngestToken. Each route checks its bearer by plain comparison with its own token, so the separation holds only when the values differ; then apps hold the ingest token and only your backend holds the server token, which also signs panel tokens. (Source:studio/studio.go:368-371;studio/auth.go:290,87-99) - Behind a reverse proxy, set
IngestToken. Loopback ingest refuses forwarded requests, so a proxied Studio without one ingests nothing remote. (Source:studio/studio.go:349-362; CHANGELOG 0.8.0 L3136) - Behind a proxy that rewrites
Host(Vite’schangeOrigin: true), list the front origin inAllowOrigins. Setup A compares theOrigin’shost:portwith theHost. (Source:studio/README.md:38-45) weft studio’s CORS list cannot be widened. It has no flag or environment variable forAllowOrigins, so a dev page on any other host (*.localhost,[::1], a LAN IP) gets no CORS headers, not even on/panel.js, and the panel does not appear. Use a same-origin proxy, or embed Studio withstudio.AllowOrigins, whose list replaces thelocalhostdefault. When the panel does not connect has the cases. (Source:studio/auth.go:774-792;cmd/weft/main.go:475-494,768-800; observed with curl and Chromium)- Mint short panel tokens. The 1 h default has no ceiling and a token cannot be revoked short of rotating the
Token. (Source:studio/auth.go:642-735) - Never put a token in a URL query. It is refused anyway; send the bearer, and use a live grant for
EventSource. (Source:studio/auth.go:250-258)
See also
Section titled “See also”- Deploy an agent service with a hosted Studio
- Run Studio: embedded, local binary or hosted
- Watch runs live
- Secure the devtools panel
- Control what content leaves the process
Symbols used: studio.Token · studio.IngestToken · studio.AllowOrigins · studio.DevToken · studio.Handler · otel.Studio · thread.PublicID · thread.ApproveAlways · Session.Grant