Skip to content

fix(analyzer): make E2 whitespace-tolerant and detect all os.environ read forms - #331

Open
weed33834 wants to merge 1 commit into
NVIDIA:mainfrom
weed33834:fix/e2-whitespace-tolerant-env-harvesting
Open

fix(analyzer): make E2 whitespace-tolerant and detect all os.environ read forms#331
weed33834 wants to merge 1 commit into
NVIDIA:mainfrom
weed33834:fix/e2-whitespace-tolerant-env-harvesting

Conversation

@weed33834

@weed33834 weed33834 commented Aug 2, 2026

Copy link
Copy Markdown

Summary

The E2 (Env Variable Harvesting) regex patterns are spell-checkers, not behavior detectors. os\.environ without optional whitespace between os and . means that inserting PEP8-irrelevant whitespace — os . environ . copy () — bypasses detection entirely. A skill scoring DO_NOT_INSTALL with canonical syntax can be rewritten to SAFE by adding spaces. The same blind spot lets dict(os.environ) and {**os.environ} pass clean, even though they do exactly what the rule is meant to catch.

Changes

  1. Whitespace-tolerant os.environ matching\s* between os and \. in all Python E2 patterns, so whitespace variants no longer bypass detection.

  2. New patternsdict(os.environ) and {**os.environ} (the two most common alternative forms of reading the full environment mapping) are now detected.

  3. 5 regression tests added to test_patterns.py.

Testing

$ python -m pytest tests/unit/test_patterns.py tests/nodes/analyzers/test_static_patterns.py -v
157 passed in 2.07s
$ make lint && make format
All checks passed!
157 files left unchanged

Fixes #329

rng1995
rng1995 previously approved these changes Aug 5, 2026

@rng1995 rng1995 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Automated SkillSpector Review]

Approved. The E2 additions cover whitespace-obfuscated os.environ access plus full-environment reads through dict() and mapping unpacking without changing the rule schema. Focused E2 regressions passed (7 tests), as did Ruff lint and format checks.

The upstream refactored the E2 regex fallback list to use
E2_PYTHON_FALLBACK_PATTERNS (instead of E2_PATTERNS) and added a
comprehensive AST-based environment-read analysis. Our PR's improved
regex patterns (whitespace-tolerant, os.environ["KEY"], {**os.environ}
spread) are merged into the upstream variable name, and the upstream's
more thorough test suite is retained.

All 19 E2-specific tests and 303 unit tests pass.
@weed33834
weed33834 force-pushed the fix/e2-whitespace-tolerant-env-harvesting branch from 998d750 to 77a6ce5 Compare August 6, 2026 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

E2 "Env Variable Harvesting" matches one spelling, so whitespace alone flips DO_NOT_INSTALL to SAFE

2 participants