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
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.
77a6ce5 to
a92654b
Compare
|
@weed33834 - Please address review comments and resolve merge conflicts. Resolve any review comments that have been addressed |
a92654b to
f950c35
Compare
…sting (NVIDIA#331) Signed-off-by: badhope <game33834@outlook.com>
247e544 to
903d4c2
Compare
|
Hi @rng1995 and maintainers — the DCO issue is now fixed. The branch was rewritten so all commits in this PR carry a proper The only remaining blocker is that CI runs on this fork PR require maintainer approval (currently @rng1995 if possible, could you re-review the latest head (903d4c2)? The previous CHANGES_REQUESTED was against an older commit. |
|
@weed33834 - Fix the CI issues please |
…read forms
The E2 regex fallback (used when Python source cannot be parsed by AST)
was missing several common os.environ access patterns and was not
whitespace-tolerant for the patterns it did cover.
Add fallback patterns for:
- os.environ['KEY'] / os.environ["KEY"] (whitespace-tolerant)
- os.environ.get('KEY') (whitespace-tolerant)
All existing patterns (items(), copy(), dict(), {**} spread) retain
whitespace tolerance. The dict-spread regex explicitly requires braces
({**os.environ}) so bare exponentiation (2 ** os.environ) is not
flagged as environment harvesting.
AST-level detection (used when Python parses successfully) now also
covers:
- os.environ['KEY'] / os.environ["KEY"] via ast.Subscript handling
- os.environ.get('KEY') by adding 'get' and 'setdefault' to the
_ENVIRONMENT_MAPPING_METHOD_CONFIDENCE mapping
This closes the gap where whitespace-obfuscated access
(e.g. `os . environ [ 'API_KEY' ]`) was parsed by the AST but not
emitted as a finding because Subscript nodes were not checked and
the 'get' method was not in the confidence table.
Add regression tests:
- Whitespace-obfuscated environ access is detected (>= 2 findings)
- 2 ** os.environ (exponentiation) is NOT flagged as E2
- {**os.environ} (dict spread) IS flagged as E2
Signed-off-by: badhope <weed33834@users.noreply.github.com>
26e6371 to
5387c3e
Compare
|
Thanks for the heads-up @rng1995. Both CI issues are now fixed. DCO CheckThe original branch had 5 merge commits without test-unit:
|
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