Skip to content

fix(python): shallow-copy OSAccess environ to prevent host dict aliasing#1

Draft
tusharhqq wants to merge 1 commit into
mainfrom
cursor/hackmonty-osaccess-environ-copy-9762
Draft

fix(python): shallow-copy OSAccess environ to prevent host dict aliasing#1
tusharhqq wants to merge 1 commit into
mainfrom
cursor/hackmonty-osaccess-environ-copy-9762

Conversation

@tusharhqq

Copy link
Copy Markdown
Owner

Summary

OSAccess previously stored the environ mapping by reference (environ or {}), which made it easy for host code to accidentally pass os.environ or another shared dict and have post-construction mutations change what Monty observes. That matches the failure mode described in the Hack Monty bounty updates (wrapper misuse around OSAccess(environ=...) rather than a VM escape).

Changes

  • Store dict(environ) when environ is not None, otherwise {}.
  • Document the shallow-copy behavior in the class and __init__ docstrings.
  • Add regression tests: shared dict mutation after init, and OSAccess(environ=os.environ) must not keep a live alias to the process environment.
  • Extend challenge/HACKMONTY_BOUNDARY_THREAT_MAP.md with a host-side OSAccess / environ wiring section.

Testing

Python tests were not executed in this agent environment (workspace Cargo is 1.83.0; maturin develop requires edition 2024). Please run make test-py or the targeted pytest cases locally.

Open in Web Open in Cursor 

OSAccess now stores a shallow copy of the environ mapping at construction
so callers cannot accidentally pass os.environ or a shared dict and have
post-init mutations widen what Monty sees.

Adds regression tests and extends the Hackmonty threat map with host
OSAccess/environ wiring notes.

Co-authored-by: Tushar Dahiya <tushardzig@gmail.com>
@github-actions

github-actions Bot commented May 3, 2026

Copy link
Copy Markdown

Codecov Results 📊

✅ Patch coverage is 100.00%. Project has 23559 uncovered lines.


Generated by Codecov Action

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