Skip to content

fix(redact): skip ENV/JSON patterns on code files to avoid false positives#15923

Closed
zons-zhaozhy wants to merge 2 commits into
NousResearch:mainfrom
zons-zhaozhy:fix/redact-code-file-false-positives
Closed

fix(redact): skip ENV/JSON patterns on code files to avoid false positives#15923
zons-zhaozhy wants to merge 2 commits into
NousResearch:mainfrom
zons-zhaozhy:fix/redact-code-file-false-positives

Conversation

@zons-zhaozhy

@zons-zhaozhy zons-zhaozhy commented Apr 26, 2026

Copy link
Copy Markdown

Summary

redact_sensitive_text() applies ENV assignment (FOO=***) and JSON field ("key": "value") patterns to all text, including source code returned by read_file/search_files. This produces false positives on legitimate code:

_TOKENS = {"foo": 1}  # → _*** = {"foo": 1}
{"name": "value"}  # → {"name": "***"}

Changes

agent/redact.py:

  • Add code_file parameter to redact_sensitive_text()
  • When code_file=True: skip ENV assignment and JSON field patterns
  • Keep high-confidence patterns (known prefixes, JWTs, private keys, DB connstrings, auth headers) — real secrets can appear in code too

tools/file_tools.py:

  • Pass code_file=True when 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_file on Python source replaces _TOKENS=*** assignments
After fix: code files show original content; real sk-xxx API keys still redacted

Closes #15934

…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.
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent loop, run_agent.py, prompt builder tool/file File tools (read, write, patch, search) labels Apr 26, 2026
@zons-zhaozhy zons-zhaozhy deleted the fix/redact-code-file-false-positives branch May 4, 2026 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder P2 Medium — degraded but workaround exists tool/file File tools (read, write, patch, search) type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(redact): ENV/JSON regex patterns cause false positives on source code files

3 participants