Skip to content

fix(analyzer): detect full environment reads via AST - #332

Draft
mohgupta-ship-it wants to merge 1 commit into
mainfrom
codex/fix-issue-329-env-ast
Draft

fix(analyzer): detect full environment reads via AST#332
mohgupta-ship-it wants to merge 1 commit into
mainfrom
codex/fix-issue-329-env-ast

Conversation

@mohgupta-ship-it

Copy link
Copy Markdown
Member

Summary

Replaces the spelling-sensitive Python E2 full-environment checks with AST-based detection.

  • Detects complete environment materialization or enumeration through copy(), dict(os.environ), dict unpacking, .items(), direct iteration, and copy.copy() variants.
  • Resolves os / environ import aliases and remains insensitive to formatting such as os . environ . copy ().
  • Preserves non-Python checks and a regex fallback for syntactically invalid Python.
  • Does not treat a single-key read or passing os.environ to a child process as environment harvesting.

Root cause

E2 matched literal text such as os.environ.copy(); semantically equivalent syntax and import aliases bypassed the rule. This AST-based implementation covers the full reproduction set from the issue without broad argument-matching false positives.

Validation

  • uv run --no-sync python -m pytest tests/nodes/analyzers/test_static_patterns.py tests/unit/test_patterns.py -q
  • uv run --with hatchling --no-sync python -m pytest -qq --disable-warnings -m "not integration and not provider" tests/
  • uv run --no-sync make lint
  • uv run --no-sync make format-check

This is a broader AST-based alternative to the regex-only coverage in #331.

Fixes #329

Created by Codex on behalf of Mohit.

Signed-off-by: Mohit Gupta <mohgupta@nvidia.com>
@mohgupta-ship-it
mohgupta-ship-it force-pushed the codex/fix-issue-329-env-ast branch from 73baca8 to 641614e Compare August 2, 2026 09:27
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