fix(redact): remove re.IGNORECASE from _ENV_ASSIGN_RE to prevent masking lowercase variables#4476
Closed
gnanam1990 wants to merge 1 commit into
Closed
Conversation
…ing lowercase variables The _ENV_ASSIGN_RE pattern was compiled with re.IGNORECASE, causing it to match lowercase variable assignments like `token = await ...` and `before_tokens = response.usage` as if they were secret environment variables. This caused two reported bugs: - NousResearch#4367: Python variable assignments (before_tokens, api_key, my_token) being incorrectly redacted in logs and tool output - NousResearch#4451: TypeScript/JS `await` keyword corrupted to `***` in patch tool output because `const token = await getToken()` matched the pattern, replacing `await` with `***` and stripping the surrounding whitespace Fix: remove re.IGNORECASE so only ALL-UPPERCASE env var names match. Add (?:^|(?<=\s)) lookbehind to prevent the pattern from consuming leading whitespace (e.g. `export SECRET=...` preserved correctly). Adds regression tests covering both Python and TypeScript/JS cases. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
teknium1
added a commit
that referenced
this pull request
Apr 5, 2026
…4367) Add 5 regression tests from PR #4476 (gnanam1990) to prevent re-introducing the IGNORECASE bug that caused lowercase Python/TypeScript variable assignments to be incorrectly redacted as secrets. The core fix landed in 6367e1c. Tests cover: - Lowercase Python variable with 'token' in name - Lowercase Python variable with 'api_key' in name - TypeScript 'await' not treated as secret value - TypeScript 'secret' variable assignment - 'export' prefix preserved for uppercase env vars Co-authored-by: gnanam1990 <gnanam1990@users.noreply.github.com>
This was referenced Apr 5, 2026
Contributor
|
The core fix already landed on main in commit 6367e1c by @LucidPaths. Your regression tests were the most comprehensive of the three submissions — we salvaged all 5 tests into PR #5185 with your co-authorship preserved. Thanks for the thorough test coverage! |
teknium1
added a commit
that referenced
this pull request
Apr 5, 2026
…4367) (#5185) Add 5 regression tests from PR #4476 (gnanam1990) to prevent re-introducing the IGNORECASE bug that caused lowercase Python/TypeScript variable assignments to be incorrectly redacted as secrets. The core fix landed in 6367e1c. Tests cover: - Lowercase Python variable with 'token' in name - Lowercase Python variable with 'api_key' in name - TypeScript 'await' not treated as secret value - TypeScript 'secret' variable assignment - 'export' prefix preserved for uppercase env vars Co-authored-by: gnanam1990 <gnanam1990@users.noreply.github.com>
Tommyeds
pushed a commit
to Tommyeds/hermes-agent
that referenced
this pull request
Apr 12, 2026
…ousResearch#4367) (NousResearch#5185) Add 5 regression tests from PR NousResearch#4476 (gnanam1990) to prevent re-introducing the IGNORECASE bug that caused lowercase Python/TypeScript variable assignments to be incorrectly redacted as secrets. The core fix landed in 6367e1c. Tests cover: - Lowercase Python variable with 'token' in name - Lowercase Python variable with 'api_key' in name - TypeScript 'await' not treated as secret value - TypeScript 'secret' variable assignment - 'export' prefix preserved for uppercase env vars Co-authored-by: gnanam1990 <gnanam1990@users.noreply.github.com>
angelburgosrosado
pushed a commit
to angelburgosrosado/hermes-agent
that referenced
this pull request
Apr 27, 2026
…ousResearch#4367) (NousResearch#5185) Add 5 regression tests from PR NousResearch#4476 (gnanam1990) to prevent re-introducing the IGNORECASE bug that caused lowercase Python/TypeScript variable assignments to be incorrectly redacted as secrets. The core fix landed in 332c115. Tests cover: - Lowercase Python variable with 'token' in name - Lowercase Python variable with 'api_key' in name - TypeScript 'await' not treated as secret value - TypeScript 'secret' variable assignment - 'export' prefix preserved for uppercase env vars Co-authored-by: gnanam1990 <gnanam1990@users.noreply.github.com>
angelburgosrosado
pushed a commit
to angelburgosrosado/hermes-agent
that referenced
this pull request
Apr 28, 2026
…ousResearch#4367) Add 5 regression tests from PR NousResearch#4476 (gnanam1990) to prevent re-introducing the IGNORECASE bug that caused lowercase Python/TypeScript variable assignments to be incorrectly redacted as secrets. The core fix landed in 332c115. Tests cover: - Lowercase Python variable with 'token' in name - Lowercase Python variable with 'api_key' in name - TypeScript 'await' not treated as secret value - TypeScript 'secret' variable assignment - 'export' prefix preserved for uppercase env vars Co-authored-by: gnanam1990 <gnanam1990@users.noreply.github.com>
02356abc
pushed a commit
to 02356abc/hermes-agent
that referenced
this pull request
May 14, 2026
…ousResearch#4367) (NousResearch#5185) Add 5 regression tests from PR NousResearch#4476 (gnanam1990) to prevent re-introducing the IGNORECASE bug that caused lowercase Python/TypeScript variable assignments to be incorrectly redacted as secrets. The core fix landed in 6367e1c. Tests cover: - Lowercase Python variable with 'token' in name - Lowercase Python variable with 'api_key' in name - TypeScript 'await' not treated as secret value - TypeScript 'secret' variable assignment - 'export' prefix preserved for uppercase env vars Co-authored-by: gnanam1990 <gnanam1990@users.noreply.github.com>
olympus-terminal
pushed a commit
to olympus-terminal/hermes-agent
that referenced
this pull request
May 16, 2026
…ousResearch#4367) (NousResearch#5185) Add 5 regression tests from PR NousResearch#4476 (gnanam1990) to prevent re-introducing the IGNORECASE bug that caused lowercase Python/TypeScript variable assignments to be incorrectly redacted as secrets. The core fix landed in 80522ed. Tests cover: - Lowercase Python variable with 'token' in name - Lowercase Python variable with 'api_key' in name - TypeScript 'await' not treated as secret value - TypeScript 'secret' variable assignment - 'export' prefix preserved for uppercase env vars Co-authored-by: gnanam1990 <gnanam1990@users.noreply.github.com>
gweeteve
pushed a commit
to gweeteve/hermes-agent
that referenced
this pull request
Jun 2, 2026
…ousResearch#4367) (NousResearch#5185) Add 5 regression tests from PR NousResearch#4476 (gnanam1990) to prevent re-introducing the IGNORECASE bug that caused lowercase Python/TypeScript variable assignments to be incorrectly redacted as secrets. The core fix landed in 6367e1c. Tests cover: - Lowercase Python variable with 'token' in name - Lowercase Python variable with 'api_key' in name - TypeScript 'await' not treated as secret value - TypeScript 'secret' variable assignment - 'export' prefix preserved for uppercase env vars Co-authored-by: gnanam1990 <gnanam1990@users.noreply.github.com>
Egavasyug
pushed a commit
to Egavasyug/hermes-agent
that referenced
this pull request
Jun 10, 2026
…ousResearch#4367) (NousResearch#5185) Add 5 regression tests from PR NousResearch#4476 (gnanam1990) to prevent re-introducing the IGNORECASE bug that caused lowercase Python/TypeScript variable assignments to be incorrectly redacted as secrets. The core fix landed in 454d48b. Tests cover: - Lowercase Python variable with 'token' in name - Lowercase Python variable with 'api_key' in name - TypeScript 'await' not treated as secret value - TypeScript 'secret' variable assignment - 'export' prefix preserved for uppercase env vars Co-authored-by: gnanam1990 <gnanam1990@users.noreply.github.com>
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.
Root Cause
_ENV_ASSIGN_REwas compiled withre.IGNORECASE, making the uppercase-only pattern[A-Z_]*TOKEN[A-Z_]*also match lowercase names. This caused two distinct bugs:Bugs Fixed
#4367 — Python variable assignments incorrectly redacted
#4451 —
awaitkeyword corrupted in TypeScript/TSX patch tool outputThe
awaitkeyword was being redacted becausetoken(lowercase) matched the pattern withre.IGNORECASE, andawaitwas the first non-whitespace word after=, so_mask_token("await")→***(5 chars < 18).Fix
Two changes to
_ENV_ASSIGN_RE:re.IGNORECASE— only ALL-UPPERCASE env var names should match (e.g.API_KEY,SECRET_TOKEN). Lowercase Python/JS/TS variable names are never redacted.(?:^|(?<=\s))lookbehind — prevents the pattern from consuming leading whitespace, soexport SECRET_TOKEN=valuestaysexport SECRET_TOKEN=***(notexportSECRET_TOKEN=***).Tests
Added 5 new regression tests in
TestEnvAssignments:test_lowercase_python_variable_token_unchanged— [Bug]: Redaction incorrectly masks lowercase Python variable assignments #4367test_lowercase_python_variable_api_key_unchanged— [Bug]: Redaction incorrectly masks lowercase Python variable assignments #4367test_typescript_await_token_unchanged— patch tool: await keyword corruption in TypeScript/TSX files #4451test_typescript_await_secret_unchanged— patch tool: await keyword corruption in TypeScript/TSX files #4451test_export_whitespace_preserved— whitespace regressionAll 43 tests pass.
Fixes #4367
Fixes #4451
🤖 Generated with Claude Code