Repository navigation
Conversation
An enforcement point reads the method and the tool name of an MCP
request, and the backend then reads the same bytes with its own parser.
encoding/json matches object keys without regard to letter case and
keeps the last member that matches, so a body such as
{"method":"tools/call","params":{"name":"drop_table"},"METHOD":"ping"}
was a handshake to the enforcement point and a call of drop_table to a
Python or Node backend. On such a backend, a task credential narrowed
with allowed_tools could call any tool of the service. "PARAMS", and
"NAME" inside params, had the same effect.
InspectJSONRPCMCPBody now reads the object member by member. A body
that is not one JSON object, or that states method, params or the tool
name in another letter case, names no tool and no handshake method, so
a rule with allowed_tools denies it. A member stated twice is refused
too, because parsers do not agree on which one they keep. This covers
the node's libp2p-http and external ingress paths, the router ingress
and the Envoy ext_authz and ext_proc servers, which all call this
function.
The task check on a /mesh/mcp stream read params.name in the same way.
It now uses the same reader (api.MCPToolCallName), answers a tools/call
that does not name one tool with JSON-RPC -32602, and logs the refusal.
This is the fix for GHSA-g9hr-vm84-pjjr.
The stdio bridge serves a command-backed MCP service over HTTP. It wrote
the body of a message with no id to the stdin of the backend as it came.
JSON allows a line break between two tokens, and a stdio MCP server
reads one message per line, so the body
{"jsonrpc":"2.0","method":"notifications/cancelled","params":
{"jsonrpc":"2.0","id":7,"method":"tools/call","params":{"name":"drop_table","arguments":{}}}
}
was one notification to the enforcement point and three lines to the
backend. A task rule with allowed_tools allows notifications/cancelled,
and the official Python MCP SDK stdio server ran the tools/call on the
second line. The previous commit does not stop this body: it states
each member once and in lower case.
writeBackend is the one function that writes to the stdin of the
backend. It now compacts the message (json.Compact) before the write.
Valid JSON holds a line feed or a carriage return only between two
tokens, so the backend gets one line for one message. Python reads
stdin in universal newlines mode and ends a line at a carriage return
too, so a test covers both.
A call was not affected: the bridge encodes it again with json.Marshal,
which compacts it. A call now passes through the same step, and a test
holds that path to one line.
Limits: the fix removes line breaks. It does not read the params of a
notification, so the hidden call still reaches the backend as data
inside the one line. A /mesh/mcp stream to a command-backed service
does not use the bridge. There the MCP go-sdk encodes each message
again and writes one line.
This completes the fix for GHSA-g9hr-vm84-pjjr.
On a /mesh/mcp stream, authorizeMCPRequest returned before any task check for a message with no id. Under a task-scoped credential, a tools/call with no id went to the backend with no check of its tool, and the default deny for other methods did not apply. A server must not run a request that has no id. The three official MCP SDK servers do not, so this is hardening and not a known bypass. A backend on a generic JSON-RPC library can run it. When the credential carries task rules, the node now sends a message with no id to the backend only when its method starts with "notifications/". JSON-RPC forbids an answer to a message with no id, so the node drops any other one, writes no response, and logs a warning with the service, the method and the peer. The stream stays open. Before, the MCP go-sdk backend of the test refused such a message and the node closed the stream. Limits: a credential with no task rules behaves as before. A notification is still not checked against the task rules. The HTTP paths are not changed: they check a tools/call with or without an id.
The Envoy ext_authz and ext_proc servers took the tool of an MCP tools/call from an X-Mesh-Mcp-Tool request header when the request had one, and did not read the body. A client can set any request header. A caller with a credential narrowed to allowed_tools sent the header with an allowed tool and a body that calls another tool, and the check allowed it. ext_proc did not ask Envoy for the body of such a request. It also did not ask for it on a path such as /mesh/MCP/<service>, because it matched the route with exact letter case. The servers now put the tool in a CheckInput field that only the body sets, on HTTP ext_authz, gRPC ext_authz and ext_proc. The header has no meaning and its constant is gone. ext_proc asks for the body of every POST to an MCP service and ignores letter case in the route. An ext_authz check for a POST with no body was allowed as a handshake, so a gateway that does not send the body to ext_authz did not enforce allowed_tools at all. Such a check now names no tool and is not a handshake: a rule with allowed_tools refuses it. A GET and a DELETE carry no call and are decided for the service alone. An ext_authz filter must set with_request_body to pass a tools/call from a credential with allowed_tools. The Envoy configuration of the e2e test now sets it. Limit: ext_proc decides on the body only when Envoy applies its mode override (allow_mode_override: true). The documentation now says so. This is the fix for GHSA-qp8f-gxq7-x6h9.
The node serves Envoy ext_authz (HTTP, gRPC v3 and v2) and ext_proc on its local API with no gate. For an egress:// destination that the node serves with a credential, the answer carried that credential in the Authorization header. The node could not tell the gateway from any other local caller. An application with a task Biscuit that allows only GET /repos/acme/* on egress://api.github.com received the secret of the node, and could then use it for any request. The documentation says that the agent never holds this credential. The node now returns the upstream credential only when the transport authenticates the caller: the Unix socket, or TLS with a verified client certificate. This is the rule that the identity evidence routes apply. It is now one function, fromTrustedTransport, and both callers use it. The API token is not sufficient, because applications hold it. The gateway server evaluates the rule on the HTTP request and gives the result to the evaluator in CheckInput.TrustedTransport. The HTTP entry point reads it from the request. For gRPC, ServeGRPC stores it in the request context, and grpc.Server.ServeHTTP derives the context of Check and Process from that context. A server with no rule trusts no transport. On any other transport the node refuses a check that would return the upstream credential. It answers 403 and logs a warning with the target, the caller and the reason. It does not call the credential broker and it does not allow the request without the credential. A check that returns no upstream credential (mcp://, inference://, a2a://, or an egress destination with no credential) does not change. TestGatewayExtProcServer and the ext_proc subtest of TestSTSTaskScopedSecurityCUJ expected the credential over plain TCP. They now use the Unix socket of the node. Limits: the rule authenticates the transport, not one gateway. A process that can open the Unix socket, or that holds a client certificate from the CA in --tls-ca, receives the credential. A gateway that reaches the node over plain TCP for an egress destination with a credential must change to the Unix socket or to a client certificate. This is the fix for GHSA-2g97-3v45-p9f4.
POST /oauth/token on the node returns a border JWT for an egress:// resource when the caller sets requested_token_type to the JWT token type. A border JWT is a bearer credential: its holder can exchange it at the cloud provider of the destination. The node returned it on every transport. An application on the same host, with a task Biscuit that grants the destination, received it over plain TCP. It could then get the cloud credential itself, outside the method, path and scope limits that the node applies. This is the same harm as the upstream credential in an ext_authz answer. The node now returns a border JWT only when the transport authenticates the caller: the Unix socket, or TLS with a verified client certificate (fromTrustedTransport). On any other transport it answers 403 access_denied and logs a warning with the requested resources. It refuses before any exchange with the control plane, so no JWT is minted for such a caller. A request for a Biscuit does not change. Step 5 of TestSTSTaskScopedSecurityCUJ asked for a border JWT over plain TCP. It now checks the refusal there, and the JWT over the Unix socket. Limits: the rule authenticates the transport, not one gateway. A border JWT stays a bearer token for its lifetime, 5 minutes by default and 15 at most. The limits on a stolen one are that lifetime and act.sub, which names the node. This completes the fix for GHSA-2g97-3v45-p9f4.
POST /sts/token had two defects. The calling node could choose the audience of the border JWT. When the egress destination pinned no audience, the control plane put the audience from the request in the JWT. A node that may reach destination A, which has no broker, asked for A with the audience that the oidc_federation broker of destination B pins. It received a signed JWT with the audience of B, although served_by of B excludes that node. A failed read of the egress policy skipped a check. The served_by check and the audience lookup each read the egress destinations and ignored a read error. When one read failed and a later read succeeded, a node outside served_by received a JWT, and a node in served_by received a JWT with the audience it asked for. The audience now comes from the egress policy only. It is the audience that the broker of the destination pins: oidc_federation.audience, or sts.amazonaws.com for aws_assume_role. Without a pinned audience it is the default https://<destination host>. The control plane refuses a request that names a different audience with 403 and writes the Border Crossing deny line. A request with no audience, or with the policy value, works as before. The control plane also refuses the request when the destination pins no audience and its default is an audience that the policy pins for another destination, so a wildcard grant cannot aim the default at a pinned value. HandleSTSToken now reads the egress policy one time. An error other than storage.ErrNotFound refuses the request with 500 and an error log that names the calling node and the destination. The served_by check, the audience and the Biscuit authorization use that one list, so the three see the same data. nodeRoles, which the served_by check calls, returns the enrolled role alone when it cannot read the mesh policy. That set is never wider than the full set and each caller grants per role, so the result cannot grant more and stays as it is. The failure was silent and is now a warning. Two control plane tests asked for an audience that their policy did not pin: TestOIDCIssuerJWKSAndSTSToken and TestSTSTokenBorderCrossingNamesTheOriginPeer. Their policy now pins it. The STS test in tests/integration asked the node for an audience of its choice and now names none. The node needs no change: it returns the refusal of the control plane to its caller as 403 access_denied with the reason. Limits. Every aws_assume_role destination has the audience sts.amazonaws.com, so the audience does not separate one AWS destination from another. The comment on STSTokenRequest.audience in api/agentmesh.proto still says that a request can set the audience. To change it needs code generation, so it is not in this commit. This is the fix for GHSA-gwq9-733j-cg85 and GHSA-g2j8-hmvc-5r3x.
…ore 1970 The OAuth token exchange of the control plane (POST /oauth/token) reads expires_in as int64 seconds and multiplies it into a time.Duration in two places: for the expire_time of the task rule and for the lifetime of the delegated Biscuit. A value above 9223372036 overflows to a negative duration. The negative duration passes the guard that lets a request only shorten the lifetime, and the control plane mints a Biscuit with an expiration before 1970. biscuit-go stores a Datalog date as unsigned seconds since the Unix epoch and compares dates unsigned. An expiration before 1970 becomes a far future date, so the Datalog check `time <= expiration` passes. The enforcement points trusted that check alone. An enrolled node that sent its own credential and a subject JWT got a delegated Biscuit that did not expire until the control plane retired the signing key. The fix has three parts. 1. Bound the request. handleOAuthTokenExchangeGrant reduces expires_in to 9223372036 seconds (math.MaxInt64 / time.Second), the largest value that converts to a time.Duration without overflow. The two multiplications get this value. The request is not refused: a larger value does not change the result, because expires_in can only shorten the lifetime. 2. Refuse at mint. The mint function refuses an expiration at or before the Unix epoch and returns an error that says why. It continues to mint an expiration in the recent past, which is a valid Datalog date. 3. Check in Go at each enforcement point. After the Datalog authorization passes, identity.AuthorizeMeshRequest reads the expiration() fact and refuses the credential when the fact is missing, at or before the Unix epoch, or not after the current time. The in-mesh verifier of the node and of sdk/meshnet, external ingress, the edge check of the router and /sts/token of the control plane call this function. Each one logs the refusal with its reason. Only this part stops a Biscuit that the control plane minted before this fix. identity.VerifyAndExtractPeerID, which authenticates a member to the control plane, also trusted the Datalog check alone. It now does the same check in Go. expirationOf reads the fact for these checks and now refuses an expiration at or before the Unix epoch. It used the zero time.Time to mean "no fact", and thus ignored an expiration with that value when the token had a second expiration. It now keeps the earliest expiration for all values. Limits: - The Go check refuses a credential from the instant of its expiration. The Datalog check compares whole seconds and admitted the credential for up to one second more. identity.VerifyBiscuit and identity.InspectVerifiedBiscuit already used the strict comparison. - A node, a router or a control plane without this fix continues to admit a Biscuit with an expiration before 1970. There, the Biscuit stays valid until it is revoked or the signing key is retired. - This commit does not change or test the verifiers in sdk/js and sdk/python. This is the fix for GHSA-qg99-6frq-2h5m.
Every reader of the directory protocol accepts a frame of at most 64 KiB. A router limited a record to 32 addresses, but not the length of an address, and it wrote a find_providers or find_peer answer without counting its bytes. A member with a publish grant for one service could announce, under the key of the service type, a record of 32 addresses of 2041 bytes. The request fits the frame. The answer adds a "/p2p/<peer id>" suffix to each address and does not fit: 67290 bytes. Every reader refused that answer with "message too large". Every lookup of the service type then failed on a router that held the record, for members and for peer routers, for as long as the member announced the record again. Many honest records had the same effect, because a lookup returns up to 100 of them. The fix has three parts: - An address in a record is at most api.DirectoryMaxAddrBytes, 1024 bytes with its peer suffix. recordAddrs refuses a longer address as an invalid request, which the router logs and counts. The longest address a libp2p host announces is about 660 bytes. 32 addresses at the bound are 32 KiB, half of the frame. - An answer fits the frame. freshRecords counts the encoded size of each record after it renders the record. It keeps each record that is at most an even share of the frame, then gives the room that is left to the larger records, the smallest first. The answer keeps the order of the records. The router logs the providers it leaves out and counts them in agentmesh_router_directory_records_omitted_total. The find_peer answer for a member that the router holds goes through the same bound. - A lookup merges the addresses that several routers hold for one provider. The merge stops at 32 addresses and logs how many it left out. Limits: - The answer bound applies to the first `limit` records of a lookup. When these do not fit, the largest are left out and no other record takes their place. - A router of an earlier version still accepts a long address and can still send an answer larger than the frame. An upgraded router refuses the copy of such a record. As before, it logs and drops such an answer. - Two parts of a record have no bound of their own: the addresses that a router reads from its peerstore for a member it holds, and the ingress allow-list. The answer bound leaves out a record that these make too large. This is the fix for GHSA-gw5v-gc33-3wg6.
…MCP path
ConnectMCPSession wrote AuthFrame{caller Biscuit} on /mesh/mcp/1.0.0
before it read the peer's AuthResponse and ran checkProvider. Any peer
the agent named therefore received the caller's credential, for example
a user's Delegated Session Biscuit, before being refused. That includes
an enrolled node not granted the service. The HTTP path already checks
the provider with VerifyProvider over /mesh/auth, using this node's own
credential, before it sets X-Mesh-Biscuit.
ConnectMCPSession now calls VerifyProvider first. call_remote_tool,
describe_remote_tool, find_remote_tools and the catalog fan-out all go
through it, and it reuses the provider verdict cache. checkProvider on
the AuthResponse stays as a second check.
TestConnectMCPSessionVerifiesProviderBeforeSendingCallerBiscuit points
ConnectMCPSession at a peer with no credential and at an enrolled node
not granted the service. It checks that neither receives a frame on
/mesh/mcp/1.0.0 and that the only credential sent is node A's own.
BanSet keeps, for each banned peer, the time the member learned the ban. reconcile keeps a ban that a /info answer omits when that time is at or after the time of the request: the answer is older than the ban. add returned early for a peer that was already in the set and kept the old time. The control plane publishes no event when an operator lifts a ban, so the peer stays in the set until the next pull. This sequence lost a ban: 1. X is in the set with time t0. 2. An operator lifts the ban. 3. A pull starts at t1. The control plane answers without X. 4. The operator bans X again. The event arrives with time t2 > t1 before the pull applies its answer. add(X, t2) changed nothing. 5. reconcile([], t1) removed X, because t0 is older than t1. The member then did not refuse X until the next pull. The Go node does not have this defect: banPeer writes the time of each ban event that is not older than the last one. add now keeps the later of the stored time and the new time, so a ban time never moves back. It still returns false for a peer that was already in the set: the callers evict a peer only on a new ban, and a peer in the set is already evicted and refused. reconcile calls add, so a ban that an answer lists also takes the fetch time when it is later. One limit stays. A ban event carries the clock of the control plane and the fetch time is the clock of the member. When the clock of the member is ahead of the clock of the control plane by more than the time between the request and the event, reconcile still removes the ban until the next pull. This is the fix for GHSA-h9gm-855f-88jw.
There was a problem hiding this comment.
Code Review
This pull request implements comprehensive security hardening across the Agent Mesh codebase, addressing several critical vulnerabilities. Key changes include: checking Biscuit expiration in Go to prevent pre-1970 bypasses (GHSA-qg99-6frq-2h5m); enforcing strict JSON-RPC parsing with unique member checks and compacting stdio bridge messages to prevent parser differentials and line-break injection (GHSA-g9hr-vm84-pjjr); restricting upstream credentials and border JWTs to trusted transports like Unix sockets or verified client certificates (GHSA-2g97-3v45-p9f4); and bounding directory address sizes and fitting records into the 64 KiB frame to prevent lookup failures (GHSA-gw5v-gc33-3wg6). Extensive unit, integration, and SDK tests have been added to validate these fixes. I have no further feedback to provide as the implementation is robust and well-tested.
This pull request fixes nine security advisories. Each commit fixes one problem and contains its regression tests. The commit message describes the defect, the fix and its limits. The advisories are published with the release that contains these commits.
allowed_tools.api, node: read one call from an MCP JSON-RPC messageand the twonode:commits after itX-Mesh-Mcp-Toolheader, or anext_authzcheck with no body, passed anytools/call.envoy, node: read the MCP tool from the request body onlyext_authz,ext_procand/oauth/tokengave the credential of an egress destination to any local caller.node, envoy: return the upstream credential only to the gatewayandnode: return a border JWT from /oauth/token only to the gateway/sts/tokensigned a border JWT with the audience of another destination.controlplane: take the border JWT audience from policy and fail closed/sts/tokenskipped theserved_byand audience checks when the policy read failed.expires_inoverflow gave a delegated Biscuit that did not expire.controlplane, identity: bound expires_in and refuse an expiration before 1970router, api: bound a directory address and the size of an answernode: verify the provider before sending the caller's Biscuit on the MCP pathsdk/js, sdk/python: keep a ban that is set again during a pullThanks to the reporters: Staberman, ersinkoc, HosniBelfeki and ignaciojaneiro, who also wrote the fix for GHSA-qgh6-qr94-7prg.
Changes that an operator sees
ext_authzmust send the request body. The node reads the tool of an MCPtools/callfrom the body only. Setwith_request_bodyon theext_authzfilter. Without the body, the node refuses aPOSTto an MCP service from a credential that hasoperation.allowed_tools. TheX-Mesh-Mcp-Toolrequest header has no meaning.ext_authz,ext_proc) and a border JWT (POST /oauth/tokenwithrequested_token_type) only over its Unix socket (--socket-path) or to a verified client certificate (--tls-ca). On another transport it answers403./sts/tokenand the node's/oauth/tokenrefuse a requested audience that differs from the audience of the egress policy. A failed read of the egress policy refuses the request with500.find_providersanswer always fits the 64 KiB frame; the new counteragentmesh_router_directory_records_omitted_totalcounts records that an answer left out.operation.allowed_tools, a message that statesmethod,paramsor the toolnametwice, or in another letter case, is refused. A request with noidthat is not anotifications/method is dropped.expires_inabove 9223372036 is reduced to that value. A correct client sees no change.Merge with "Rebase and merge", so that each advisory keeps its commit and the reporter stays the author of his fix.