Skip to content

Distrust repository-local Python interpreters (avoid executing .venv/bin/python) - #142

Closed
tachyon-beep wants to merge 1 commit into
mainfrom
codex/propose-fix-for-.venv-interpreter-vulnerability
Closed

Distrust repository-local Python interpreters (avoid executing .venv/bin/python)#142
tachyon-beep wants to merge 1 commit into
mainfrom
codex/propose-fix-for-.venv-interpreter-vulnerability

Conversation

@tachyon-beep

Copy link
Copy Markdown
Collaborator

Motivation

  • Prevent execution of repository-controlled interpreter files (e.g. <project_root>/.venv/bin/python) which Pyright may invoke, creating an arbitrary code-execution vector.
  • Ensure interpreter discovery only selects explicitly trusted/activated interpreters or operator overrides rather than untrusted files from analyzed repositories.

Description

  • Remove project-local .venv/bin/python discovery from both the Python plugin and the Rust host so repository-local interpreters are no longer selected; the discovery API keeps project_root in the signature but does not inspect the repository for executables. (plugins/python/src/loomweave_plugin_python/interpreter.py, crates/loomweave-core/src/plugin/interpreter.rs).
  • Drop the dotvenv interpreter source and adjust the pinned-classification to treat only explicit overrides and activated environments (VIRTUAL_ENV/CONDA_PREFIX) as pinned. (plugins/python/src/loomweave_plugin_python/interpreter.py, crates/loomweave-core/src/plugin/interpreter.rs).
  • Change host export policy so the PluginHost does not hand repository-local interpreter paths to language-server plugins and treat empty override values as not permitting a repository interpreter. (crates/loomweave-core/src/plugin/host.rs).
  • Add and adjust regression tests to verify repository .venv executables and symlinks are ignored, update Pyright-session tests to exercise explicit overrides, and update server tests to assert no repository interpreter is advertised. (tests under plugins/python/tests/* and changes to crates/loomweave-core tests).

Testing

  • python -m pytest -o addopts='' plugins/python/tests/test_interpreter.py -q — passed (test subset exercised and 13 tests passed).
  • cargo test -p loomweave-core plugin::interpreter --lib — passed (8 tests passed).
  • cargo test -p loomweave-core only_language_server_plugins_are_pointed_at_the_project_interpreter --lib — passed (host-side regression passed).
  • Repo-level checks: ruff/python -m compileall, cargo fmt --all -- --check, and git diff --check were run and passed, and the code was committed as fix(python): distrust repository-local interpreters.
  • Environment notes: a full Python test invocation including test_server.py/test_pyright_session.py could not be collected in this environment due to missing yaml in the test environment and the plugin venv lacking pytest, which are external-environment limitations and not regressions in the changes.

Codex Task

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 31, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-08-31T16:22:11.607136Z 9f40b5d PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9f40b5d69a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 190 to 192
pub fn discover_project_interpreter(
project_root: &Path,
_project_root: &Path,
env: &dyn Fn(&str) -> Option<OsString>,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Update the CLI test for removed dotvenv discovery

When no override or activated environment is present, ignoring project_root makes discovery return the unpinned PATH/none result, but analyze_interpreter_change_forces_full_reanalysis in crates/loomweave-cli/tests/analyze.rs still supplies only <project>/.venv/bin/python and asserts that this path is fingerprinted and exported. The verify.yml workspace-wide nextest job runs this test, so the suite will fail on Unix; update the integration scenario to transition between trusted interpreter sources while preserving its re-dispatch coverage.

Useful? React with 👍 / 👎.

Comment on lines +83 to +85
# Keep the project root in the API because this function is mirrored by
# the host, but never use it to select an executable from the repository.
_ = project_root

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Remove the obsolete create-.venv remediation

After this function deliberately stops inspecting the project root, merely creating <project>/.venv cannot resolve interpreter_unpinned; nevertheless, loomweave doctor still tells affected users to “set LOOMWEAVE_PYTHON_INTERPRETER or create .venv,” and the Python README and ADR document the same obsolete rung. Users following that advice remain degraded, so the user-facing remediation and discovery documentation should instead require an explicit override or activated environment.

Useful? React with 👍 / 👎.

@tachyon-beep

Copy link
Copy Markdown
Collaborator Author

Closing without merge — the concern is real but the fix is too broad.

Why not merge:

  • It removes ADR-058 rung 2 (<project_root>/.venv/bin/python) outright, reversing an accepted decision without an ADR amendment. Rung 2 is the launcher-independent fix for the elspeth resolution bug (see the ADR's bisect table); dropping it reintroduces the "VIRTUAL_ENV set, venv not on PATH" empty-resolution case for every hook-spawned analyze.
  • In the normal operator model .venv is operator-created and gitignored, not repository content; the only untrusted case is a repo that commits an executable at that path.
  • It deletes the load-bearing the_root_canonicalisation_at_both_call_sites_is_load_bearing test and is CI-red on both Verify legs.

What happens instead: the narrow mitigation — skip rung 2 only when .venv/bin/python is git-tracked (both sides of the cross-language contract, ADR-058 amended, once-per-run attribution log) — is tracked as Filigree clarion-9b3cf287b7.

@tachyon-beep
tachyon-beep deleted the codex/propose-fix-for-.venv-interpreter-vulnerability branch September 1, 2026 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant