Skip to content

Python -c analysis#134

Open
nickdavies wants to merge 2 commits intoldayton:mainfrom
nickdavies:python-c-analysis
Open

Python -c analysis#134
nickdavies wants to merge 2 commits intoldayton:mainfrom
nickdavies:python-c-analysis

Conversation

@nickdavies
Copy link
Copy Markdown
Contributor

This PR stacks on top of #122 and provides analysis of python -c usage. It attempts to deny any analysis on commands that contain any kind of expansion because that makes it too difficult to determine safety.

It is easier to review this diff once the lower one is merged but if you have any questions let me know, I am happy to add more tests or make changes

Nick Davies added 2 commits March 31, 2026 18:19
Add python-allow-module and python-deny-module config directives so
users can customize which Python modules are considered safe or
dangerous during static analysis.

- Config: parse and validate module names (dotted identifiers only),
  accumulate across config layers, support inline comments
- SafetyAnalyzer: parameterize with extra_safe_modules/extra_deny_modules
  merged with hardcoded sets. Allow overrides exact matches in the
  dangerous list (submodules must be allowed separately).
- Thread Config through HandlerContext so python handler can access
  configured module lists.

Example .dippy config:
  python-allow-module numpy
  python-allow-module pandas
  python-deny-module requests
- Statically analyze python -c inline code using the existing
  SafetyAnalyzer AST visitor. Safe code (no I/O, no dangerous imports)
  is auto-approved.
- Track per-word bash expansion flags (word_has_expansions) through
  HandlerContext so the python handler can detect when -c code contains
  $VAR or $(cmd) expansions and fall back to ask.
- Config module overrides (python-allow-module / python-deny-module)
  apply to inline code analysis as well.
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.

1 participant