Skip to content

search --json prints four session metadata fields that redactMetadata does not cover #1048

Closed

Description

@Vasanthdev2004

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:

  • SourceModelID is set by the session importer through agentsessions.DisplayField, which redacts and strips controls before the value is stored. Driven with a sk-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 by redactMetadata.
  • Tag on an imported session is sessions.ImportedSessionTag(agent, sourceID), built from the adapter name and the foreign session id rather than free text.
  • SpecUserComment and SpecRejectReason carry 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:

  1. Return an explicit presentation type from search with only the fields the CLI renders, so a new Metadata field is absent by default rather than exposed by default, or
  2. Keep Metadata but 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

  1. added
    bugSomething isn't working
    issue-approvedReviewed and approved by the core team; community PRs may implement this issue.
    on Sep 12, 2026
  2. Vasanthdev2004 commented on Sep 24, 2026

    @Vasanthdev2004
    CollaboratorAuthor

    Picked this up, and the count is larger than the title says. Filling every string-kinded field of sessions.Metadata with a credential, running it through redactMetadata and walking the result: ten covered, twenty carrying the secret straight through.

    covered (10)  SessionID Title Cwd ModelID Provider ParentSessionID
                  ForkedFromEventID CreatedAt UpdatedAt LastEventType
    
    leaked (20)   SessionKind Tag RootSessionID AgentName TaskID
                  SpawnedFromEventID SpecID SpecFilePath SpecStatus
                  SpecDraftModelID SpecDraftReasoning SpecUserComment
                  SpecRejectReason SpecSourceSessionID SpecImplSessionID
                  Goal.Objective Goal.Status Goal.StatusReason
                  Goal.CreatedAt Goal.UpdatedAt
    

    Two corrections to the issue body. SourceModelID does not exist anywhere in the repository, so that one cannot be assessed as written; SpecDraftModelID is probably what was meant. And the Goal was not in the list at all, which matters because it is the only nested struct here and Goal.Objective and Goal.StatusReason are 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 redactMetadata is hand-kept, so the gap grows every time a field is added to the struct, silently.

    The Goal also needs care beyond adding it to the list. Metadata is passed by value but Goal is 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 --json output.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingissue-approvedReviewed and approved by the core team; community PRs may implement this issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions