Skip to content

fix: mask secrets before live tool-result delivery - #146596

Merged
steipete merged 3 commits into
mainfrom
codex/tool-result-secret-redaction
Sep 13, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/tool-result-secret-redaction

Conversation

@steipete

@steipete steipete commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Related: #71211

What Problem This Solves

Fixes: secrets in tool output can reach the next model request even when the saved transcript masks them.

User Impact

User impact: the OpenClaw harness masks recognized and registered secrets in live tool-result text, while preserving ordinary source text, media, and the original arguments used to execute tools.

Why This Change Was Made

Apply the effective session redaction policy after extension transformations and revalidate the current result around callbacks. Preserve prepared bytes through storage and restoration only while the text, pattern policy, and registered-secret revision still match. The existing session runtime registry binds this policy internally; no public SDK method, new settings, or native Codex behavior changes.

Evidence

Real read and exec regressions failed before the repair and pass afterward for Anthropic Messages and OpenAI Responses. Coverage includes extension replacements, errors, media preservation, and SQLite close/reopen. Checks also cover explicit pattern overrides, late secret registration, non-idempotent custom patterns, and unregistered app-specific passwords using the complete existing text-field policy. Typechecks, lint, repository guards, and independent review passed. An authenticated Anthropic file-read continuation passed without the synthetic credential in its request payload.

Final API-scope cleanup: 70 focused tests, SDK type contracts, types/lint/import/export guards, and fresh independent review through P2 passed. The authenticated Anthropic continuation passed again after this cutover.

@clawsweeper

clawsweeper Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: L maintainer Maintainer-authored PR labels Sep 13, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 13, 2026
@clawsweeper

clawsweeper Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 12, 2026, 10:58 PM ET / September 13, 2026, 02:58 UTC (Revision 5).

ClawSweeper review

What this changes

Masks finalized tool-result text before the next model request and preserves those masked bytes through transcript storage without adding a public SDK method.

Merge readiness

✅ Ready for maintainer review

This PR remains useful: current main lacks the live masking step, and the older related PR closed unmerged. Both prior concerns are resolved, with no remaining actionable defect found.

Priority: P1
Reviewed head: 1b0977844544ac4e4af89495ab1faa1a91e1a94b

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, well-covered repair with both earlier concerns addressed and no remaining correctness finding.
Proof confidence 🌊 off-meta tidepool Not applicable: The maintainer-authored PR is exempt from the external-contributor proof gate. Its reported authenticated Anthropic continuation matches the inspected live test's session masking and provider-payload checks; no execution was performed by this reviewer.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The maintainer-authored PR is exempt from the external-contributor proof gate. Its reported authenticated Anthropic continuation matches the inspected live test's session masking and provider-payload checks; no execution was performed by this reviewer.
Evidence reviewed 9 items Previous API concern resolved: The exact-head commit removes SessionManager.prepareModelVisibleToolText, moves preparation into an internal session-identity registry, and adds SDK type assertions against exposing the preparation helpers. This addresses the previous review's sole remaining rank-up move.
Live admission and invalidation: Session handling prepares text after extension replacement, again after synchronous listeners, and after write settlement. Prepared markers match the exact text, configured patterns, full-context policy, and secret-registry revision; changed inputs therefore trigger another masking pass.
Field-aware masking and storage consistency: Preparation now invokes the complete model-visible text-field redactor, including app-password handling. Persistence receives the guard's config and copies preparation metadata only when serialized text remains identical. Regression cases cover first provider payloads, SQLite reopen, explicit policy overrides, late registration, and non-idempotent patterns.
Findings None None.
Security None None.

How this fits together

OpenClaw's agent session receives tool results after extension processing, publishes events, and saves transcripts. The prepared result then feeds the model's next request and subsequent conversation replay.

flowchart LR
  A[Tool output or error] --> B[Extension processing]
  B --> C[Session text masking]
  D[Secret registry and patterns] --> C
  C --> E[Listeners and revalidation]
  E --> F[Transcript storage]
  E --> G[Next model request]
  F --> H[Conversation replay]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +169, Tests +614, Docs +7. Total +790 across 18 files.

View PR surface stats
Area Files Added Removed Net
Source 11 219 50 +169
Tests 5 623 9 +614
Docs 2 8 1 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 18 850 60 +790

Review metrics

Metric Value Why it matters
Production versus regression coverage production net +169 lines; tests net +614 lines Production growth implements session-bound preparation and invalidation; tests cover provider payloads, callbacks, restoration, and the SDK boundary.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #71211
Summary: This PR is a candidate fix for the reported model-context exposure; it does not establish closure of every raw tool-event surface mentioned in the broader issue.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Technical review

Best possible solution:

Keep masking at finalized session-result admission, reuse the established text policy, and preserve prepared bytes without expanding the plugin API.

Do we have a high-confidence way to reproduce the issue?

Yes, at source level: an ordinary read or exec result containing a registered secret can reach the next model request on current main without live masking. No runtime reproduction was executed during this review.

Is this the best way to solve the issue?

Yes. Preparing finalized text after extension processing covers shared tool outcomes while retaining execution arguments, media, and the existing redaction policy; the previous public-API expansion is removed.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against f0817f23e939.

Labels

Label changes:

  • remove merge-risk: 🚨 compatibility: Current PR review selected no merge-risk labels.

Label justifications:

  • P1: The PR repairs recognized secrets reaching model requests through ordinary tool-output workflows.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The maintainer-authored PR is exempt from the external-contributor proof gate. Its reported authenticated Anthropic continuation matches the inspected live test's session masking and provider-payload checks; no execution was performed by this reviewer.

Evidence

What I checked:

  • Previous API concern resolved: The exact-head commit removes SessionManager.prepareModelVisibleToolText, moves preparation into an internal session-identity registry, and adds SDK type assertions against exposing the preparation helpers. This addresses the previous review's sole remaining rank-up move. (src/agents/sessions/session-tool-result-redaction.ts:6, 1b0977844544)
  • Live admission and invalidation: Session handling prepares text after extension replacement, again after synchronous listeners, and after write settlement. Prepared markers match the exact text, configured patterns, full-context policy, and secret-registry revision; changed inputs therefore trigger another masking pass. (src/agents/sessions/agent-session-base.ts:388, 1b0977844544)
  • Field-aware masking and storage consistency: Preparation now invokes the complete model-visible text-field redactor, including app-password handling. Persistence receives the guard's config and copies preparation metadata only when serialized text remains identical. Regression cases cover first provider payloads, SQLite reopen, explicit policy overrides, late registration, and non-idempotent patterns. (src/logging/redact.ts:891, 1b0977844544)
  • Current main still needs the fix: The fetched main revision emits finalized tool-result events and persists a separate copy without the new live preparation calls. The provider text extractor sanitizes Unicode but does not mask explicit text blocks, so existing structured-block redaction does not duplicate this repair. (src/agents/sessions/agent-session-base.ts:383, f0817f23e939)
  • Latest-release comparison: Reading the session event handler at the supplied v2026.9.4 release commit likewise shows extension emission and persistence without live tool-text preparation. The release source was retrieved through GitHub after the local tag lookup failed. (src/agents/sessions/agent-session-base.ts:390, 3a9d69db306c)
  • Proof scope and reported result: The captured body and fix: mask secrets before live tool-result delivery #146596 (comment) report an authenticated Anthropic file-read continuation passing after the internal-API cutover. The inspected live test exercises the real session/provider path, checks a successful marker-bearing continuation, and blocks synthetic-secret egress in its payload callback. Execution was reported by the author, not performed during this read-only review. (src/agents/sessions/agent-session.live.test.ts:184, 1b0977844544)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (4 earlier review cycles)
  • reviewed 2026-09-13T00:41:58.910Z sha c0dc3708d333755d6c2080e0162d0fc0c4a4cb35 :: blocked before merge. :: [P1] Preserve field-aware masking before marking tool text prepared
  • reviewed 2026-09-13T00:56:45.717Z sha c0dc3708d333755d6c2080e0162d0fc0c4a4cb35 :: blocked before merge. :: [P1] Preserve field-aware masking before marking tool text prepared
  • reviewed 2026-09-13T01:52:00.485Z sha 8139a27 :: blocked before merge. :: none
  • reviewed 2026-09-13T01:59:49.693Z sha 8139a27 :: blocked before merge. :: none

@steipete
steipete marked this pull request as ready for review September 13, 2026 00:51
@steipete
steipete force-pushed the codex/tool-result-secret-redaction branch from c0dc370 to 8139a27 Compare September 13, 2026 01:45
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 13, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Addressed the text-field masking finding: preparation now applies the same complete model-visible text-field policy that persistence uses. The new unregistered app-password regression failed before the correction and passes for the first actual provider payload and SQLite close/reopen; benign source text remains intact. The 326 focused tests and independent review passed. The branch also includes main's separate upgrade-cohort test correction; that 18-test owner suite and the 13 end-to-end payload/restoration cases pass on the refreshed base.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@steipete

Copy link
Copy Markdown
Contributor Author

The API-scope concern is resolved: the new public SessionManager.prepareModelVisibleToolText method is removed. The existing session runtime registry holds the guard-bound callback internally; there are no new SDK exports.

The SDK type regression fails with the former method and passes after removal. All 70 focused tests pass, including 13 first-continuation/SQLite policy cases, plus types, lint, import/export guards and a fresh independent review through P2. The authenticated Anthropic file-read continuation passes after this cutover.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. label Sep 13, 2026
@steipete
steipete merged commit dcf3baa into main Sep 13, 2026
185 of 187 checks passed
@steipete
steipete deleted the codex/tool-result-secret-redaction branch September 13, 2026 03:11
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 13, 2026
* fix: mask secrets before live tool-result delivery

* fix: preserve field-aware masking in live tool text

* refactor(agents): keep tool-result preparation internal
Finn763 added a commit to Finn763/openclaw that referenced this pull request Sep 16, 2026
…142821)

- P1: connect the encoding to the existing transcript owner. transcript-redact-text.ts
  escapes raw literals, marks the masks redaction produces, and keeps sanitized output
  when no mask was produced; transcript-redact.ts routes source-input text through the
  same encoder; the caller-less transcript-redact-values.ts module is removed.
- P1: the persisted-detail sanitizer keeps truncation and partial-secret omission output
  even when it produced no mask, so an unterminated private-key fragment can no longer be
  restored into persisted details.
- P2: a literal-only complete marker is stored escaped (no genuine mark), so replay keeps
  the user's bytes instead of replacing them; tests cover the no-fresh-mark case the
  helper test skipped by adding a genuine mark.

Model-visible tool text keeps the delivery dialect (bare masks) because those bytes are
admitted live by prepareModelVisibleToolTextBlock (openclaw#146596), and identity comparisons use
the canonical (unmarked) form: delivery-mirror dedupe, append identity and Claude CLI
import dedupe no longer compare marked bytes against unmarked ones. Re-redacting stored
bytes is not a byte fixed point (a hint body is mask-shaped text), so a second pass
collapses a hint to a marked placeholder; the row stays masked, replayable and secret-free.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant