fix(compaction): redact credential-like values from summary pipeline - #12734
Closed
teknium1 wants to merge 1 commit into
Closed
fix(compaction): redact credential-like values from summary pipeline#12734teknium1 wants to merge 1 commit into
teknium1 wants to merge 1 commit into
Conversation
Port from openclaw/openclaw#67801. The context compressor's summarizer prompt instructs the model to preserve specific values (file paths, commands, error messages, etc.) so it can produce concrete handoffs. That instruction also caused API keys, bearer tokens, and env-var assignments surfaced through tool output (terminal, read_file, curl -v) to be copied verbatim into the persistent summary and re-injected on every subsequent compaction. Apply agent.redact.redact_sensitive_text at three points: - serializer output (primary defense) - previous-summary re-injection on iterative compaction - LLM-returned summary before storage in _previous_summary agent/redact.py already had the full pattern set; it was wired only to log formatters and cron scrubbing, never to compression. Tests: 6 regression cases covering API-key prefixes, env assignments, authorization headers, JSON token fields, non-secret content preservation, and summarizer-echo defense. Refs: openclaw/openclaw#67801
Contributor
Author
|
Redundant — same three-layer redaction landed on main in commit 3368814 (PR #9200 by @entropidelic, Apr 20). Both PRs applied |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Credentials surfaced through tool output (env dumps,
.envreads, curl -v, etc.) no longer leak into context-compression summaries or survive across compactions.Root cause:
agent/context_compressor.pyserializes tool results and assistant tool-call arguments verbatim into the summarizer prompt, and the prompt explicitly instructs the model to preserve "specific values" for a concrete handoff. API keys, bearer tokens, and env-var assignments were copied into the stored_previous_summaryand re-injected on every subsequent compaction.agent/redact.pyalready had a robust pattern set (40+ token prefixes, env assignments, JSON fields, auth headers, JWTs) but was wired only to log formatters and cron output — never to the compression pipeline.Ported from openclaw/openclaw#67801. OpenClaw's fix combined a prompt wording change (remove "tokens, API keys" from the preservation instruction) with a payload-side sanitizer. Hermes's summarizer prompt never listed tokens/keys as preservation targets, so only the payload-side fix is needed here.
Changes
agent/context_compressor.py: importredact_sensitive_text; apply at three points_serialize_for_summaryreturn value (primary defense — scrubs tool results, assistant messages, and tool-call arguments before they reach the summarizer)_previous_summary(belt-and-suspenders if summarizer echoes a secret from the input)tests/agent/test_context_compressor.py: 6 new regression tests — API key prefixes, env assignments, authorization headers, JSON token fields, non-secret content preservation, summarizer-echo defense.Validation
echo $OPENAI_API_KEYin tool outputsk-***in serialized input and stored summaryAuthorization: Bearer ghp_...in curl outputBearer ghp_***tests/agent/test_context_compressor.pytests/agent/test_redact.pyE2E verified with real imports:
read_file(".env")tool result containing a mock production key is scrubbed toOPENAI_API_KEY=***in the serialized summary input.Source
Ported from openclaw/openclaw#67801 'fix(compaction): stop retaining credential-like values'