fix: harden lib-agent.sh PYTHONPATH against shadow module bypass#195
Merged
fix: harden lib-agent.sh PYTHONPATH against shadow module bypass#195
Conversation
Replace PYTHONPATH="$RECURSIVE_DIR/lib:$REPO_DIR" with _NS_LIB env var and sys.path.insert(0, os.environ['_NS_LIB']) at all 6 call sites in lib-agent.sh (cleanup_old_logs, cleanup_healer_log, cleanup_orphan_branches, compact_handoffs, should_evaluate, run_evaluation). Matches the pattern applied to daemon.sh in PR #190.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PYTHONPATH="$RECURSIVE_DIR/lib:$REPO_DIR"calls in.recursive/engine/lib-agent.shwith the safer_NS_LIBenv-var +sys.path.insert(0, os.environ['_NS_LIB'])pattern$REPO_DIRfrom every path assignment in lib-agent.sh — a shadow module placed in the project root could previously hijack importsdaemon.shin PR fix: harden daemon python3 -c against module shadowing and interpolation #190cleanup_old_logs,cleanup_healer_log,cleanup_orphan_branches,compact_handoffs,should_evaluate,run_evaluationVerification
bash -n .recursive/engine/lib-agent.shpasses (syntax clean)make checkpasses — 882 tests, ruff, mypy, shell syntax, ASCII checks all greenPYTHONPATHassignments remain in lib-agent.shSafety invariants
No safety invariants modified. This change touches the import mechanism for library helpers only; circuit breaker, cost cap, selective git add, zone compliance, prompt guard, lock file, and reset-to-origin logic are all unchanged.
Test plan
bash -n .recursive/engine/lib-agent.sh- syntax check passesmake check- full CI passes (882 tests)PYTHONPATHassignments remain in lib-agent.sh_NS_LIBassignments and 6sys.path.insertcalls are present