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

…read forms

The E2 (Env Variable Harvesting) regex patterns used `os\.environ` without
optional whitespace between `os` and `.environ`, so inserting PEP8-irrelevant
whitespace (`os . environ . copy ()`) bypassed detection entirely. This meant
a skill scoring `DO_NOT_INSTALL` with canonical syntax could be rewritten to
`SAFE` by adding spaces.

Changes:
- Add `\s*` between `os` and `\.` in all Python os.environ patterns so that
  whitespace variants are detected uniformly.
- Add patterns for `dict(os.environ)` and `{**os.environ}`, the two most
  common alternative forms of reading the full environment mapping.
- Add 5 regression tests covering whitespace-tolerant and alternative forms.

Fixes NVIDIA#329
Signed-off-by: weed33834 <weed33834@users.noreply.github.com>
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

1 participant