Skip to content

fix: policy denies python -m — the cwd lands on sys.path - #40

Merged
VarunGore36 merged 1 commit into
mainfrom
fix/policy-python-module-exec
Nov 8, 2026
Merged

VarunGore36 merged 1 commit into
mainfrom
fix/policy-python-module-exec

Conversation

@VarunGore36

Copy link
Copy Markdown
Owner

Summary

Part 6 of 18 in the exec-denylist fix series.

python -m <module> executes a module by name with the current directory at sys.path[0] — and the child's cwd is the guest-writable workspace. python3 -m evil imports and runs /workspace/evil.py: guest-written code under the trusted python3 name, invisible to the shell/interpreter gates.

  • Denied for python/python3 (version-tolerant) wherever python appears, including bundled short-flag clusters (-Bm)
  • Trade-off, documented in-code: legitimate module runs (python3 -m http.server) pay the same price — the module name is argv-visible but trusted-vs-guest resolution (site-packages vs cwd) is not something the v0 denylist can scope. Script-file form (python3 script.py) stays allowed; operators who need -m have exec.allowlist.
  • grep -m 5 … (an -m data flag without python) stays allowed

Test plan

  • python_module_exec_is_denied: 8 assertions (path tolerance, version tolerance, rest-reach, cluster form, allow side, false-positive guard)
  • cargo test -p toolcage-policy: 39 passed
  • cargo test --workspace: 51 suites, 0 failed
  • fmt + clippy -D warnings: clean

python -m executes a module by name with the CURRENT DIRECTORY at
sys.path[0]: 'python3 -m evil' imports and runs /workspace/evil.py —
guest-written code under the trusted python3 name. Denied for
python/python3 (version-tolerant) wherever python appears, including
cluster forms (-Bm). Legitimate module runs (python3 -m http.server)
pay the same price — documented; script-file form (python3 script.py)
stays allowed, and operators who need -m have exec.allowlist.
@VarunGore36
VarunGore36 merged commit 984c92a into main Nov 8, 2026
5 checks passed
@VarunGore36
VarunGore36 deleted the fix/policy-python-module-exec branch November 8, 2026 23:52
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