Skip to content

Secure the devtools panel

View as Markdown

In a page you ship, the panel carries a panel token: a short-lived token your backend mints from Studio for one conversation’s public id, with the server token that never leaves the backend. A read-scoped panel token (the default) lets the page read that conversation and nothing else; a playground-scoped one also lets it replay, decide and steer there. Never put the dev token or the server token in a page you ship. On your own machine, setup A on loopback needs no token, and with weft studio (setup B) your dev page carries the dev token as data-token.

Mint the token in your backend, in docs-site/examples/devtools/appturns.go:

devtools/appturns.go
// mintPanelToken asks Studio for a token scoped to one conversation,
// with the server token, which never leaves the backend. playground
// lets the page act (replay, decide, steer); without it the token reads.
func mintPanelToken(ctx context.Context, studioURL, serverToken, publicID string, playground bool) (string, error) {
body, err := json.Marshal(map[string]any{"public_id": publicID, "ttl": "15m", "playground": playground})
if err != nil {
return "", err
}
req, err := http.NewRequestWithContext(ctx, http.MethodPost,
strings.TrimSuffix(studioURL, "/")+"/api/panel-tokens", bytes.NewReader(body))
if err != nil {
return "", err
}
req.Header.Set("Authorization", "Bearer "+serverToken)
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
return "", err
}
defer func() { _ = resp.Body.Close() }()
var out struct {
Token string `json:"token"`
}
if resp.StatusCode != http.StatusOK || json.NewDecoder(resp.Body).Decode(&out) != nil {
return "", fmt.Errorf("mint panel token: %s", resp.Status)
}
return out.Token, nil
}

devtools/appturns.go on GitHub

Then render it into the page with the panel’s tag:

devtools/appturns.go
// panelTag is the page's script tag: the hosted Studio, the minted
// token and the conversation, escaped as attributes.
var panelTag = template.Must(template.New("panel").Parse(
`<script type="module" src="{{.Studio}}panel.js" data-weft` +
` data-endpoint="{{.Studio}}" data-token="{{.Token}}" data-scope="{{.PublicID}}"></script>`))

devtools/appturns.go on GitHub

data-token (or <meta name="weft:token">) is in your page’s source for anyone who loads the page, which is why it must be a panel token scoped to the conversation that page shows.

SetupToken in the pageWho may read what
A · Studio embedded in your app, no studio.Tokennonea loopback Host, or an AllowOrigins host; everything is readable from there
B · weft studiothe dev token, as data-token on your dev page onlyeverything; never ship it
C · hosted, studio.Token(tok)a panel token minted per pageone public id, or one batch of runs by its tags

POST /api/panel-tokens exists only when Studio has a Token, and only the server token may call it. The body is {"public_id": "pub_…", "tags": {…}, "ttl": "15m", "playground": false}, with public_id or tags required; ttl defaults to 1h and has no maximum, so pick a short one. A field it does not know is a 400 naming the fields, never a read token minted in silence: {"scope":"playground"} answers body must be JSON with public_id, tags, ttl and playground ("playground": true mints a playground token). The answer is {"token":"weft_pt.…","public_id":"pub_…","scope":"read","exp":"…"}, plus tags when the token has them. The token is the claims {public_id, tags, scope, exp} signed with HMAC-SHA256 under the Token: changing the Token invalidates every panel token.

A tag-scoped token reads a batch of runs by their run metadata, across public ids: {"tags": {"arena.batch": "cli-20261012-115753"}}, with or without a public_id. Its limits:

  • It is read-only: "playground": true beside tags is a 400.
  • It takes at most 16 pairs, with keys and values of at most 256 bytes, and no weft.* key but weft.flow.
  • Every read it makes is held to its tags, as a public id token’s is to its public id. That covers runs, search, stats, sessions (with their timeline, entries and export), traces (every span must carry the tags), a run and its events, transcript, steps, spans, export, tree and diff, and the live stream and its grant.
  • Like any read token, it reads no app logs, request records or tool catalogs. A tags-only token (no public_id) reads no run commands either: commands are a public id’s (a 403). The experiments list is the server token’s alone.
  • A run without the tags is a 403, and so is another value of one of its tag keys: a request narrows, never widens.
  • A Subagent child inherits the tags. An untagged pool or thread child is a counted hidden hole, “without your token’s tags”.
  • The command routes refuse it.

The capability is panel_token_tags. A tag scope is only as tight as your app’s own tagging, since metadata is caller-written. That is why minting stays the server token’s. ExampleToken (tagScope) mints one. Secure Studio covers the server side.

Accessread panel tokenplayground panel tokendev / server token
Runs, sessions, traces and the live stream of its public id✓✓✓
Another public id’s run403 this token is scoped to … (its public id or its tags)403✓
System prompts, tool catalogs (the request tab, /api/manifest); in /api/runtimes, agent instructions, the default tool_choice name and stophidden / omitted✓✓
Replay verbs, the experiment drawernot drawn✓, inside its public id✓
Decide a parked turn, steer403 this token is read-only: mint it with "playground": true to act✓, inside its public id✓
App logs (📄 ⤢)not drawnnot drawn✓
save as testnot drawn✓✓
Propose a prompt (keep as prompt)—copies only: “a proposal needs the dev token”✓
Experiments routes, the runtime link, breakpoints, DELETE, /api/live?all=1403403✓

A playground token’s replay must come from a run inside its public id and may not set an experiment_id. The panel reads the token’s scope from its claims only to decide what to draw; Studio enforces the scope on every route and every live frame. Child runs that carry another public id, or none (a pool child session, a nested Generate, a child whose Metadata cleared weft.public_id), are left out and counted as one hidden hole, labelled “hidden by your token’s access”. Its reason reads N child runs carry another public id, or none: a panel token reads its own public id's runs, so they are left out. A run’s delegated cost then reads unknown to the token: N of M child runs carry another public id, or none: a panel token does not read their cost (See what a run cost). TestPanelTokenReadsItsPublicID in the example mints a read token for pub_jane and checks that it lists only pub_jane’s turn, gets 403 for pub_ali’s run and for an approval, and that a playground token for pub_jane decides that conversation’s parked turn but not pub_ali’s.

Two detection rungs read the page (Scope the panel), and their defaults depend on the token:

  • The fetch wrapper (the Weft-Scope header rung) is on by default only when the page and Studio are both on loopback and the token is not a panel token (weft_pt.). A shipped page is never patched unless you set data-detect="headers". It reads response headers only, never a body, and is restored as found on disconnect.
  • DOM markers are on everywhere except a page off loopback under a read-scoped panel token.

The footer says which are on: under a panel token on loopback it reads detect: markers.

Without a Token, Studio’s API answers only a loopback Host (or an AllowOrigins host), and refuses an unsafe method (anything but GET, HEAD or OPTIONS) whose Origin is not the request’s own host and port or an AllowOrigins entry, or that has no Origin but Sec-Fetch-Site: cross-site: cross-origin write refused (setup A). Another site open in your browser cannot approve your parked turns or start replays. Secure Studio has the details.

Studio’s pages need a token of their own; the panel never puts its token in a URL. Under a playground-scoped panel token, the panel’s ⤢ and every [data-weft-handoff] link go through GET /api/panel-handoff?to=<path> (capability handoff, only when Studio has a Token):

BearerAnswer
playground panel token303 to <base><to>#token=weft_pt.…: a fresh read token for the same public id, valid 5 minutes and never past the caller’s own expiry. With Accept: application/json, {location, exp} instead
server token303 to <base><to>#token=<server token>, the way weft open --with-token signs a terminal in, so the panel’s ⤢ and g s land signed in
read panel token403 a read-scoped token cannot widen: …; the page links to Studio directly and Studio asks for a token

to must be a path under Studio’s base (one leading /, no scheme, host, fragment, backslash, white space or . segment), else 400: it is never an open redirect. The token rides in the fragment, which is never sent to a server. The hand-off is logged without the token. The tab opens after the answer, so a browser may block it as a popup; past 1 s the panel shows the plain link on its note line.

The opened tab keeps the handed-over token in sessionStorage["studio.tab-token"], for that tab alone; it never replaces the token stored in localStorage. When its 5 minutes are over and Studio answers 401, the tab drops it and retries with the stored token, if there is one. With none stored, the token prompt reads “The hand-off token this tab’s link carried expired; paste a token or ask for a new link.” Settings › Token shows a hand-off token as “this tab only”, and its clear drops that token alone: “this tab’s hand-off token cleared: the stored token serves again”.

EventSource cannot send headers, so the panel opens its live stream with a grant: POST /api/live-grant with the token in the Authorization header answers a signature, and the stream is GET /api/live?public_id=…&kinds=…&sig=weft_lg.…. A grant lasts 60 s, never past the panel token’s expiry, and may be reused by the browser’s reconnects while it lasts. A query ?token= is refused 401 on every /api route.

When a panel token expires, Studio ends its stream with one frame:

event: expired
data: {}

The panel does not ask again: the live dot goes out (its title turns from live to history), the turns it read stay, and nothing reaches the console. Mint a new token and set a new data-token; the panel restarts its connection on it.

  • Mint per page, per conversation, short-lived. A panel token has no maximum TTL and cannot be revoked short of rotating the Token. (Source: studio/auth.go:642-735)
  • Mint read scope unless the page’s user may act. A playground token can replay, decide and steer inside its conversation. (Source: studio/auth.go:468-477)
  • Never ship the dev or server token, in data-token or weft:token. Both are in the page’s source. (Source: studio/README.md:1297-1299; studio/web/npm/README.md:99-101)
  • Keep the token out of URLs. Studio refuses ?token=; links the panel builds carry none, and the hand-off uses the fragment. (Source: AGENTS.md:402-405)
  • Expect the panel to go quiet at expiry. It keeps what it read and stops live updates; refresh the token from your page. (Source: studio/README.md:862-866)
  • A refused token says what it wants. A Studio that answers 401 or 403 is never removed: the panel’s line names the token it wants: Studio needs a token at <endpoint> — add data-token (the dev token) or a panel token (POST /api/panel-tokens) · retry. When the panel does not connect lists each case. (Source: CHANGELOG.md:61; studio/web/src/panel/element.ts:2844-2861 reachLine)

Symbols used: studio.Token · studio.AllowOrigins · thread.PublicID