feat(cosh): add secret redaction for model output and tool results#100
Merged
samchu-zsl merged 2 commits intoalibaba:mainfrom Apr 7, 2026
Merged
feat(cosh): add secret redaction for model output and tool results#100samchu-zsl merged 2 commits intoalibaba:mainfrom
samchu-zsl merged 2 commits intoalibaba:mainfrom
Conversation
Collaborator
Author
b7a1695 to
91cd579
Compare
samchu-zsl
reviewed
Apr 7, 2026
Collaborator
samchu-zsl
left a comment
There was a problem hiding this comment.
Thanks for the fix. I have a remaining concern.
Since secrets are redacted from the LLM's stream output, could this affect tool calls? Say, if I'm installing Claude Code and provide an API key, would that key be redacted before the write tool is called?
Collaborator
Author
|
The redaction is purely a terminal display concern — it never mutates tool parameters or blocks writes. |
samchu-zsl
approved these changes
Apr 7, 2026
Collaborator
samchu-zsl
left a comment
There was a problem hiding this comment.
All concerns addressed. LGTM. Thanks!
- Add secretRedactor.ts with regex patterns for sk-, ant-, LTAI, Bearer, accessKeySecret, env vars - Apply redactSecrets() to streamed model output - Fix streaming split vulnerability: accumulate raw turn buffer and redact full content per chunk - Apply redactPartListUnion/redactAnsiOutput to tool results in coreToolScheduler.ts - Add Secret Protection instruction to system prompt in prompts.ts
- Extend returnDisplay redaction to cover FileDiff type (WriteFile / EditFile) - Redact fileDiff, newContent, and originalContent fields to prevent secrets from appearing in post-execution diff summaries
91cd579 to
abf76f1
Compare
22 tasks
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.

Description
Add a secret redaction layer to prevent sensitive credentials from being displayed in the terminal. Introduces
secretRedactor.tswith pattern-based detection for common key formats (OpenAIsk-, Anthropicant-, Alibaba CloudLTAI/accessKeySecret, Bearer tokens, genericapiKey/passwordfields, and environment variable assignments).The redaction is applied at two interception points:
useGeminiStream.ts): each stream chunk is accumulated into a raw turn buffer and redacted against the full buffer, fixing a streaming-split vulnerability where a secret spanning multiple chunks could partially leak.coreToolScheduler.ts):llmContent,returnDisplay(string and ANSI variants) are redacted before further processing.A
Secret Protectionrule is also added to the system prompt to instruct the model to refuse revealing secrets at the source.Related Issue
fixes #83
closes #83
Type of Change
Scope
cosh(copilot-shell)Checklist
cosh: Lint passes, type check passes, and tests passagent-sec-core(Rust):cargo clippy -- -D warningsandcargo fmt --checkpassagent-sec-core(Python): Ruff format and pytest passos-skills: Skill directory structure is valid and shell scripts pass syntax checkpackage-lock.json/Cargo.lock)Testing