Repository navigation
fix(sleep): don't import or run code from the project directory - #338
Merged
Merged
Conversation
When no source checkout was resolvable, the runners (sh/ps1/cmd): - searched upward from the CWD for a skillopt_sleep/ folder and ran it as the engine, and - in Fallback 2 probed with `python -c "import skillopt_sleep"` and ran `python -m skillopt_sleep`, both of which put the CWD first on sys.path. The CWD is the user's (possibly untrusted) project, so a planted skillopt_sleep/ or skillopt_sleep.py there executed on the next /sleep. Drop the CWD upward search (SKILLOPT_SLEEP_REPO covers that use case) and run Fallback 2 through a -c launcher that removes the CWD entry from sys.path before importing, keeping the CWD itself since the engine uses it as the default project. Adds regression tests for both plants. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
When no source checkout was resolvable, the sleep runners (
run-sleep.sh, its bundled copy,.ps1,.cmd) could execute code from the current directory, which is the user's (possibly untrusted) project:skillopt_sleep/folder and ran it as the engine.python -c "import skillopt_sleep"and ranpython -m skillopt_sleep; both put the CWD first onsys.path, so a top-levelskillopt_sleep.pywould be imported.Changes:
SKILLOPT_SLEEP_REPO(already documented in the plugin READMEs) covers that use case-clauncher that removes the CWD entry fromsys.pathbefore importing /runpy.run_module. The CWD itself is unchanged because the engine uses it as the default project.Test plan
TestRunnerIgnoresCwdPlants(plantedskillopt_sleep.pyandskillopt_sleep/in CWD): fail onmain, pass on this branchpytest tests/test_run_sleep_fallback.py tests/test_plugin_sync.py— 22 passed, 1 skipped--helpshowsusage: skillopt_sleep).ps1/.cmdnot runnable locally (no Windows) — relying on the Windows Pester CI🤖 Generated with Claude Code