Post

One Token Contract, Three Verifiers: Ten of Eleven Bad Tokens Got Through Somewhere

A security review of an AI agent gateway ran seventeen test tokens through the three verifiers of its principal token. Of the eleven tokens the contract says to reject, ten were accepted by at least one service. Here is the test, what each gap means, and how to run the same check on your own system.

One Token Contract, Three Verifiers: Ten of Eleven Bad Tokens Got Through Somewhere

An AI agent gateway attaches a signed principal token to every call it forwards. Three pieces of code verify that token: a reference helper published by the gateway, and the verifiers inside the two services behind it. All three are meant to implement the same contract. I ran seventeen test tokens through all three. Of the eleven tokens the contract says to reject, ten were accepted by at least one verifier. The only one rejected everywhere was a token with the wrong audience.

The panels service accepted a token thirty minutes into a 3600-second lifetime, against a contract that caps lifetime at 60 seconds. It also accepted an ES256 signature where only EdDSA is allowed. The radar service accepted a token whose issuer was "evil", and another with no issuer at all. Each service rejected tokens the other accepted, so neither service’s own tests would have revealed the other’s gaps.

Finding this took no clever attack. It took one test that fed the same tokens to every verifier and compared the answers. Nobody had written that test.

Agent infrastructure makes this worse than a typical web stack does. A delegated agent call crosses several hops, and every MCP server, tool backend and internal API on the way is another verifier of the same token. The chain is only as strict as its loosest verifier, and every new tool adds another one.

TL;DR

  1. Ten of eleven bad tokens got through somewhere. Panels accepted eight tokens the contract says to reject (lifetime, clock skew, algorithm, required claims). Radar accepted four (issuer and required claims). It also rejected two valid tokens of the current shape, plus the stale golden token.
  2. The shared golden test had gone stale. The one golden token predated the current claim set. Both consumers rejected it, so it had stopped testing anything.
  3. The method is short. Write the contract down. Pick a reference verifier. Mint one token per way each claim can be wrong. Run every token through every verifier. Fail the build on any disagreement.
  4. The fix is one verifier, not better copies. Vendor the reference into every consumer, delete the local implementations, regenerate the golden vectors from the current issuer, and run the vectors in CI.

The system

The findings come from a security review of Lookout, an AI agent platform I build and run on my homelab. It spans five repos: lookout-gateway, lookout-radar, lookout-panels, lookout-web and lookout-platform. The review covered HEAD of main in each repo, using static analysis and offline test runs on git archive snapshots. No cluster, no network.

The gateway sits between callers (agents and users) and two upstream services: radar, and panels, which serves MCP tools. On every forwarded call it attaches a principal token in the X-Lookout-Principal header, carrying these claims:

ClaimValue
isslookout-gateway, exact
audexactly one string: radar or panels:<server>
algEdDSA (Ed25519) only
subthe caller: agent:<id> or user:<id>
act{ "sub": "user:<id>" }: the user the caller acts for; absent on a direct user call
principalobject with subject, on_behalf_of, chain, auth_method, token_id, scopes
exp - iatexactly 60 seconds
jtiUUIDv7, present
iatpresent
clock tolerance5 seconds on exp

The token is signed with an Ed25519 key, and verifiers fetch the public key from the gateway’s JWKS endpoint. Three verifiers check it:

VerifierWhat it isLocation
clientReference helper (verify-principal.ts)lookout-gateway/clients/ts/
radarverifyGateway() in radar’s auth middlewarelookout-radar/apps/server/src/auth.ts
panelsmcp() authenticator in panelslookout-panels/packages/shared/src/auth.ts

Radar and panels both started from the reference helper and were then changed independently. The contract itself lived in the helper’s header comment: “only EdDSA, iss must be lookout-gateway, a token older than 60 s is rejected.” Apart from one golden token, there was no shared test.

The test

The harness loads all three verifiers from read-only snapshots of their repos. It generates three keys in process: an Ed25519 key standing in for the gateway, an ES256 key, and a second ES256 key standing in for a SPIRE workload key. All three public keys go into a local JWKS that every verifier is pointed at. The clock is fixed, so the time-dependent vectors are deterministic.

Each vector starts from a correct token and changes exactly one thing. Each verifier is configured the way its service is in production: same audience, same expected issuer. The expected result comes from the contract as written at the time of the review: the reference helper’s header comment and the checks the helper enforces. The table above lists what the gateway sends today, which includes sub and act. The old golden token (G0) predates both claims, and the reference helper still accepts it, so it is marked as accept.

The results

Bold marks a verifier that disagrees with the contract.

IDTokenContractclientradarpanels
V1correct token, as signing.rs emits todayacceptacceptacceptaccept
V2wrong audiencerejectrejectrejectreject
V33600 s lifetime, presented at iat+10rejectrejectrejectaccept
V3b3600 s lifetime, presented 30 min laterrejectrejectrejectaccept
V4iss = "evil", valid signaturerejectrejectacceptreject
V4biss absentrejectrejectacceptreject
V5jti absentrejectrejectacceptaccept
V6iat absentrejectrejectrejectaccept
V7signed with ES256rejectrejectrejectaccept
V86 s past expiryrejectrejectrejectaccept
V8b25 s past expiryrejectrejectrejectaccept
V9principal object absentrejectrejectacceptaccept
V10direct user call (user:owner)acceptacceptrejectaccept
V11same token presented twiceacceptacceptacceptaccept
V12iat 20 s in the futureacceptacceptrejectaccept
P-ISSpanels with its shipped default issueracceptn/an/areject
G0old golden token (no sub or act)acceptacceptrejectreject

Eleven vectors should be rejected. Panels accepted eight of them and radar four; between them, ten got through at least one service. The reference helper matched the contract on all sixteen vectors it was run against. That is expected, since the contract was written from it. The interesting columns are the other two.

What each gap means

Panels does not enforce lifetime (V3, V3b, V8, V8b)

Panels has no check on exp - iat, so it accepts whatever lifetime the issuer writes into the token. A 3600-second token passes at ten seconds and again at thirty minutes. Panels also uses a 30-second clock skew instead of the contract’s 5, so a correct 60-second token stays valid there for 90 seconds.

This matters because replay within the lifetime is accepted by design: V11 passes everywhere. The 60-second cap is the only limit on how long a stolen token stays useful. The token is audience-bound, so it can only be replayed against the service it was minted for, but on panels the replay window is set by whoever issued the token, not by the contract. The dev signer, for example, issues tokens valid for fifteen minutes.

Panels accepts ES256 (V7)

Panels verifies against a ten-algorithm allowlist instead of pinning EdDSA, and it accepted a token signed with an ES256 key from the same JWKS. RFC 8725 §3.1 is explicit that a library must let the caller restrict algorithms and the caller must do it. The gateway only issues EdDSA tokens, so a correctly configured panels never sees anything else. The gap shows up when the configuration is not correct: if LOOKOUT_GATEWAY_PRINCIPAL_JWKS_URL is unset, panels falls back to verifying principal tokens against the SPIRE SVID key set. In that state, a SPIRE-issued JWT with aud=panels:<server> is stopped only by the issuer string and by a regex on the actor ID that happens to reject the / in a SPIFFE ID. The algorithm pin is the check that should have stopped it, and it was not there.

Radar has no issuer check (V4, V4b)

Radar accepted iss = "evil" and a token with no iss at all. It checks the signature and the audience, but not who claims to have issued the token. Its trust is therefore exactly as narrow as its key set: any key that ends up there, whether from a second gateway, a migration or a test environment, can mint tokens radar accepts. RFC 8725 §3.8 covers this case: the verifier should check that the signing key belongs to the issuer the token names. With one gateway and one key set, the gap is latent. It is also the kind of gap nobody notices until the second issuer arrives.

Both consumers skip required claims (V5, V6, V9)

The contract requires jti, iat and the principal object. Panels accepted tokens missing any of the three. Radar requires iat but accepted tokens missing jti or principal.

The principal object carries the delegation chain, the auth method, the token ID and the scopes. A verifier that does not require it cannot base authorization decisions on it, and cannot tell a token from the current issuer apart from one minted by something that only gets the registered claims right.

Radar rejects valid tokens (V10, V12)

Radar rejected a direct call from the owner because it compares the caller against a literal identity string instead of the configured owner. It rejected a token with iat 20 seconds in the future because it allows no clock skew at all. The contract is silent on future iat: the reference helper’s 5-second tolerance applies to exp, and it accepts the token. V12 is marked against radar because it disagrees with the reference, but the vector also exposed a gap in the contract itself, which should say how far ahead of the verifier an issuer’s clock may run. Both radar results are availability bugs, not security gaps, and they have the same cause as the rest: a local reimplementation of a rule defined somewhere else.

Panels rejects tokens under its own default config (P-ISS)

Panels’ base ConfigMap sets the expected issuer to https://lookout-gateway.lookout-gateway.svc. The gateway issues lookout-gateway. Under the shipped default, panels rejects every token the gateway issues today, and every MCP call returns 401. The base config also points at the wrong JWKS host: the gateway Service is named gateway, not lookout-gateway, so the key fetch fails as well.

Nobody noticed, because the homelab overlay overrides both values. This is a deployment bug, not a security finding, but it is the same drift: the base config restates the contract and gets it wrong.

The golden test had stopped testing (G0)

The repo’s golden vector was generated by the issuer before the sub and act claims were added. The reference helper still accepts it. Both consumers reject it. So the one shared fixture described a token the gateway no longer issues, and passing it said nothing about whether the verifiers agree on the tokens it does issue.

How serious it was

The review found nine issues: one critical, two high, four medium and two low. The critical one was the shared dev signer: it issued a JWT-SVID for any identity, and a principal token for any agent, to any caller who could reach it, and the homelab overlays trusted it. The two high findings were a gateway namespace with no network policy and an owner login that needed no credential.

The verifier gaps were rated medium. While the dev signer was open, anyone could mint a fully valid token, so a lax verifier gave an attacker little they did not already have. With the signer restricted and a single issuer and key set, none of the gaps is directly exploitable. They are latent: each one waits for a second key, a longer-lived issuer or a stolen token.

The review also recorded 43 things that held up: exact audience matching everywhere, alg: none and HMAC refused, expired tokens rejected, JWKS failures rejected, unknown kid rate-limited, no wildcard users, no public access, delegation that narrows rather than widens, shape-checked admin grant writes, and a gateway that refuses to start on a model mismatch. The verifiers were not careless. Each was mostly right, in a different way.

Why the copies drift

Nothing in the setup kept the three verifiers equal. The contract was a comment in one file. Each consumer had its own verification code and its own tests, and those tests checked each consumer against itself. The only shared fixture had gone stale. Every individual change could be reasonable and the system would still end up with three contracts.

The gaps fall into predictable groups: defaults left in place (30-second skew, a broad algorithm allowlist), checks that only matter once a second issuer exists (iss), and claims added to the issuer after a consumer was written (sub and act, as the golden token shows).

Agent systems multiply this. Panels is an MCP server, and every MCP server and tool backend an agent reaches through a delegation chain is another verifier of the same token, usually owned by a different team. The July MCP revision makes this worse in a specific way: it moved issuer validation and several other checks out of the protocol and into each implementer’s code, and the official Python SDK’s 2.x releases ran their issuer check on only one of two discovery paths. The same shape appears outside identity, too. Perplexity’s Secure Intelligence Institute tested ten third-party sandbox platforms that offer hostname- or domain-based egress controls and found “at least one network-policy bypass in eight of the ten” (Escaping SPACE: Part I). Ten implementations of one policy, eight with a gap.

The method

This is concrete enough to run on your own system.

1. Write the contract down

One document, cited by every service. For Lookout it has this shape:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1. Parties and identities
   - Who issues tokens, who verifies them, what SPIFFE IDs they use

2. JWT-SVID (workload to workload)
   - alg, kid, iss, aud, sub, exp, max lifetime, failure behaviour

3. Actor header (REST)
   - X-Lookout-Actor: value, who sends it, who accepts it

4. Principal token (gateway to upstream)
   - alg, typ, kid, iss, aud, sub, act, principal object,
     exp - iat cap, iat required, jti required, clock skew,
     JWKS URL, key rotation, failure behaviour

5. One verifier, one set of vectors
   - The reference verifier implementation
   - The golden vectors generated from it

6. Dev mode
   - When the dev signer is allowed, what it can issue, what it cannot

If the code disagrees with the document, the code is wrong.

2. Pick the reference verifier

Use the issuer’s own verifier if it has one, or the most complete consumer. In Lookout that was verify-principal.ts, because it implemented every claim. The reference changes only through a contract review.

3. Enumerate the vectors

For every claim, mint a token where it is absent, where it has a wrong value, and where it sits just past each limit (expiry, lifetime cap, skew). Then add the valid-but-unusual cases that a strict verifier tends to break: direct user calls, replay within the lifetime, clock skew in both directions. Finally, add one vector per consumer running its shipped default config, which is how P-ISS was found.

Each vector changes exactly one thing from a correct token. If it changes two, a rejection does not tell you which check fired.

4. Mint the tokens

Use one in-process key set and a fixed clock. You do not need the issuer’s real key: the test is about verifier behaviour. Include at least one key the verifiers must not trust for this token type, such as a different algorithm, so that algorithm and key-selection checks have something to reject.

5. Run every vector through every consumer

Load each verifier from a read-only snapshot of its repo, not from a copy you have edited. Configure it the way the service is configured in production. Record accept or reject.

6. Fail on any disagreement

A disagreement in either direction is a finding. False accepts are security gaps; false rejects are outages waiting for a clock to drift.

Here is a runner skeleton using jose. Each consumer gets a small adapter that imports its real verifier, passes it the production settings, and maps the outcome to "accept" or "reject". The adapters are the only part you write per service.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// vector-runner.mts: run principal-token vectors against every verifier.
// Run: npx tsx vector-runner.mts
import { SignJWT, generateKeyPair, exportJWK, createLocalJWKSet } from "jose";
import { randomUUID } from "node:crypto";
import { consumers } from "./adapters.mts";

type Verdict = "accept" | "reject";
type Alg = "EdDSA" | "ES256";

// Keys: the gateway's Ed25519 key, plus an ES256 key it must never accept.
const ed = await generateKeyPair("EdDSA", { crv: "Ed25519" });
const ec = await generateKeyPair("ES256");
const jwks = createLocalJWKSet({
  keys: [
    { ...(await exportJWK(ed.publicKey)), kid: "gw", alg: "EdDSA", use: "sig" },
    { ...(await exportJWK(ec.publicKey)), kid: "other", alg: "ES256", use: "sig" },
  ],
});

const NOW = 1_800_000_000; // fixed clock, in seconds

const base = (aud: string) => ({
  iss: "lookout-gateway",
  aud,
  sub: "agent:a1",
  act: { sub: "user:u1" },
  principal: {
    subject: "agent:a1",
    on_behalf_of: "user:u1",
    chain: ["user:u1", "agent:a1"],
    auth_method: "oidc",
    token_id: "t1",
    scopes: ["read"],
  },
  iat: NOW,
  exp: NOW + 60,
  jti: randomUUID(), // the contract wants UUIDv7; use a v7 generator if you check it
});

const without = (o: Record<string, unknown>, k: string) => {
  const { [k]: _, ...rest } = o;
  return rest;
};

const sign = (claims: Record<string, unknown>, alg: Alg = "EdDSA") =>
  new SignJWT(claims)
    .setProtectedHeader({ alg, kid: alg === "EdDSA" ? "gw" : "other", typ: "JWT" })
    .sign(alg === "EdDSA" ? ed.privateKey : ec.privateKey);

// One claim changed per vector. `at` is when the token is presented.
const vectors: Array<{
  id: string;
  what: string;
  expect: Verdict;
  claims: (aud: string) => Record<string, unknown>;
  alg?: Alg;
  at?: number;
}> = [
  { id: "V1", what: "correct token", expect: "accept", claims: base },
  { id: "V2", what: "wrong audience", expect: "reject", claims: () => base("someone-else") },
  { id: "V3", what: "3600 s lifetime", expect: "reject", claims: (a) => ({ ...base(a), exp: NOW + 3600 }), at: NOW + 10 },
  { id: "V4", what: "issuer = evil", expect: "reject", claims: (a) => ({ ...base(a), iss: "evil" }) },
  { id: "V4b", what: "issuer absent", expect: "reject", claims: (a) => without(base(a), "iss") },
  { id: "V5", what: "jti absent", expect: "reject", claims: (a) => without(base(a), "jti") },
  { id: "V7", what: "signed with ES256", expect: "reject", claims: base, alg: "ES256" },
  { id: "V8", what: "6 s past expiry", expect: "reject", claims: base, at: NOW + 66 },
  // ...one entry per vector in your enumeration
];

// consumers: Record<name, { audience: string;
//   verify(token: string, jwks: JWKS, nowSeconds: number): Promise<Verdict> }>
let failures = 0;
for (const v of vectors) {
  const cells: string[] = [];
  for (const [name, c] of Object.entries(consumers)) {
    const token = await sign(v.claims(c.audience), v.alg);
    const got = await c.verify(token, jwks, v.at ?? NOW + 1);
    if (got !== v.expect) failures++;
    cells.push(`${name}=${got === v.expect ? got : `**${got}**`}`);
  }
  console.log(`${v.id.padEnd(4)} expect=${v.expect.padEnd(6)} ${cells.join(" ")}  ${v.what}`);
}
process.exit(failures ? 1 : 0);

If a verifier reads Date.now() directly instead of taking a clock, fake the timer in its adapter (for example with @sinonjs/fake-timers) rather than editing the snapshot. The point is to test the code the service actually runs.

The fix

Stop maintaining copies. Vendor the reference verifier into every consumer, delete the local implementations, regenerate the golden vectors from the current issuer, and run the vectors in each consumer’s CI.

For Lookout, the review recommended:

  • radar: vendor the helper (adds the iss check and 5 s tolerance), and accept the configured owner identity instead of a literal.
  • panels: vendor the helper (adds the EdDSA pin, lifetime cap, iat, jti and 5 s tolerance), remove the SVID-key fallback, fix the issuer and JWKS host in the base config, and restrict the actor header.
  • gateway: publish the extended helper and regenerated vectors (one per audience form, from the current signing.rs), pick the SVID audience name, and pass an OpenFGA token.

The fixes landed on 12 November. Radar now checks the issuer and jti with a 5-second tolerance. Panels enforces the principal token contract. The golden vectors are generated from the signer, and the gateway’s base config matches what radar, panels and web expect. On the same day the rest of the chain was tightened: the dev signer now mints only the web and gateway SPIFFE IDs and changes its key IDs with its keys, the gateway namespace is isolated with default-deny network policies, and OpenFGA runs on Postgres with a preshared key.

The takeaway

Three verifiers of one token, each written from the same helper, ended up enforcing three different contracts. Ten of eleven bad tokens got through at least one of them. No individual verifier’s test suite could have caught that, because each suite only compared a verifier against itself.

Better tests for each copy will not fix it. One verifier, one written contract and one set of vectors run against every consumer in CI will. It takes about a day to build and about a minute to run.

If you run an agent gateway, run the vectors against your own verifiers. The results will tell you which service implements which subset of the contract, and which gaps are live vulnerabilities and which are waiting for a second issuer.

If you want a quick read on your own agents against the OWASP Agentic Top 10, the Agent Security Scorecard takes about twelve minutes. If you run an agent gateway and want help testing your token verification, get in touch.


References

Token contract and verification

Contract and conformance testing

The same pattern at other layers

AI agent identity

My own work referenced

The Security Lab Newsletter

This post is the article. The newsletter is the lab.

Subscribers get what doesn't fit in a post: the full attack code with annotated results, the measurement methodology behind the numbers, and the week's thread — where I work through a technique or incident across several days of testing rather than a single draft. The RAG poisoning work, the MCP CVE analysis, the red-teaming patterns — all of it started as a newsletter thread before it became a post. One email per week. No sponsored content. Unsubscribe any time.

Join the lab — it's free

Already subscribed? Browse the back-issues →

This post is licensed under CC BY 4.0 by the author.