Skip to content

fix(sleep): don't import or run code from the project directory - #338

Merged
Yifan Yang (Yif-Yang) merged 1 commit into
mainfrom
security/run-sleep-search-path
Oct 29, 2026
Merged

Yifan Yang (Yif-Yang) merged 1 commit into
mainfrom
security/run-sleep-search-path

Conversation

@Yif-Yang

Copy link
Copy Markdown
Contributor

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:

  1. They searched upward from the CWD for a skillopt_sleep/ folder and ran it as the engine.
  2. Fallback 2 probed with python -c "import skillopt_sleep" and ran python -m skillopt_sleep; both put the CWD first on sys.path, so a top-level skillopt_sleep.py would be imported.

Changes:

  • Remove the CWD upward search; SKILLOPT_SLEEP_REPO (already documented in the plugin READMEs) covers that use case
  • Fallback 2 uses a -c launcher that removes the CWD entry from sys.path before importing / runpy.run_module. The CWD itself is unchanged because the engine uses it as the default project.

Test plan

  • New TestRunnerIgnoresCwdPlants (planted skillopt_sleep.py and skillopt_sleep/ in CWD): fail on main, pass on this branch
  • pytest tests/test_run_sleep_fallback.py tests/test_plugin_sync.py — 22 passed, 1 skipped
  • Manual: Fallback 2 with the package installed still runs (--help shows usage: skillopt_sleep)
  • .ps1 / .cmd not runnable locally (no Windows) — relying on the Windows Pester CI

🤖 Generated with Claude Code

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>
@Yif-Yang
Yifan Yang (Yif-Yang) merged commit bc0a392 into main Oct 29, 2026
13 checks passed
@Yif-Yang
Yifan Yang (Yif-Yang) deleted the security/run-sleep-search-path branch October 29, 2026 08:40
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