fix(agent/redact): preserve lowercase Python variable assignments from redaction#4368
Open
InB4DevOps wants to merge 1 commit intoNousResearch:mainfrom
Open
fix(agent/redact): preserve lowercase Python variable assignments from redaction#4368InB4DevOps wants to merge 1 commit intoNousResearch:mainfrom
InB4DevOps wants to merge 1 commit intoNousResearch:mainfrom
Conversation
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.
Fix: Preserve lowercase Python variable assignments from redaction
Problem
The redaction regex in
agent/redact.pyincorrectly redacted values of lowercase Python variable assignments, treating them as environment variables containing secrets.Before:
Was incorrectly transformed to:
Root Cause
The
_ENV_ASSIGN_REregex used there.IGNORECASEflag, which caused it to match lowercase Python variable names (likebefore_tokens,api_key,my_token) in addition to uppercase environment variables (likeAPI_KEY,OPENAI_API_KEY).Solution
re.IGNORECASEflag — now only ALL-uppercase environment variables match(?:(?:^|\s))anchor — ensures match starts at beginning of string or after whitespacetest_lowercase_python_vars_not_redactedwith 3 test casesChanges
agent/redact.pyre.IGNORECASEflagtests/agent/test_redact.pytest_lowercase_python_vars_not_redactedmethodbefore_tokens,my_token,api_keyTesting
All 39 tests pass:
python3 -m pytest tests/agent/test_redact.py -v # 39 passed, 5 warnings in 0.35sVerification
Before fix:
After fix:
Closes: #4367