Skip to content

fix(redact): skip env-assignment redaction for os.getenv/os.environ lookups (#2852) - #2854

Closed
crazywriter1 wants to merge 2 commits into
NousResearch:mainfrom
crazywriter1:fix/2852-redaction-getenv
Closed

fix(redact): skip env-assignment redaction for os.getenv/os.environ lookups (#2852)#2854
crazywriter1 wants to merge 2 commits into
NousResearch:mainfrom
crazywriter1:fix/2852-redaction-getenv

Conversation

@crazywriter1

Copy link
Copy Markdown
Contributor

Summary

Fixes #2852redact_sensitive_text() treated Python lines like ha_token=os.getenv('HOMEASSISTANT_TOKEN') as shell-style secret assignments. The RHS was passed through _mask_token(), corrupting source code (e.g. os.get...EN')).

Fix

In _redact_env, skip masking when the captured value starts with os.getenv or os.environ (programmatic env lookup, not a literal secret).

Tests

  • Added TestEnvLookupPreserved in tests/agent/test_redact.py (getenv, environ.get, bracket access, spaced =, multiline skill snippet, and a check that real KEY=jwt... assignments are still redacted).

Test plan

  • pytest tests/agent/test_redact.py — 38 passed

…ookups (NousResearch#2852)

The _ENV_ASSIGN_RE pattern matched ha_token=os.getenv(...) and treated the whole RHS as a secret value, corrupting skill source code.

Skip masking when the value starts with os.getenv or os.environ.

Add regression tests for getenv, environ.get, bracket access, and multiline skill snippets.

Fixes NousResearch#2852
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint labels May 2, 2026
@crazywriter1

Copy link
Copy Markdown
Contributor Author

Rebased onto main, conflict with the new code_file guard. That guard fixes #2852 only when callers pass code_file=True. The os.getenv/os.environ skip is still needed for the default path (e.g. MY_API_TOKEN=os.getenv(...) without code_file). Merged both in _redact_env.

@teknium1 teknium1 closed this in 9e872db Jul 5, 2026
teknium1 added a commit that referenced this pull request Jul 5, 2026
…v-skip

fix(redact): don't mask programmatic env lookups in KEY=value redaction (salvage #2854)
habarmc1223-sudo pushed a commit to habarmc1223-sudo/hermes-agent-fluxmem that referenced this pull request Jul 8, 2026
'KEY=os.getenv(...)' / 'os.environ[...]' / 'process.env.X' values are
variable-name references in code snippets, not leaked secrets. Masking
them corrupted pasted code in prose/log contexts (issue NousResearch#2852):
ha_token=os.getenv('HOMEASSISTANT_TOKEN') -> ha_token=os.get...EN').

Skip these values inside _redact_env, which covers all three passes that
share the closure (_ENV_ASSIGN_RE, _CFG_DOTTED_RE, _CFG_ANCHORED_RE).
Real secret values are still masked.

Salvage of PR NousResearch#2852-fix NousResearch#2854 — the PR's own placement (an unconditional
pass before the code_file gate) would have reintroduced the code-file
false-positive class; the skip is applied inside the existing gated pass
instead. Tests adapted from the PR.

Co-authored-by: crazywriter1 <sampiyonyus@gmail.com>
habarmc1223-sudo pushed a commit to habarmc1223-sudo/hermes-agent-fluxmem that referenced this pull request Jul 8, 2026
…redact-getenv-skip

fix(redact): don't mask programmatic env lookups in KEY=value redaction (salvage NousResearch#2854)
santhreal pushed a commit to santhreal/hermes-agent that referenced this pull request Jul 13, 2026
'KEY=os.getenv(...)' / 'os.environ[...]' / 'process.env.X' values are
variable-name references in code snippets, not leaked secrets. Masking
them corrupted pasted code in prose/log contexts (issue NousResearch#2852):
ha_token=os.getenv('HOMEASSISTANT_TOKEN') -> ha_token=os.get...EN').

Skip these values inside _redact_env, which covers all three passes that
share the closure (_ENV_ASSIGN_RE, _CFG_DOTTED_RE, _CFG_ANCHORED_RE).
Real secret values are still masked.

Salvage of PR NousResearch#2852-fix NousResearch#2854 — the PR's own placement (an unconditional
pass before the code_file gate) would have reintroduced the code-file
false-positive class; the skip is applied inside the existing gated pass
instead. Tests adapted from the PR.

Co-authored-by: crazywriter1 <sampiyonyus@gmail.com>
santhreal pushed a commit to santhreal/hermes-agent that referenced this pull request Jul 13, 2026
…redact-getenv-skip

fix(redact): don't mask programmatic env lookups in KEY=value redaction (salvage NousResearch#2854)
Gravezzz pushed a commit to Gravezzz/hermes-agent that referenced this pull request Jul 21, 2026
'KEY=os.getenv(...)' / 'os.environ[...]' / 'process.env.X' values are
variable-name references in code snippets, not leaked secrets. Masking
them corrupted pasted code in prose/log contexts (issue NousResearch#2852):
ha_token=os.getenv('HOMEASSISTANT_TOKEN') -> ha_token=os.get...EN').

Skip these values inside _redact_env, which covers all three passes that
share the closure (_ENV_ASSIGN_RE, _CFG_DOTTED_RE, _CFG_ANCHORED_RE).
Real secret values are still masked.

Salvage of PR NousResearch#2852-fix NousResearch#2854 — the PR's own placement (an unconditional
pass before the code_file gate) would have reintroduced the code-file
false-positive class; the skip is applied inside the existing gated pass
instead. Tests adapted from the PR.

Co-authored-by: crazywriter1 <sampiyonyus@gmail.com>
Gravezzz pushed a commit to Gravezzz/hermes-agent that referenced this pull request Jul 21, 2026
…redact-getenv-skip

fix(redact): don't mask programmatic env lookups in KEY=value redaction (salvage NousResearch#2854)
leewenjie pushed a commit to leewenjie/hermes-agent that referenced this pull request Aug 7, 2026
'KEY=os.getenv(...)' / 'os.environ[...]' / 'process.env.X' values are
variable-name references in code snippets, not leaked secrets. Masking
them corrupted pasted code in prose/log contexts (issue NousResearch#2852):
ha_token=os.getenv('HOMEASSISTANT_TOKEN') -> ha_token=os.get...EN').

Skip these values inside _redact_env, which covers all three passes that
share the closure (_ENV_ASSIGN_RE, _CFG_DOTTED_RE, _CFG_ANCHORED_RE).
Real secret values are still masked.

Salvage of PR NousResearch#2852-fix NousResearch#2854 — the PR's own placement (an unconditional
pass before the code_file gate) would have reintroduced the code-file
false-positive class; the skip is applied inside the existing gated pass
instead. Tests adapted from the PR.

Co-authored-by: crazywriter1 <sampiyonyus@gmail.com>
leewenjie pushed a commit to leewenjie/hermes-agent that referenced this pull request Aug 7, 2026
…redact-getenv-skip

fix(redact): don't mask programmatic env lookups in KEY=value redaction (salvage NousResearch#2854)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: LLM token redaction breaking on .env handling on scripts

2 participants