Skip to content

feat(a2a-agent): atif/1 reads leave out the secrets the SDK knows - #827

Merged
earakely-scale merged 8 commits into
mainfrom
edgararakelyan/y2b-scrub
Nov 20, 2026
Merged

earakely-scale merged 8 commits into
mainfrom
edgararakelyan/y2b-scrub

Conversation

@earakely-scale

@earakely-scale earakely-scale commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

The last of Y2b's three PRs for FD-6076: an agent's atif/1 reads leave out every secret its SDK holds or is handed, and every one the agent registers (Y2b-4). Part of FD-6076.

What changes

  • Every atif/1 read is scrubbed as it's served: the document, the aux log and the turn context; inline, uploaded through the objects form, and in cursor pages. Each secret is written [redacted:<length>] wherever it occurs, in any string, mapping keys included. Native reads keep every secret byte for byte.
  • What the SDK knows (_secrets.Secrets.for_agent, one per agent that serves atif/1; framework.py only builds it, hands it the control token and each extension call, and AtifCopy serves everything through its scrub):
    • its control token, once the lifespan takes it, and the model credentials in its environment: LITELLM_API_KEY and the values of LITELLM_EXTRA_HEADERS;
    • write-only agent-config values, and write-only defaults: a string whole, and in a mapping only what a credential-like key names (and everything below it), so pi's model_params doesn't get priority or a provider's name redacted;
    • an MCP registration's header values and credential-like query values;
    • a CDP endpoint's header values, and the token in its URLs;
    • every transfer grant an extension call hands the agent, by the parts of its URL that carry the credential: a presigned URL's credential-like query values (X-Amz-Signature, X-Amz-Credential, X-Amz-Security-Token, X-Goog-Signature, Azure's sig, token, key, ...; not X-Amz-Algorithm, X-Amz-Date or X-Amz-SignedHeaders, so AWS4-HMAC-SHA256 stays in an agent's text), else its token-like path segments (a grant server's /v1/grants/<token>, plain query or not), and a password; each query value both decoded and as the URL writes it, so a copy of the URL inside another URL's query matches too. Every copy of a URL holds those, so a URL an agent prints keeps its host and path and loses its signature. Also its headers other than Content-Type and the like, and a signed upload form's signing fields;
    • a clock follower's read token;
    • whatever the agent registers with self.register_secret(value), once its app exists.
  • Taken as each extension call is parsed, before any handler runs, so an agent that overrides the SDK's handler (mcp add, agent-config set, ...) is covered too.
  • A value under 8 characters isn't scrubbed, with one warning per source that names the source, never the value. Short parts of a URL, such as X-Amz-Expires=900, are skipped silently.
  • Matching: each secret raw, JSON-escaped (ASCII or not) and percent-encoded, the longest first. The match compiles as a prefix trie once per change, when a read next needs it. A grant adds only its signature, since the session token and access key a role signs every grant with are one secret each: with 500 grants of 1,200-character S3 URLs (temporary credentials), the compile takes 0.07 s and 6 MiB, and at 3,000 it takes 0.45 s and 34 MiB, where registering each whole URL took 5.2 s and 410 MiB at 500. A scan takes 0.2 ms.
  • Cursor pages count their byte budget as they serve, so a redaction longer than its secret can't push a page past max_bytes.
  • Docs: the README's Serving ATIF section, PROFILE.md and the agents guide.

Choices to review

  • Scrubbing happens at read time, not when a step is written. So a secret the SDK learns later (a config set or a CDP add after the turn) is left out of everything served from then on, and the adapter sees the unscrubbed records. The cost is a regex pass over each served string.
  • A grant is redacted by its credential parts, not whole. A printed URL keeps its host, path and non-credential parameters, which aren't secret, and each grant costs the match a signature rather than its whole URL.
  • Credentials are told by their names (one rule for query parameters, a signed form's fields and the keys of a write-only mapping), not by every value: plain paths, Content-Type, X-Amz-Algorithm, the upload form's key and a write-only mapping's non-credential values are left, so ordinary text isn't mangled. A credential under a name the rule doesn't know is still caught whole, in the URL or by a registration.
  • MCP URLs are scrubbed only by their query values, as Y2b-4 named header values. A gateway URL itself isn't a credential.
  • A replay of the served inputs no longer equals the served document when a secret is in them: the native log keeps it. The served document is that replay with the secrets redacted. The chaos harness checks exactly that.
  • Media bytes aren't scrubbed; Y3 (FD-6077) moves them.

Testing

  • tests/test_a2a_atif_scrubbing.py (22 tests):

    • a registered secret is redacted in every read form (task, context, both cursors, all three uploads) and kept in the native read;
    • one case per source the SDK is handed: model key, model headers, control token, write-only config, MCP headers, CDP URL;
    • presigned grants redacted by their signature wherever printed (whole, as a request line, percent-encoded), with AWS4-HMAC-SHA256 and X-Amz-Date left;
    • a role's 200 grants with one session token add their signatures alone;
    • a path token beside a plain query, and a signed URL encoded again inside another URL;
    • a write-only mapping set through a real agent's config is redacted by its credentials alone, with no short-value warning;
    • a tokened grant URL redacted by its token, with plain paths and short values left and no warning;
    • signed upload forms redacted by their signing fields alone;
    • a clock follower's read token;
    • the longest secret wins, and an escaped one is redacted too, in mapping keys as well;
    • a non-ASCII secret in an inbound DataPart, through a real agent;
    • the trie matches what a plain longest-first alternation does, on random overlapping forms;
    • 3,000 grants compile once, when a read needs them;
    • a short secret gets one warning per source;
    • a cursor page's byte budget counts what it serves;
    • an agent without atif/1 registers nothing, and registering before create_app() is refused.

    Removing each source's registration, or the read-time scrub, fails these tests.

  • Integration: a new test in test_prompt_agent_live_trajectory_local.py deploys the echo agent with a model key and prompts run printenv LITELLM_API_KEY. The native read keeps the printed key; the atif/1 read holds [redacted:<n>] instead and validates. put_test_agent takes an env.

  • Serving chaos (the PR 1 and PR 2 harness, now with the seed's model key in the agent's environment and in some texts, messages and notes). It checks:

    • no atif/1 answer or upload holds the key;

    • native reads keep it;

    • replaying the served inputs, then redacting the key, gives the served document.

    • On the vm host: 20 min on 9f68009 (89,081 seeds, 334,069 tasks, 33,253 restarts, 33,254 restores), no failures. The integration file's 4 tests passed there.

    • 60 s locally on each commit, no failures. It caught both planted leaks: an unscrubbed cursor page, and an unscrubbed aux log and turn context.

🤖 Generated with Claude Code

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge.

Summary

The SDK removes known secrets from atif/1 reads while leaving native logs unchanged.

  • ATIF reads now replace known secrets with redaction labels.

earakely-scale accepted that two mapping keys can collapse after redaction, as the cost of not serving their secrets.

Reviews (10) · Last reviewed commit: "docs(a2a-agent): the README names how a ..." · Reviewed by Greptile

Every atif/1 read, inline, uploaded or paged, writes each secret the SDK holds or is
handed as [redacted:<length>] wherever it occurs: the control token, the model key and
extra headers' values, write-only agent-config values, MCP and CDP credentials, the
parts of every transfer grant that carry its credential, a clock follower's read token,
and whatever the agent registers with self.register_secret(value). Secrets are taken
from each extension call before any handler runs and scrubbed at read time, matched raw,
JSON-escaped and percent-encoded, the longest first; one under 8 characters is left with
a warning. Cursor pages count their byte budget as they serve. Native reads are untouched.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@earakely-scale
earakely-scale requested a review from a team as a code owner November 19, 2026 20:03
…ets as a trie built once per change

A secret used as a mapping key, or written JSON-escaped without ASCII escapes as an
inbound DataPart's compact JSON is, was served as it was. Keys are scrubbed too, and each
secret's non-ASCII JSON form is matched. Adding a secret no longer rebuilds the match: it
is compiled when a read next needs it, as a prefix trie, so a call that hands the agent a
grant per file, or a run that accumulates thousands, compiles once and scans no slower.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
earakely-scale and others added 3 commits November 19, 2026 14:36
…en't redacted

Every query value of a presigned URL was registered, so AWS4-HMAC-SHA256 and the
signing date were redacted wherever an agent met them, and every string in a write-only
mapping was, so pi's model_params had words like "priority" redacted and short ones
warned about. One rule now tells a credential by its name (signature, credential, token,
key, password, auth, policy, ...) for query parameters, a signed form's fields and the
keys of a write-only mapping, taking everything below a credential-like key; a write-only
string is still taken whole, and a grant's URL and request line still are.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… needs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… credential

Each grant registered its whole URL and its path and query, about 4,700 unique
characters for a 1,200-character S3 URL with a session token, so 500 grants made the
trie 2.4M characters: a 5.2 s compile on the event loop and 410 MiB after each new
grant. A URL now gives its credential-like query values, or the token-like path
segments of a URL with no query, and its password: every copy of the URL holds them, and
the session token and access key a role signs every grant with are one secret each, so
a grant adds its signature. 500 such grants compile in 0.07 s and 6 MiB.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
earakely-scale and others added 3 commits November 19, 2026 15:22
…f/1 is served

Secrets.for_agent takes the agent's environment and write-only config defaults, and
add_request now takes an agent-config call's write-only values too, so framework.py only
builds it and hands it the control token and each extension call. AtifCopy is built with
the scrub and serves everything through it, the task read's aux log and turn context as
wire dicts, so no read path passes a scrub of its own; its cursor pages take each step's
id from the step before scrubbing. Secrets._forms names a secret's four forms, the two
name rules share one comment, and the tests share one string walker.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…y secrets as written

A grant server's /v1/grants/<token>?download=1 gave no secret, since only a URL with no
query had its path tokens taken: path tokens are now taken whenever the query carries no
credential. A signed URL percent-encoded again, as inside another URL's query, held its
token encoded twice, which no form matched: each credential query value is now taken as
the URL writes it too, whose own encoding is that copy's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@earakely-scale
earakely-scale merged commit ac83e9b into main Nov 20, 2026
36 of 37 checks passed
@earakely-scale
earakely-scale deleted the edgararakelyan/y2b-scrub branch November 20, 2026 00:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant