Skip to content

Session ids derived from unvalidated provider- and model-supplied text can collide in the store and falsify the identity model's path invariant #441

Closed

Description

@jhrozek

Follow-up to the member-name fix in 7bb865ab, which closed the same root cause for
team members. Two other sources of session-id text are still unvalidated.

The pattern

A session id is assembled from text mecatl does not control, and two consumers
then read that id as structured:

  • the store's filename token — jsonlstore safeName admits exactly
    [A-Za-z0-9._-] and maps every other rune to _, so two distinct ids can
    collapse onto one session file;
  • a SPIFFE path segment, for the agent-identity work — where a lossily
    sanitized segment is a claim the verifier cannot parse back.

docs/agent-identity-model.md states the invariant as "team and call ids
dash-free hex (already true)". The team half was false and is now fixed. The
call half is not enforced anywhere — it rests on provider behaviour.

1. Provider-supplied call ids

engine/agent/subagent.go (childSessionID) builds the child session id as
fmt.Sprintf("%s-%s", t.idPrefix, callID), where callID is the tool-call id
returned by the provider. Nothing validates its charset.

mecatl talks to OpenAI-compatible gateways, an OpenRouter adapter, and the
ToolHive LLM gateway, so the id's shape is a property of whatever endpoint is
configured, not of mecatl. A gateway returning an id containing / or a space
yields two children whose distinct ids safeName onto one session file.

2. Model-supplied resume ids

engine/agent/subagent.go (validateResume) checks only
strings.HasPrefix(args.Resume, t.idPrefix+"-"). Everything after the prefix is
model-authored and unvalidated, so resume: "subagent-../../a b" passes
validation and becomes a session.SessionID handed to the store.

Severity: low today, structural tomorrow

safeName sanitizes the filename, so nothing escapes the store directory — the
existing defense holds and there is no traversal. Exploiting the collision also
requires already knowing the id being collided with, which bounds the practical
attack.

What makes it worth fixing is that it is a documented invariant that is simply
false, in the same class the Track B handover flagged
(docs/agent-identity-track-b-workload-identity.md, "The current child SPIFFE
path invariant is false"), and the agent-identity work turns these strings into
credential path segments where a lossy sanitize stops being harmless.

Suggested fix

Mirror what landed for members: validate at the point the id is constructed
rather than sanitizing per consumer, since the lossy sanitize is what loses the
distinction between two ids in the first place. team.ValidMemberName is the
existing shape; a shared identifier-segment validator would serve all three
sites. A provider id that fails should be a loud, correlated diagnostic rather
than a silent rewrite, so a non-conforming gateway is visible.

Whichever way it goes, the identity model should record the decision rather than
keep the "already true" claim.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions