---
title: Secure the devtools panel
description: Which token the devtools panel carries in a page you ship (a per-page panel token minted by your backend, read or playground scope, never the dev or server token), what each token may do, the loopback-only defaults, the hand-off to Studio and the live stream's grant and expiry.
url: https://weftgo.dev/docs/observe/devtools/security/
type: how-to
sources:
  - 'W11-factcheck4, v0.20.2: weft/studio/playground.go:975-982 (tagOnlyCommands: only a token with no public id is refused the command reads)'
  - 'weft/studio/playground.go:975-982 (tagOnlyCommands: a tag-only panel token reads no command, 403), 1019-1043 (a public id''s panel token reads its public id''s commands); weft/studio/apphost_test.go:60-64 — v0.20.2'
  - weft/studio/tag_token_test.go:420-495 (what a tag token reads and is refused; v0.20.2)
  - 'weft/studio/auth.go:632-735 (servePanelTokens: decodeStrict''s 400, public_id or tags, read-only tags, ttl; checkMintTags: 16 pairs, 256 bytes, weft.flow alone)'
  - 'weft/CHANGELOG.md:47 (0.20.0: tag-scoped panel tokens), 61 (401/403 never removed), 64 (handoff for the server token), 69 (the hidden hole''s words), 76 (child runs), 82 (unknown body field 400)'
  - 'weft/studio/auth.go:72-80 (panelClaims: public_id, scope read|playground, exp; weft_pt.), 169-218 (sign and parse: HMAC-SHA256 under the Token), 341-344 (forbidden: this token is scoped to public id …), 468-477 (mayAct: this token is read-only), 642-735 (servePanelTokens: the server token only, ttl default 1h, any positive duration)'
  - 'weft/studio/handoff.go (GET /api/panel-handoff: playground token → 303 #token= read token, 5 minutes capped at its exp; server token 303 without fragment; read token 403; to under the base else 400; with a Token only)'
  - 'weft/studio/livegrant.go (the 60 s grant, reusable, never past a panel token''s expiry; event: expired)'
  - weft/studio/debugger.go:39-43 (breakpoints refuse every panel token)
  - 'weft/studio/README.md:833-866 (no link or request URL carries a token; the grant; a panel token''s stream ends with event: expired and is not asked again)'
  - weft/studio/README.md:1297-1299 (a weft:token meta tag is a token in the page's source)
  - weft/studio/README.md:3521-3537 (GET /api/panel-handoff)
  - weft/studio/web/npm/README.md:99-101 (tokens in pages you ship)
  - 'weft/studio/web/src/panel/config.ts:7 (weft:token), 320 (data-token), 533-568 (headerRungOn: loopback page and endpoint, no weft_pt. token; markerRungOn: off only off loopback under a read token)'
  - 'weft/studio/web/src/lib/replay.ts:370-393 (tokenScopeOf: a hint read from the token''s claims, never a check; canReplay)'
  - weft/studio/web/src/panel/element.ts:848-848 (handoff under a playground token with the handoff capability)
  - weft/AGENTS.md:350-353 (/api/panel-tokens, /api/panel-handoff), 402-411 (Token walls /api, ?token= refused, the live grant, expired, the setup A cross-origin write rule)
  - weft/CHANGELOG.md:893 (panel-handoff, plan G3), 3402 (read tokens cannot decide, steer or read /api/manifest; /api/runtimes omits instructions), 3404 (a playground token's source run inside its public id; no experiment_id; experiments refuse panel tokens; /api/live checks every frame; constant-time compare), 4147 (the runtime link and breakpoints refuse panel tokens)
  - docs-site/examples/devtools/appturns_test.go:TestPanelTokenReadsItsPublicID
  - 'observed: a scratch app embedding weft studio v0.17.0 with studio.Token (WEFT_DISCOVERY=off), Chromium (Playwright 1.62.0) and curl: under a read panel token the panel drew no replay verb, no save as test and no 📄 ⤢, the request read request: hidden by your token scope, the parked verbs read this token is read-only: mint it with "playground": true to act, and the footer detect: markers; under a playground token the verbs were drawn and ⤢ called GET /api/panel-handoff and opened runs/<id>?step=0&view=story#token=weft_pt.… (a read token); the live stream opened with POST /api/live-grant then /api/live?…&sig=weft_lg.…; a 40 s token''s live dot went from live to history with no new grant and nothing in the console; curl saw event: expired at a 6 s token''s expiry; ttl 0s was 400; a read token''s hand-off was 403 a read-scoped token cannot widen; to=https://evil.example/ was 400; ?token= was 401'
  - 'weft/studio/auth.go:823-845 (hostAllowed: loopback or an AllowOrigins host)'
  - weft/studio/README.md:196-209 (children of another public id, or none, left out as one hidden hole; delegated cost not known to the token)
  - weft/studio/pricing.go:977 (the delegated reason under a panel token)
  - weft/studio/web/src/lib/api.ts:1053-1061 (studio.tab-token in sessionStorage, never localStorage), 1113-1135 (a 401 drops the tab token and retries with the stored one)
  - weft/studio/web/src/components/studio/token-wall.tsx:40-43, 68-71 (the expired hand-off wording)
  - weft/studio/web/src/routes/settings.tsx:412 (clear drops the hand-off token alone), 421 (this tab only)
  - 'weft/studio/manifest.go:176-182 (a read token''s /api/runtimes: no instructions, default tool_choice name or stop)'
  - weft/studio/web/src/panel/state.ts:2055-2068 (a fetchMeta failure sets gone; a 401 or 403 also walled, never removed — v0.20.2); weft/studio/web/src/panel/client.ts:66-86 (any non-2xx answer throws); weft/studio/web/src/panel/element.ts:2276-2290 (the self-mounted dock removed, a mount the host made shows the not-reachable line)
  - 'observed: a scratch weft studio v0.17.0 and curl: an expired 2 s panel token, the old dev token and a panel token minted before --rotate-token answered /api/meta 401 bad or expired token; in Chromium 151 a script-tag dock with a refused token was removed and a <weft-devtools> showed Studio not reachable at http://127.0.0.1:7381/ · retry, the only console line the browser''s Failed to load resource: … 401 (Unauthorized)'
  - 'weft/studio/web/src/lib/saves.ts:125-130 (mayExportTestWith: export and not read scope); weft/studio/web/src/panel/element.ts:5966 (logs link: no panel token)'
---

# Secure the devtools panel

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`:

```go title="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](https://github.com/weftgo/weftgo.dev/blob/main/docs-site/examples/devtools/appturns.go)

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

```go title="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](https://github.com/weftgo/weftgo.dev/blob/main/docs-site/examples/devtools/appturns.go)

`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.

## Tokens

| Setup | Token in the page | Who may read what |
|---|---|---|
| A · Studio embedded in your app, no `studio.Token` | none | a loopback `Host`, or an `AllowOrigins` host; everything is readable from there |
| B · `weft studio` | the dev token, as `data-token` on your dev page only | everything; never ship it |
| C · hosted, `studio.Token(tok)` | a panel token minted per page | one 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)`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/studio#example-Token-TagScope) mints one. [Secure Studio](https://weftgo.dev/docs/production/security/#panel-tokens-and-handoff) covers the server side.

### What each token can do

| Access | read panel token | playground panel token | dev / server token |
|---|---|---|---|
| Runs, sessions, traces and the live stream of its public id | ✓ | ✓ | ✓ |
| Another public id's run | 403 `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 `stop` | `hidden` / omitted | ✓ | ✓ |
| Replay verbs, the experiment drawer | not drawn | ✓, inside its public id | ✓ |
| Decide a parked turn, steer | 403 `this token is read-only: mint it with "playground": true to act` | ✓, inside its public id | ✓ |
| App logs (`📄 ⤢`) | not drawn | not drawn | ✓ |
| save as test | not 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=1` | 403 | 403 | ✓ |

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](https://weftgo.dev/docs/observe/studio/cost/#unpriced-unknown-and-scripted)). `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.

### What the panel touches by default

Two detection rungs read the page ([Scope the panel](https://weftgo.dev/docs/observe/devtools/scope/#the-detection-ladder)), 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`.

### Cross-origin writes in setup A

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](https://weftgo.dev/docs/production/security/#setup-a-without-a-token) has the details.

## Handoff

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`):

| Bearer | Answer |
|---|---|
| playground panel token | 303 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 token | 303 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 token | 403 `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".

## Live grants and expiry

`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:

```text
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.

## Best practices & gotchas

- **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](https://weftgo.dev/docs/observe/devtools/install/#when-the-panel-does-not-connect) lists each case. (Source: CHANGELOG.md:61; `studio/web/src/panel/element.ts:2844-2861` `reachLine`)

## See also

- [Secure Studio: tokens, loopback and origins](https://weftgo.dev/docs/production/security/)
- [Install the devtools panel](https://weftgo.dev/docs/observe/devtools/install/)
- [Approve and steer your app's own turns](https://weftgo.dev/docs/observe/devtools/app-turns/)
- [Watch runs live](https://weftgo.dev/docs/observe/studio/live/)
- [Scope the panel to a conversation](https://weftgo.dev/docs/observe/devtools/scope/)

Symbols used: [`studio.Token`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/studio#Token) · [`studio.AllowOrigins`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/studio#AllowOrigins) · [`thread.PublicID`](https://pkg.go.dev/github.com/weftgo/weft@v0.20.2/thread#PublicID)
