fix(analyzer): make E2 whitespace-tolerant and detect all os.environ read forms - #331
fix(analyzer): make E2 whitespace-tolerant and detect all os.environ read forms#331weed33834 wants to merge 1 commit into
Conversation
rng1995
left a comment
There was a problem hiding this comment.
[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.
998d750 to
77a6ce5
Compare
| (r"dict\s*\(\s*os\s*\.\s*environ\s*\)", 0.6), | ||
| (r"\{\s*\*\*\s*os\s*\.\s*environ\s*\}", 0.6), | ||
| # Python: {**os.environ} — full environ read via spread | ||
| (r"\*\*\s*os\s*\.\s*environ", 0.6), |
There was a problem hiding this comment.
Blocking: broadening the prior mapping-literal regex to bare ** makes the malformed-Python fallback flag exponentiation. On this exact head, result = 2 ** os.environ plus a syntax error elsewhere produces an E2 finding on line 2, even though the existing valid-Python negative test correctly treats this expression as non-harvesting. Keep mapping-unpack boundaries or otherwise distinguish unpacking from exponentiation, and add a fallback-path regression.
rng1995
left a comment
There was a problem hiding this comment.
[Automated SkillSpector Review]
Re-review: requesting changes on the new head. The 19 focused E2 tests and Ruff lint pass, but the conflict-resolution commit broadens the malformed-Python fallback from mapping unpacking to bare ** os.environ. Exact-head verification shows 2 ** os.environ is then reported as E2 when another syntax error triggers fallback. Restore unpacking boundaries or equivalent parsing and cover the malformed negative case. GitHub also reports merge conflicts.
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.
77a6ce5 to
a92654b
Compare
Summary
The E2 (Env Variable Harvesting) regex patterns are spell-checkers, not behavior detectors.
os\.environwithout optional whitespace betweenosand.means that inserting PEP8-irrelevant whitespace —os . environ . copy ()— bypasses detection entirely. A skill scoringDO_NOT_INSTALLwith canonical syntax can be rewritten toSAFEby adding spaces. The same blind spot letsdict(os.environ)and{**os.environ}pass clean, even though they do exactly what the rule is meant to catch.Changes
Whitespace-tolerant
os.environmatching —\s*betweenosand\.in all Python E2 patterns, so whitespace variants no longer bypass detection.New patterns —
dict(os.environ)and{**os.environ}(the two most common alternative forms of reading the full environment mapping) are now detected.5 regression tests added to
test_patterns.py.Testing
Fixes #329