Skip to content

Add configurable Python module lists via config directives - #122

Merged
ldayton merged 1 commit into
ldayton:mainfrom
nickdavies:claude/python-configurable-modules-GCu5f
Jun 8, 2026
Merged

Add configurable Python module lists via config directives#122
ldayton merged 1 commit into
ldayton:mainfrom
nickdavies:claude/python-configurable-modules-GCu5f

Conversation

@nickdavies

Copy link
Copy Markdown
Contributor

I wanted to be able to configure Python modules in preparation for enabling -c analysis. I'm not super familiar with the codebase so please let me know what you think of the approach. Happy to adjust to match any style etc.

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

@nickdavies nickdavies closed this Mar 31, 2026
@nickdavies
nickdavies deleted the claude/python-configurable-modules-GCu5f branch March 31, 2026 23:45
@nickdavies
nickdavies restored the claude/python-configurable-modules-GCu5f branch March 31, 2026 23:51
@nickdavies nickdavies reopened this Mar 31, 2026
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
@nickdavies
nickdavies force-pushed the claude/python-configurable-modules-GCu5f branch from 7910583 to 42ddb64 Compare April 1, 2026 00:36
@nickdavies nickdavies mentioned this pull request Apr 1, 2026
@nickdavies
nickdavies marked this pull request as ready for review April 1, 2026 00:42

@ldayton ldayton left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this — and sorry for the long wait on review.

This is a clean, self-contained change. A few things I checked that made me comfortable merging it on its own:

  • When no python-allow-module/python-deny-module is configured, behavior is byte-identical to before (empty sets), so there's no change for users who don't opt in.
  • allow overriding the hardcoded dangerous list via exact-match set subtraction is correct — submodules like http.server stay denied because they're separate entries, so allowing http doesn't leak them (your test covers this).
  • It's an opt-in user override, which fits the security model the same way allow … / set default allow already do.
  • Merges cleanly onto current main and the full suite passes.

Merging. The -c analysis and secrets work (#134/#135) I'll follow up on separately.

@ldayton
ldayton merged commit 5cf99e2 into ldayton:main Jun 8, 2026
1 check passed
ldayton added a commit that referenced this pull request Jun 8, 2026
python -c was always ask. Now the inline body is run through the same AST
safety analyzer used for script files: expansion-free code that passes
analysis is auto-approved, dangerous imports/builtins ask, and any bash
expansion ($VAR, $(...)) in the -c argument falls back to ask because bash
rewrites the code at runtime.

Based on @nickdavies's #134 (rebased onto main after its base #122 landed),
plus a fix for a token-alignment bug: the per-token expansion flags were
indexed against the full word list while the handler sees env-stripped
tokens, so a leading FOO=bar shifted the flags and wrapper recursion dropped
them. The flags are now re-sliced in lockstep with tokens at both points.

Closes #134.

Co-authored-by: Nick Davies <github@nicolasdavies.com.au>
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.

2 participants