PDM project with a venv interpreter and python.use_venv off: agent mode patches the unused venv and vex attests not_affected while __pypackages__ stays unpatched
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 4/5
- 預估耗時
- 1-2 天
- 新手友好度
- 72/100
研究方向
Start in crates/socket-patch-core/src/crawlers/python_crawler.rs, especially pdm_project_site_packages near line 899 and pdm_uses_venv near line 909; then read the PDM compatibility section in docs/testing/pdm-compatibility.md. Reproduce the supplied PDM 2.29.7 case with python.use_venv off and compare the scanned environment with pdm run imports. Done when the active __pypackages__ install is selected for patching and VEX checks it, with the compatibility docs corrected.
由索引模型根據 Issue 內容生成。
描述
[agent] Found by the scheduled PDM bug-hunt routine (ledger #312).
Summary
When PDM's saved interpreter (.pdm-python, or [python] path in .pdm.toml on PDM 1.x) is a venv interpreter but python.use_venv is off, PDM installs into PEP 582 __pypackages__/<X.Y>/lib and runs the project from there. socket-patch's crawler takes the saved venv as the project env without looking at use_venv. When that venv also holds a copy of the package (it was synced before the project switched to PEP 582, or the user pip-installed into it), agent mode patches that unused copy and reports success. vex then attests not_affected while the code the project actually imports is unpatched: a false VEX attestation.
PDM picks the env in Project.get_environment as PythonEnvironment if config["python.use_venv"] and self.python.get_venv() is not None else PythonLocalEnvironment (the same in 2.12.4 and 2.29.7). PDM 1.4.5 uses config["use_venv"] and is_venv_python(...), with use_venv defaulting to False. So on PDM 1.x a venv interpreter in .pdm.toml means __pypackages__ by default, and on PDM 2.x it does once pdm config -l python.use_venv false is set.
This differs from the closed #502 / #528 / #609. Those covered a base interpreter with use_venv off, and a saved venv with use_venv on. Here it's a saved venv with use_venv off. docs/testing/pdm-compatibility.md says "The first of them that is an environment wins: a venv … A base interpreter means PEP 582 only when python.use_venv is off". That ordering doesn't match PDM: use_venv off means PEP 582 even when the interpreter is a venv.
Impact
- Agent:
scan --mode agentprints "Patched 1 package" and the manifest records the patch, butpdm runimports the unpatched__pypackages__copy.vexattests the vulnerability asnot_affected. Users and CI gating onsocket-patch vexget a false attestation. - Hosted / vendored (fails closed, but stuck): after the scan,
pdm syncinstalls the patched wheel into__pypackages__. Thenvexchecks the stale.venvcopy, omits the patch asnot_appliedand exits with "No applied patches…", and the scan's stale-install warning points at the.venv. Following the remedy can never produce a VEX document.
Repro (PDM 2.29.7, Linux)
mkdir demo && cd demo
printf '[project]\nname = "demo"\nversion = "0.1.0"\nrequires-python = ">=3.9"\ndependencies = ["urllib3==1.26.18", "idna==3.7"]\n\n[tool.pdm]\ndistribution = false\n' > pyproject.toml
python3.11 -m venv .venv && echo "$PWD/.venv/bin/python" > .pdm-python # what `pdm use .venv` records
pdm lock && pdm sync # installs into .venv
pdm config -l python.use_venv false # switch the project to PEP 582
pdm sync # now installs into __pypackages__/3.11/lib
pdm run python -c 'import urllib3; print(urllib3.__file__)' # .../__pypackages__/3.11/lib/urllib3/__init__.py
socket-patch scan --mode agent --yes # "Patched 1 package"
grep -c SOCKET_PATCHED .venv/lib/python3.11/site-packages/urllib3/response.py # 1 (unused copy patched)
grep -c SOCKET_PATCHED __pypackages__/3.11/lib/urllib3/response.py # 0 (the copy PDM runs)
socket-patch vex # statement: not_affected <- false
(Patch data came from a local mock of the patch API serving a marker patch for [email protected]. The Socket hosts aren't reachable from the sandbox.)
PDM 1.4.5 needs no config: .pdm.toml [python] path = "<proj>/.venv/bin/python" with urllib3 in both .venv and __pypackages__ gives the same result (venv patched, __pypackages__ not, vex attests). With nothing installed in .venv, the agent scan patches nothing: "1 vulnerability left to patch".
Expected vs actual
- Expected (docs/testing/pdm-compatibility.md, "The installed env is the one PDM records … Agent mode patches the env found, and the hosted and vendored stale-install warnings and
vexcheck it"): the env PDM installs into, here__pypackages__/<X.Y>/lib, gets patched and is whatvexchecks. CLI_CONTRACT.md: VEX only attests patches whose files hold the patched content. - Actual: the unused
.venvcopy is patched and attested.
Versions
| PDM | config | socket-patch | agent result | vex |
|---|---|---|---|---|
| 2.29.7 | .pdm-python → .venv, pdm.toml use_venv = "false" |
main cfc870f (2 fresh runs) |
.venv patched, __pypackages__ not |
false not_affected |
| 2.29.2 | same | main | same | false |
| 2.12.4 | same | main | same | false |
| 2.29.7 | same | v5.1.0 release | same | false (not a regression) |
| 1.4.5 | .pdm.toml python.path → .venv (default use_venv false) |
main | same | false |
| 2.29.7, hosted | same | main | pdm sync patches __pypackages__ |
not_applied (fails closed, stale .venv checked) |
The crawler logic isn't OS-specific (Scripts\python.exe / Lib\site-packages on Windows), so I expect the same on macOS and Windows. Not run there.
Suspect code
crates/socket-patch-core/src/crawlers/python_crawler.rs:899 (pdm_project_site_packages): interpreters.iter().find_map(|i| env_root_of_interpreter(i)) returns the venv's site-packages before pdm_uses_venv (line 909) is consulted. pdm_uses_venv should gate the venv branch too, with its existing PDM 1.x default (off for a legacy .pdm.toml project). The doc paragraph in docs/testing/pdm-compatibility.md ("The first of them that is an environment wins") would need the same correction.
Generated by Claude Code
- 主要語言
- Rust
- 星號
- 9
- 分支
- 2
- 平均合併
- 1 天 8 小時
- 30 天內合併 PR
- 313
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
SocketDev/socket-patch 的其他 Issue
-
agent:triaged arch-audit bug priority:p2
難度 2/5 1-3 小時 新手友好度 84/100
SocketDev/socket-patch#2306 ·
維護者通常 1 天內回覆
-
agent:triaged arch-audit bug priority:p3
難度 2/5 1-3 小時 新手友好度 88/100
SocketDev/socket-patch#2296 ·
維護者通常 1 天內回覆
-
agent:needs-human agent:triaged ci-janitor priority:p1
難度 2/5 1-3 小時 新手友好度 72/100
SocketDev/socket-patch#2270 · 3 則留言 ·
維護者通常 1 天內回覆
-
agent:triaged arch-audit bug priority:p1
難度 2/5 1-3 小時 新手友好度 82/100
SocketDev/socket-patch#2259 ·
維護者通常 1 天內回覆
-
agent:triaged arch-audit priority:p3 refactor
難度 2/5 1-3 小時 新手友好度 83/100
SocketDev/socket-patch#1860 ·
維護者通常 1 天內回覆
查看 SocketDev/socket-patch 的全部 Issue
相似的 Issue
-
Find/Replace panel: "Previous/Next occurrence" labels overlap and overflow their buttons (French)未關閉
難度 2/5 1-3 小時 新手友好度 63/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 62/100
obi1kenobi/cargo-semver-checks#1839 · 3 則留言 ·
維護者通常 1 天內回覆
-
Bash init calls `cygpath` unconditionally on Windows, which breaks non-Cygwin shells like `brush`可能已有人在做 @iliqiliev 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 72/100
ajeetdsouza/zoxide#1381 ·
維護者通常 5 天內回覆
-
triage
難度 1/5 1-3 小時 新手友好度 88/100
kornia/kornia-rs#1416 · 1 則留言 ·
維護者通常 2 天內回覆