Repository navigation
Description
redactMetadata in internal/search/search.go redacts ten sessions.Metadata fields and leaves four caller-provided string fields untouched: Tag, SourceModelID, SpecUserComment and SpecRejectReason. RedactResult embeds that metadata in every Hit, and zero search --json prints the result directly, so text in any of those four reaches stdout unredacted.
Found while reviewing #878, where CodeRabbit raised it. It is not that PR's regression and its import path is already defended, so filing it separately.
What is and is not exposed today:
SourceModelIDis set by the session importer throughagentsessions.DisplayField, which redacts and strips controls before the value is stored. Driven with ask-ant-api03-key in a foreign model id, both contiguous and tab-split, and with an escape sequence: all came back redacted or stripped. So the field is covered by accident of where it is written, not byredactMetadata.Tagon an imported session issessions.ImportedSessionTag(agent, sourceID), built from the adapter name and the foreign session id rather than free text.SpecUserCommentandSpecRejectReasoncarry spec-mode review text straight from the user, and nothing sanitizes them on the way in or out.
So the live exposure is the two spec fields, and the other two are one refactor away from becoming exposed, since nothing at the search boundary states the rule.
The comment on WorkspaceKey a few lines up already makes the right argument, that a presentation copy should not carry operational identity, and then the function keeps hand-listing fields. A struct gains a field and the redaction silently does not cover it, which is how these four got here.
Suggested fix, either:
- Return an explicit presentation type from search with only the fields the CLI renders, so a new
Metadatafield is absent by default rather than exposed by default, or - Keep
Metadatabut redact every string field by construction rather than by name, and add a test that fails when a new string field is added without coverage.
Option 1 matches the WorkspaceKey reasoning. Either way, a regression on one of the spec fields.
Activity
Vasanthdev2004 commentedon Sep 24, 2026
Picked this up, and the count is larger than the title says. Filling every string-kinded field of
sessions.Metadatawith a credential, running it throughredactMetadataand walking the result: ten covered, twenty carrying the secret straight through.Two corrections to the issue body.
SourceModelIDdoes not exist anywhere in the repository, so that one cannot be assessed as written;SpecDraftModelIDis probably what was meant. And theGoalwas not in the list at all, which matters because it is the only nested struct here andGoal.ObjectiveandGoal.StatusReasonare free user text, the same category as the two spec fields you identified as the live exposure.The analysis of WHY those two are the live exposure still holds, and the framing that the others are "one refactor away" turns out to be the important part: the list in
redactMetadatais hand-kept, so the gap grows every time a field is added to the struct, silently.The
Goalalso needs care beyond adding it to the list.Metadatais passed by value butGoalis a pointer inside it, so redacting through it rewrites the goal the caller still holds: a search would edit the live session record it was only asked to report on.PR up shortly: every text field redacted, the goal through a copy, and a test that walks the struct instead of repeating the list, so the next field added fails on the day it lands rather than the day someone notices it in
--jsonoutput.