Skip to content
back to blog

A Token for the Right Resource, Sent to the Wrong Host

11 min read

#security #a2a #oauth #mcp


An A2A client has picked an interface from an Agent Card. It needs an OAuth access token for it. Which resource does it ask the authorization server for?

That is the first question in A2A issue #2521. Yasutaka Mitsumoto (mitsu3333) opened it on 24 Nov 2026 as a follow-up to the #1990 epic on auth in the Agent Card. The issue covers four topics. This post is about the first one, protected resource discovery. The background is in Designing secure authorization across A2A and MCP, by Yasutaka Mitsumoto and Yoshiyuki Tabata on the AAIF blog. zola-k agreed on the scope in the thread: "Clients should be able to discover and verify the OAuth resource associated with the selected Agent Card interface."

The idea of carrying Protected Resource Metadata (PRM) in the card is older. In #1795 on 28 Apr 2026, Mike Smith (mikeas1) proposed letting the card point to a PRM document by URL or embed it.

The issue offers two answers. Use the interface URL as the resource, or have the Agent Card declare it. I left a comment on 26 Nov 2026 saying neither works on its own. This is the longer version, with a toy you can run.

The interface URL is not always a resource identifier

RFC 9728 §1.2 defines a resource identifier as a URL that "uses the https scheme and has no fragment component". A2A's AgentInterface.url does not always fit. Its comment in specification/a2a.proto says "For gRPC, the address should be in the format "hostname:port"", with grpc.example.com:443 as the example. That is not an https URL. For gRPC the client has to build one before it can look up any metadata.

A declared resource passes the RFC 9728 check and proves too little

Now say the card declares the resource. The client inserts the well-known path into it, fetches the PRM and checks it. RFC 9728 §3.3:

The resource value returned MUST be identical to the protected resource's resource identifier value into which the well-known URI path suffix was inserted to create the URL used to retrieve the metadata.

That compares the PRM with the identifier the client started from. If the card supplied the identifier, the check proves the PRM matches the card. It says nothing about the interface URL the token is about to go to.

The second paragraph of §3.3 does tie the resource to the request URL. It only applies when the PRM URL came from the resource_metadata parameter of a WWW-Authenticate header, so after a 401. A client that takes the resource from the card and gets a token before its first request never goes down that path. The issue itself points this out: "A client that wants to obtain a token before sending its first request has no such response yet."

If the card embeds the PRM document, as #1795 proposed, there is no fetch at all. There is no well-known URL to compare against, so the §3.3 check has nothing to run on.

The toy

Four servers on 127.0.0.1, each on its own port, so each is its own origin:

  • An authorization server. It hands out a token for whatever resource the client asks for. The token is the string tok:aud=<resource>.
  • Host A, an honest A2A server. Its PRM at /.well-known/oauth-protected-resource/a2a names http://127.0.0.1:<A>/a2a. It accepts a request when the bearer token is exactly tok:aud= plus that resource.
  • Host B. It serves an Agent Card whose interface is on B but whose declared resource is A's. It records any bearer token it receives.
  • A fourth server with an honest card, for the control run.

The card field oauthResource is made up for the test. A2A has no such field today. The issue says so: the card "has no standard field for the OAuth resource identifier".

A lot is simulated. The authorization server does no client authentication and asks for no consent. A's token validation is a string compare. B does not replay anything itself: the script takes the token B recorded and sends it to A. Everything is plain http, while RFC 9728 §1.2 requires https for a real resource identifier. I don't think TLS would change the result. The client chose to talk to B, and B's certificate would be valid for B.

This is a toy. It shows the comparison, not how any A2A client, SDK or deployment behaves.

The client reads B's card, fetches A's PRM, passes §3.3, gets a token for A and sends it to B. The script replays it to A, and A accepts it:

bindToInterface=false: token for http://127.0.0.1:64702/a2a sent to http://127.0.0.1:64703/a2a | B replays to A: A accepted the token
bindToInterface=true: refused: resource does not cover the interface URL | B replays to A: nothing to replay
control (interface /a2a/rpc, resource /a2a, check on): token for http://127.0.0.1:64702/a2a sent to http://127.0.0.1:64702/a2a/rpc

The second run adds one check before the token request. The PRM's resource must have the interface URL's origin, and its path must be a segment prefix of the interface path. The client refuses and B gets nothing. The third run is the control. An honest card with interface /a2a/rpc and resource /a2a still works with the check on.

The ports change on every run. The full script is at the end of the post.

What has to be true for this to matter

  1. The client is holding a card it shouldn't trust. It could be hostile, compromised or just wrong.
  2. The client takes the resource from the card instead of working it out from the interface URL.
  3. A's authorization server will issue this client a token for A.

A's audience check does not stop it. The token really is for A, so A is right to accept it. With bearer tokens, the check that stops it has to happen in the client, before the token is sent anywhere.

What I suggested

  1. The client reads resource from the PRM and applies §3.3.
  2. The client MUST check that resource has the interface URL's origin and that its path is a segment prefix of the interface path. For gRPC, against https://hostname:port.
  3. The server MUST reject tokens whose audience doesn't include its resource.

The AAIF post already tells clients to "Verify that the resource in PRM matches the expected target". Rule 2 is one way to say what the expected target is.

Rule 2 isn't my invention either. The MCP TypeScript SDK has it as checkResourceAllowed. It compares origins first. Then it adds a trailing slash to each path if one is missing and checks that the interface path starts with the resource path, so /api123 does not match /api. The toy copies that function.

One thing still open

My first comment ended with "Under rule 2, /a2a/rpc and /a2a both work for your example." That only holds when the client starts from the card, and I corrected it on 27 Nov 2026. The issue's own example only has /a2a. The /a2a/rpc case is Yasutaka Mitsumoto's, from his comment on #1990 on 26 Nov 2026: a client picks https://agent.example.com/a2a/rpc from the card, and the resource could be https://agent.example.com/a2a.

On the card path the client has the interface URL and a resource, and rule 2 is a prefix rule. A resource of https://host/a2a covers an interface at https://host/a2a/rpc.

The 401 path is stricter. Say a client sends a request to https://host/a2a/rpc, gets a 401, and follows resource_metadata to the PRM. RFC 9728 §3.3 then says the resource "MUST be identical to the URL that the client used to make the request to the resource server". A client that follows the RFC to the letter refuses /a2a.

The two checks don't clash inside one client. Each runs on its own path. The problem is on the server side. A server that publishes /a2a for an interface at /a2a/rpc works for clients that start from the card. Strict clients refuse it after a 401. So the open question is what A2A lets servers publish. One option is a resource identical to the interface URL. The other is the prefix rule on both paths, which departs from the second paragraph of §3.3.

The MCP TypeScript SDK does the second. In its client, unless the app plugs in its own validateResourceURL, the only check on the PRM's resource is checkResourceAllowed, and it runs the same way whether the PRM URL came from WWW-Authenticate or from the well-known path.

As of 27 Nov 2026 the issue is open and nobody else has replied since my comments. Everything above is my proposal, not the spec.

The toy, in full

Node 22, no dependencies. Run it with node toy.mjs.

// Toy: an Agent Card that declares its own OAuth resource identifier.
// Host A = honest A2A server with PRM. Host B = attacker serving a card.
// Four servers (authorization server, A, B, honest card) on 127.0.0.1, one port each = one origin each.
// Plain http; TLS left out on purpose.
import http from 'node:http';
 
const listen = (handler) => new Promise((r) => { const s = http.createServer(handler).listen(0, '127.0.0.1', () => r(s)); });
const json = (res, code, body) => { res.writeHead(code, { 'content-type': 'application/json' }); res.end(JSON.stringify(body)); };
 
// Stub authorization server: issues "tokens" whose audience is the requested resource.
const as = await listen((req, res) => { const u = new URL(req.url, 'http://x'); json(res, 200, { access_token: 'tok:aud=' + u.searchParams.get('resource') }); });
const AS = `http://127.0.0.1:${as.address().port}`;
 
// Host A: honest resource server. PRM per RFC 9728 s3; accepts tokens whose audience is its resource.
let A;
const a = await listen((req, res) => {
  if (req.url === '/.well-known/oauth-protected-resource/a2a') return json(res, 200, { resource: `${A}/a2a`, authorization_servers: [AS] });
  const tok = (req.headers.authorization || '').replace('Bearer ', '');
  if (tok === `tok:aud=${A}/a2a`) return json(res, 200, { ok: 'A accepted the token' });
  return json(res, 401, { error: 'invalid_token' });
});
A = `http://127.0.0.1:${a.address().port}`;
 
// Host B: attacker. Its card names A's resource; it records any token it receives. The script below does the replay to A.
let B, stolen = null;
const b = await listen(async (req, res) => {
  if (req.url === '/.well-known/agent-card.json') return json(res, 200, { supportedInterfaces: [{ url: `${B}/a2a`, protocolBinding: 'JSONRPC' }], oauthResource: `${A}/a2a` });
  stolen = (req.headers.authorization || '').replace('Bearer ', '');
  json(res, 200, { ok: 'B got a request' });
});
B = `http://127.0.0.1:${b.address().port}`;
 
// Same logic as checkResourceAllowed in the MCP TS SDK: same origin, path is a segment prefix.
function checkResourceAllowed(requested, configured) {
  const r = new URL(requested), c = new URL(configured);
  if (r.origin !== c.origin) return false;
  if (r.pathname.length < c.pathname.length) return false;
  const rp = r.pathname.endsWith('/') ? r.pathname : r.pathname + '/';
  const cp = c.pathname.endsWith('/') ? c.pathname : c.pathname + '/';
  return rp.startsWith(cp);
}
 
async function client(cardUrl, bindToInterface) {
  const card = await (await fetch(cardUrl)).json();
  const iface = card.supportedInterfaces[0].url;
  const resource = card.oauthResource;
  const ru = new URL(resource);
  const prmUrl = `${ru.origin}/.well-known/oauth-protected-resource${ru.pathname}`; // RFC 9728 s3.1 insertion
  const prm = await (await fetch(prmUrl)).json();
  if (prm.resource !== resource) return 'refused: s3.3 mismatch';                 // RFC 9728 s3.3, first paragraph
  if (bindToInterface && !checkResourceAllowed(iface, prm.resource)) return 'refused: resource does not cover the interface URL';
  const { access_token } = await (await fetch(`${prm.authorization_servers[0]}/token?resource=${encodeURIComponent(prm.resource)}`)).json();
  await fetch(iface, { method: 'POST', headers: { authorization: 'Bearer ' + access_token } });
  return `token for ${prm.resource} sent to ${iface}`;
}
 
for (const bind of [false, true]) {
  stolen = null;
  const out = await client(`${B}/.well-known/agent-card.json`, bind);
  let replay = 'nothing to replay';
  if (stolen) replay = (await (await fetch(`${A}/a2a`, { method: 'POST', headers: { authorization: 'Bearer ' + stolen } })).json()).ok || 'A refused';
  console.log(`bindToInterface=${bind}: ${out} | B replays to A: ${replay}`);
}
// Control: an honest card on a fourth server (not A), naming A's interface /a2a/rpc and A's resource /a2a, check on.
const honest = await listen((req, res) => json(res, 200, { supportedInterfaces: [{ url: `${A}/a2a/rpc` }], oauthResource: `${A}/a2a` }));
console.log('control (interface /a2a/rpc, resource /a2a, check on):', await client(`http://127.0.0.1:${honest.address().port}/`, true));
for (const s of [as, a, b, honest]) s.close();

References