fix(analyzers): share Python AST parsing for environment-read detection - #332
Conversation
73baca8 to
641614e
Compare
|
Could this PR also introduce a shared Python AST parsing utility for the existing AST analyzer, output_handling, data_exfiltration, and future AST-backed analyzers? Each currently parses Python independently. Centralizing parsing would avoid repeated full-file parses during a scan and give us one place for syntax-error handling, alias resolution, and eventually scope-aware name resolution. E2 can still own its detection logic here; it would simply consume the shared parsed tree. |
Signed-off-by: Mohit Gupta <mohgupta@nvidia.com>
Signed-off-by: Mohit Gupta <mohgupta@nvidia.com>
641614e to
1bf8b72
Compare
|
Valid calls such as |
Signed-off-by: keshavp <32313895+keshprad@users.noreply.github.com>
keshprad
left a comment
There was a problem hiding this comment.
Approved: the keyword-form E2 regression is fixed, focused validation passes, and all PR checks are green.
Summary
Replaces spelling-sensitive Python E2 checks with AST-based environment-read detection and introduces shared per-scan Python AST parsing for all AST-consuming analyzers.
copy(),dict(os.environ), dict unpacking,.items(), direct iteration, andcopy.copy()variants.osandenvironimport aliases and is insensitive to formatting such asos . environ . copy ().os.environto a child process as full-environment harvesting.Motivation
E2 previously matched literal text such as
os.environ.copy(), so aliases and equivalent Python syntax bypassed the rule. The shared AST layer fixes that detection gap while removing duplicate parsing across analyzer branches.Validation
uv run --no-sync python -m pytest tests/nodes/analyzers/test_static_patterns.py tests/unit/test_patterns.py -quv run --with hatchling --no-sync python -m pytest -qq --disable-warnings -m "not integration and not provider" tests/uv run --no-sync make lintuv run --no-sync make format-checkThis supersedes the regex-only coverage in #331.
Fixes #329