fix(redact): skip ENV/JSON patterns on code files to avoid false positives#15923
Closed
zons-zhaozhy wants to merge 2 commits into
Closed
fix(redact): skip ENV/JSON patterns on code files to avoid false positives#15923zons-zhaozhy wants to merge 2 commits into
zons-zhaozhy wants to merge 2 commits into
Conversation
…tives
redact_sensitive_text() applied ENV assignment and JSON field patterns
to all text, including source code returned by read_file and
search_files. This caused false positives:
- _TOKENS=*** in Python code → redacted as env var assignment
- {"key": "value"} in JSON/JS code → redacted as secret JSON field
Add code_file=True parameter to skip ENV/JSON patterns while keeping
high-confidence patterns (known prefixes, JWTs, private keys, DB
connection strings, auth headers) that detect real secrets even in code.
file_tools.py: pass code_file=True when the target file is a recognized
source code extension.
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
redact_sensitive_text()applies ENV assignment (FOO=***) and JSON field ("key": "value") patterns to all text, including source code returned byread_file/search_files. This produces false positives on legitimate code:{"name": "value"} # → {"name": "***"}Changes
agent/redact.py:code_fileparameter toredact_sensitive_text()code_file=True: skip ENV assignment and JSON field patternstools/file_tools.py:code_file=Truewhen the target file has a recognized source code extension (.py,.js,.ts,.java,.go,.rs,.rb,.c,.cpp,.h,.jsx,.tsx,.vue,.sh,.yaml,.yml,.json,.toml,.cfg,.ini,.xml,.html,.css,.scss,.sql,.md,.rst)Testing
Before fix:
read_fileon Python source replaces_TOKENS=***assignmentsAfter fix: code files show original content; real
sk-xxxAPI keys still redactedCloses #15934