fix(redact): add code_file param to skip false-positive ENV/JSON patterns#19715
Merged
Conversation
…erns ENV-assignment and JSON-field regex patterns in redact_sensitive_text() cause false positives when reading source code files: - MAX_TOKENS=*** triggers the ENV assignment pattern - "apiKey": "test" in test fixtures triggers the JSON field pattern Add code_file=False parameter. When code_file=True, skip only the ENV-assignment and JSON-field regex passes; all other patterns (prefixes, auth headers, private keys, DB connstrings, JWTs, URL secrets) are still applied. Update file_tools.py (read_file and search_files) to pass code_file=True so agent code analysis is not polluted by false-positive redactions. Closes #15934
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.
Salvage of #16127 by @ms-alan onto current main.
Summary
ENV_ASSIGNandJSON_FIELDregex patterns inredact_sensitive_text()cause false positives when reading source code files —MAX_TOKENS=***triggers the ENV-assignment pattern even though it's a constant definition, and"apiKey": "test"in test fixtures matches the JSON-field pattern. Both are safe content in that context. Add acode_file=Trueflag that skips those two patterns while keeping prefix patterns, auth headers, private keys, DB connstrings, JWTs, and URL secrets always redacted.Conflict resolution during salvage
Main has since added a
force: bool = Falsekeyword-only param to the signature. Merged signatures to accept both kwargs:redact_sensitive_text(text, *, force=False, code_file=False). Docstring updated to explain both flags.Note on authorship
The contributor's original commit had an empty author email (
pander <>, local git-config quirk). Re-attributed toms-alan <chenb19870707@gmail.com>(GitHub public email) during salvage so the commit passes AUTHOR_MAP validation.Changes
code_file=Trueskips ENV/JSON patterns (+20/-14)Validation
scripts/run_tests.sh tests/agent/ -k redact -> 78 passed
Original PR: #16127
Fixes: #15934