Skip to content

fix(redact): don't mask programmatic env lookups in KEY=value redaction (salvage #2854) - #58534

Merged
teknium1 merged 1 commit into
mainfrom
salvage/2854-redact-getenv-skip
Jul 5, 2026
Merged

fix(redact): don't mask programmatic env lookups in KEY=value redaction (salvage #2854)#58534
teknium1 merged 1 commit into
mainfrom
salvage/2854-redact-getenv-skip

Conversation

@teknium1

@teknium1 teknium1 commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Summary

The secret redactor no longer corrupts pasted code that assigns from environment lookups — ha_token=os.getenv('HOMEASSISTANT_TOKEN') stays intact instead of becoming ha_token=os.get...EN'). Fixes #2852.

Salvage of #2854 by @crazywriter1 — same intent, relocated: the PR inserted an unconditional redaction pass before the code_file gate that grew after it branched, which would have reintroduced the code-file false-positive class and duplicated the env pass. The skip now lives inside the existing gated _redact_env closure, which all three relevant regex passes share (_ENV_ASSIGN_RE, _CFG_DOTTED_RE, _CFG_ANCHORED_RE) — so the lowercase ha_token= corruption the issue reported is fixed too, which the PR's placement missed. Tests adapted from the PR; co-authored credit on the commit.

Changes

  • agent/redact.py: _ENV_LOOKUP_VALUE_RE (os.getenv / os.environ[...] / os.environ.get / process.env / $ENV{) + skip inside _redact_env (+13).
  • tests/agent/test_redact.py: TestEnvLookupPreserved — 9 tests incl. negatives proving real secrets still mask (+46).

Validation

Before (main, live repro) After
MY_API_KEY=os.getenv('OPENAI_API_KEY') MY_API_KEY=*** unchanged
ha_token=os.getenv("HOMEASSISTANT_TOKEN") ha_token=os.get...EN") unchanged
OPENAI_API_KEY=sk-abc123... masked still masked
tests/agent/test_redact.py (full file) pass

Infographic

pr-2854-salvage

'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 #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 #2852-fix #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>
@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint area/auth Authentication, OAuth, credential pools sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data labels Jul 4, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Salvage of #2854 (@crazywriter1) fixing #2852 — related, not a duplicate: the redaction skip was relocated inside the gated _redact_env closure (shared by _ENV_ASSIGN_RE/_CFG_DOTTED_RE/_CFG_ANCHORED_RE), which also fixes the lowercase ha_token= corruption the original placement missed.

@teknium1
teknium1 merged commit 4eaf5ba into main Jul 5, 2026
31 checks passed
@teknium1
teknium1 deleted the salvage/2854-redact-getenv-skip branch July 5, 2026 07:45
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
…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
…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
…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

area/auth Authentication, OAuth, credential pools comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P3 Low — cosmetic, nice to have sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data 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