On-ramp · Lesson 04
An API token is a password with a label
An engineer pastes a curl command into a ticket to show a failing call. It includes -H 'Authorization: Bearer acmepay_live_…'. The ticket system indexes it; the token is now readable by everyone who can search tickets, and works until someone notices. The prefix is a fictional service's, but the habit is real: many providers start their keys with a fixed string naming the service and whether the key is live, which is what lets a secret scanner recognise a leaked key in a ticket, a log or a commit.
What it is
An API token is a string a server accepts in place of a login. The client presents it on each request; the server looks it up (an opaque token) or verifies a signature on it (a self-contained one, lesson 8) and learns who is calling and what they may do. In HTTP it travels in the Authorization header as Bearer <token> (RFC 6750, 2012). Bearer is the operative word: whoever bears it is let in. There is no second factor, no check that the sender is the person it was issued to.
The first lesson's server returned the token it was given, in auth. Anything that logs headers, a debugging proxy, an error report or a curl -v pasted into chat holds a working credential.
Where a token must not go
| Place | Why not |
|---|---|
The URL's query string (?token=…) |
it lands in access logs, browser history and Referer headers; RFC 6750 (section 5.3) says they should not be passed in page URLs |
| A prompt or a tool result | the model can repeat it to whoever the next turn's text reaches |
| A log line or trace | logs outlive tokens and are read by more people |
| A repository | forever, in history |
| A tool call's arguments | it is then in the record the gateway stores (Module 3, lesson 1) |
Tokens belong in the Authorization header, set by code that the model cannot write.
Four properties that bound the damage
- Audience: which server accepts it (lesson 8). A token for one server should be useless at another.
- Scope: what it permits there (
crm:read, notcrm:*). - Lifetime: minutes, not months. A leaked token that expired is a log entry, not an incident.
- Subject: whom it names, so the log can say who did the thing.
A long-lived, all-scopes, all-audience, anonymous-subject key is a static secret; the whole of Module 12 is about not handing one to an agent.
Expert: revocation, rotation and binding a token to a key
Rotation replaces a token on a schedule; revocation kills one now. A self-contained token cannot be un-issued: a server that only verifies the signature will accept it until exp. Revocation therefore needs either a short lifetime (the course uses five minutes), a server-side list consulted on use, or an introspection call (RFC 7662). Each has a cost per request; Module 12 measures it.
The other remedy attacks the word bearer itself. A sender-constrained token is bound to a key the client holds: with mutual TLS the token names the client certificate's thumbprint (RFC 8705), and with DPoP the client signs a fresh proof, covering the method, the URL and a timestamp, with the private key whose public half the token names (RFC 9449, 2023). A stolen token is then useless without the key. The protection moves rather than vanishes: a client whose key sits in the same process memory as the token loses both to one compromise, and every resource server must check the proof, or the binding is decoration.
Check yourself
- Name two places in a typical agent stack, apart from the URL, where an
Authorizationheader could be logged without anyone choosing to log it. - A token has a one-year life, scope
*, no audience. Which of the four properties would you tighten first, and what does that change about a leak? - Why does "the model never sees the token" matter, if the model is not the one who leaks it?
Answers
- An error report or crash dump that attaches the failing request, headers and all; and a tool or service that echoes the request back, as lesson 1's server did with
auth, which puts the token into the tool result, the model's context and every record the gateway keeps of that result. Debugging proxies and traces that record headers by default do the same. - Lifetime first: from a year to minutes. Every other property bounds what a leaked token can do; lifetime bounds for how long, and a leak of a token that has already expired is a log entry, not an incident. Audience and scope come next, because a short-lived
*token is still a skeleton key while it lives. - Because the model's output is steered by whoever writes text into its context. A token the model can see is one an injected instruction can have it copy into a tool argument, an e-mail or an answer; the model needs no motive to be the channel. A token set in the header by code the model cannot write is out of reach of every prompt.