You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 240672f
Browse filesBrowse the repository at this point in the historyBrowse files
docs(auth): flag threads/events and threads/state as unscoped
The revised thread-authorization section claimed the Intelligence runtime
scopes every thread-bearing route to the resolved user. It does not.
handleGetThreadEvents and handleGetThreadState resolve the caller through
identifyUser and then discard the result, calling getThreadEvents({
threadId }) / getThreadState({ threadId }). The platform client takes no
userId on either method — both hit project-authenticated _inspect
endpoints — so any caller identifyUser accepts can read the event log and
agent state of any thread in the project given its id.
Replace the blanket guarantee with a per-route table, and document the
onBeforeHandler guard narrowed to those two routes so the Intelligence
path is not told there is nothing to build.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Copy file name to clipboardExpand all lines: showcase/shell-docs/src/content/docs/auth.mdx
+37-7Lines changed: 37 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -450,12 +450,12 @@ Verifying *who* the caller is doesn't yet stop them reaching *someone else's con
450
450
451
451
| Runtime | Who scopes threads to a user |
452
452
| --- | --- |
453
-
|`CopilotRuntime` with `intelligence`|The runtime does, via [`identifyUser`](#the-intelligence-platform-scopes-threads-for-you). |
453
+
|`CopilotRuntime` with `intelligence`|Mostly the runtime, via [`identifyUser`](#the-intelligence-platform-scopes-most-thread-routes) — with two inspector routes you still have to guard. |
454
454
| Anything else — SSE runtime, custom store, local in-memory runner | You do. See [Scope threads yourself](#scope-threads-yourself). |
455
455
456
-
### The Intelligence Platform scopes threads for you
456
+
### The Intelligence Platform scopes most thread routes
457
457
458
-
The Intelligence runtime requires an `identifyUser` callback — construction throws without one (or without at least one Channel). It runs on the server, once per request, and the id it returns is what the runtime passes to the platform on every thread-bearing route:
458
+
The Intelligence runtime requires an `identifyUser` callback — construction throws without one (or without at least one Channel). It runs on the server, once per request, and the id it returns is the scope the runtime hands to the platform:
@@ -470,9 +470,39 @@ const runtime = new CopilotRuntime({
470
470
});
471
471
```
472
472
473
-
That resolved id is applied to `agent/run`, `agent/connect`, the thread message, event, and state reads, `threads/update`, `threads/archive`, `threads/delete`, and the token minted for the thread subscription. `threads/list`is scoped by the resolved user *and* filtered by `agentId`, so `useThreads` returns the caller's threads rather than every thread in the project.
473
+
Every route resolves the caller this way, so an unauthenticated request is rejected everywhere. What differs is whether the resolved id is then *carried to the platform* as a scope:
474
474
475
-
So on this path there is no ownership table to build. What you own is `identifyUser` itself:
475
+
| Route | Scoped to the resolved user? |
476
+
| --- | --- |
477
+
|`agent/run`, `agent/connect`| Yes |
478
+
|`threads/list`| Yes — and filtered by `agentId`, so `useThreads` returns the caller's threads rather than the project's |
479
+
|`threads/messages`| Yes |
480
+
|`threads/update` (rename via `PATCH`, delete via `DELETE`), `threads/archive`| Yes |
481
+
| Thread subscription token | Yes |
482
+
|`threads/events`, `threads/state`|**No** — see the callout below |
483
+
484
+
<Callouttype="warn"title="`threads/events` and `threads/state` are not user-scoped">
485
+
These two routes back the [inspector](/inspector). Both resolve the caller through
486
+
`identifyUser` and then discard the result, reading the thread by id alone — the runtime
487
+
calls the platform's project-authenticated `_inspect` endpoints, which take no user
488
+
parameter. Any caller `identifyUser` accepts can read the full event log and current agent
489
+
state of any thread in the project, given its `threadId`.
490
+
491
+
Guard them yourself until the platform scopes them. The `onBeforeHandler` pattern below
492
+
applies on the Intelligence path too, narrowed to these two routes:
493
+
494
+
```ts
495
+
onBeforeHandler: async ({ route }) => {
496
+
if (route.method!=="threads/events"&&route.method!=="threads/state") return;
497
+
498
+
// Neither route is scoped platform-side. Reject outright unless you keep an
499
+
// ownership record of your own to check `route.threadId` against.
500
+
thrownewResponse("Not found", { status: 404 });
501
+
},
502
+
```
503
+
</Callout>
504
+
505
+
For everything in the Yes rows there is no ownership table to build. What you own is `identifyUser` itself:
476
506
477
507
-**Derive the id from a server-verified credential.** The callback receives the raw `Request`; whatever it returns is trusted from there on. Reading a user id straight out of a header or request body hands every caller the ability to name themselves.
478
508
-**Return a stable id.** It is the key threads hang off. Change it — swapping an email for a subject claim, say — and that user's existing threads stop resolving.
@@ -488,7 +518,7 @@ See [Scope Rich Threads to the signed-in user](/threads-lifecycle#scope-rich-thr
488
518
489
519
### Scope threads yourself
490
520
491
-
Without the Intelligence Platform there is no server-side binding between a `threadId` and a user. A `threadId` is just an opaque id travelling in a request: if user A learns user B's, every thread route accepts it. The rest of this section is the pattern for a custom store, a plain SSE runtime, or the local in-memory runner.
521
+
Without the Intelligence Platform there is no server-side binding between a `threadId` and a user. A `threadId` is just an opaque id travelling in a request: if user A learns user B's, every thread route accepts it. The rest of this section is the pattern for a custom store, a plain SSE runtime, or the local in-memory runner — and it's also what you narrow to `threads/events` and `threads/state` if you *are* on the platform.
492
522
493
523
#### Own the mapping
494
524
@@ -567,7 +597,7 @@ Filter server-side. Hiding rows in the UI leaves the underlying route open.
567
597
568
598
-**Always validate** the token on the backend. Never trust the frontend's claim.
569
599
-**Scope every read and write** to the resolved user. Auth context only matters if you actually use it to filter data.
570
-
-**Bind threads to a user.** On the Intelligence Platform that means a correct `identifyUser`; off it, an ownership check on every thread route rather than only at login. See [Thread authorization](#thread-authorization).
600
+
-**Bind threads to a user.** On the Intelligence Platform that means a correct `identifyUser`, plus your own guard on `threads/events` and `threads/state`; off it, an ownership check on every thread route rather than only at login. See [Thread authorization](#thread-authorization).
571
601
-**Don't log raw tokens.** Log the resolved user id (or `anonymous`) instead.
572
602
-**Use HTTPS in production.** The Bearer token is sensitive.
573
603
-**Refresh strategy.** Your frontend is responsible for rotating expired tokens before they reach the agent. CopilotKit doesn't refresh on your behalf.
0 commit comments