Skip to content

fix: runtime Python import blocking via __import__ hook#30

Merged
b-macker merged 1 commit into
masterfrom
audit/python-import-blocking
Jun 14, 2026
Merged

fix: runtime Python import blocking via __import__ hook#30
b-macker merged 1 commit into
masterfrom
audit/python-import-blocking

Conversation

@b-macker

Copy link
Copy Markdown
Owner

Summary

  • Override builtins.__import__ in PythonCExecutor to enforce govern.json blocked imports at runtime
  • Catches dynamic imports (__import__("o"+"s"), importlib.import_module()) that bypass static source scanning
  • Closes F-3 from Round 6 slop audit (the last remaining finding)
  • Removed stale TODO comment in main.cpp

Changes

  • src/runtime/python_c_executor.cpp — inject __import__ hook before user code execution, reading blocked list from GovernanceEngine::getCurrent()->getLanguageConfig("python")->imports.blocked
  • src/cli/main.cpp — replaced TODO with documentation comment pointing to new implementation

Test plan

  • cd build && cmake .. && make naab-lang -j4 — compiles clean
  • bash run-all-tests.sh — 396/396, 0 unexpected failures
  • Manual test: dynamic __import__("sub"+"process") blocked when subprocess in blocked list
  • CI passes

🤖 Generated with Claude Code

Override builtins.__import__ in PythonCExecutor to check govern.json
blocked imports list, catching dynamic imports (__import__("o"+"s"),
importlib) that bypass static source scanning. Closes F-3 from R6 audit.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

NAAb Governance Report

Metric Count
Files checked 16
Passed 16
Failed 0

All governance checks passed!

Generated by NAAb Governance Engine v4.0

@b-macker b-macker merged commit b385efb into master Jun 14, 2026
20 checks passed
@b-macker b-macker deleted the audit/python-import-blocking branch June 14, 2026 10:23
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