From a uv workspace member, an agent-mode scan patches the Python on PATH instead of the workspace .venv: an OS package is modified, the project is reported as patched and vex attests it
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 48/100
Hướng nghiên cứu
Start with core/crawlers/python_crawler.rs, especially local_sites_with, uv_owns_project_env, and the adjacent uv_project_environment_is_the_project_env test; read utils/uv_workspace.rs for the existing workspace-root lookup. Run the proposed a_uv_workspace_member_never_reads_the_interpreter_on_path test and inspect how workspace environment paths are resolved. Done means agent-mode scans from a member use the workspace environment and never fall back to the Python on PATH.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
[agent] Found by the architecture refactor routine (ledger discussion #2244, lead L48), on main at cfc870f.
Problem
In a uv workspace, uv.lock and the environment (.venv) live at the workspace root, and uv sync or uv run from a member directory use that environment. A member directory holds only its own pyproject.toml.
An agent-mode run from a member directory (cd packages/lib && socket-patch scan, or --cwd packages/lib) does not know the member belongs to a workspace. It sees a pyproject.toml with no uv.lock and no .venv beside it, takes the directory for a project with no environment of its own, and reads the Python on PATH instead. When that interpreter holds a package the member declares (any version of it), the run patches that copy:
- The wrong copy is patched. The file written belongs to the OS Python (
/usr/lib/python3/dist-packages/six.py, owned by the distribution'spython3-sixpackage), not to the project. Every other program on the machine that imports it now runs the patched bytes, anddpkg --verifyreports the file as modified. - The project stays unpatched and is reported as patched. The scan says
Applied 1 patchandPatched 1 package, exit 0.apply --checksaysPatches are in sync.uv runfrom the same directory still imports the unpatched file from the workspace's.venv. - The VEX statement is false.
vexwritesnot_affectedfor the member's product. When the workspace locks another version than the OS has, the statement is for a version the workspace does not install at all. - With nothing matching in the OS Python, the advice is wrong. The scan says
No packages found: the 25 packages installed in the Python on PATH are not ones this project declares. Install its requirements first, thoughuv synchas installed them.
A relative UV_PROJECT_ENVIRONMENT has the same cause: uv resolves it against the workspace root, socket-patch against the member directory, finds nothing there and reads the Python on PATH.
The rule that is broken is stated in the code and has been fixed three times, one package manager at a time: "A uv project or script lock installs only into uv's own env. With none synced yet nothing is installed for it […]; the OS Python is never its env (#964)" (core crawlers/python_crawler.rs, lines 3628 to 3630). The test for a uv project is a uv.lock in the directory itself (uv_owns_project_env, line 1125), which a workspace member never has.
Vendored and hosted mode already know the layout. utils/uv_workspace.rs walks up to the [tool.uv.workspace] root, and both modes refuse a member with its name (#1138, fixed in 2a11629f). The contract lists it under "Reads bounded to the repository root": "a uv workspace pyproject.toml above (redirect_workspace_lockfile_elsewhere, pypi_uv_workspace_unsupported)". pixi workspace members have a rule of their own in the crawler ("From a workspace member directory […] the environment pixi run / pixi shell activated for that workspace is used instead"). The agent-mode crawler has neither for uv.
Who it hurts
- A uv monorepo that runs socket-patch per package directory, the way the contract describes for Python monorepos ("invoking the tool once per subproject (
--cwdeach), as a per-directory CI step would"), on a machine whose system Python has any of the member's dependencies. The Ubuntu image these runs used hassix,PyYAML,cryptography,PyJWT,pillow,packaging,pyparsing,httplib2,oauthlibandsetuptoolsin/usr/lib/python3/dist-packages. The versions need not match the workspace's: the scan looks up patches for the version the OS has. - CI and container builds most of all: they run as root, so the write to the OS package succeeds, and nobody has activated the workspace's
.venv(withVIRTUAL_ENVset to it the run is correct). - Whoever reads the VEX document, and whatever else on the machine imports the OS package.
Evidence on main
The binary is built from cfc870f. uv is 0.11.32. The machine's python3-six is 1.16.0-4. The patch API is a local stand-in that serves one patch for pkg:pypi/[email protected]; the patched six.py defines SOCKET_PATCHED.
$ cat pyproject.toml # the workspace root, which also holds uv.lock and .venv
[project]
name = "app"
version = "0.1.0"
requires-python = ">=3.11"
dependencies = ["lib"]
[tool.uv.sources]
lib = { workspace = true }
[tool.uv.workspace]
members = ["packages/*"]
$ cat packages/lib/pyproject.toml
[project]
name = "lib"
version = "0.1.0"
requires-python = ">=3.11"
dependencies = ["six==1.16.0"]
$ uv sync
+ lib==0.1.0 (from file://<w>/w1/packages/lib)
+ six==1.16.0
$ cd packages/lib
$ uv run python -c 'import six; print(hasattr(six, "SOCKET_PATCHED"), six.__version__, six.__file__)'
False 1.16.0 <w>/w1/.venv/lib/python3.11/site-packages/six.py
$ dpkg --verify python3-six # clean
$ socket-patch scan --mode agent
Found 1 package (1 python)
Warning: PyPI: run `pip check` (or `uv pip check`) to verify .dist-info/RECORD consistency. …
Applied 1 patch.
HIGH [email protected] CVE-2026-0001
Next steps:
1. Commit .socket/ to keep the patches.
2. Run `socket-patch apply` after every `pip install`, locally and in CI. A fresh install removes the patches.
Patched 1 package, fixing 1 vulnerability (1 high).
… (exit 0)
$ uv run python -c 'import six; print(hasattr(six, "SOCKET_PATCHED"), six.__version__, six.__file__)'
False 1.16.0 <w>/w1/.venv/lib/python3.11/site-packages/six.py
$ grep -c SOCKET_PATCHED <w>/w1/.venv/lib/python3.11/site-packages/six.py /usr/lib/python3/dist-packages/six.py
<w>/w1/.venv/lib/python3.11/site-packages/six.py:0
/usr/lib/python3/dist-packages/six.py:1
$ dpkg --verify python3-six
??5?????? /usr/lib/python3/dist-packages/six.py
$ socket-patch apply --check
Patches are in sync (1 patch checked). (exit 0)
$ socket-patch vex --product pkg:generic/[email protected] -O - | jq -c '.statements[] | {status, impact_statement}'
{"status":"not_affected","impact_statement":"Patched via Socket patch dddddddd-0000-4000-8000-000000000001"}
$ socket-patch scan --mode agent --json | jq -c '[.events[] | .action], [.warnings[].code]' # on a fresh copy
["downloaded","applied"] []
socket-patch rollback from the member restores the OS file.
The same workspace locking six==1.17.0, which has no patch here. The OS still has 1.16.0:
$ uv run python -c 'import six; print(six.__version__, six.__file__)'
1.17.0 <w>/w2/.venv/lib/python3.11/site-packages/six.py
$ socket-patch scan --mode agent
Found 1 package (1 python)
Applied 1 patch.
HIGH [email protected] CVE-2026-0001
Patched 1 package, fixing 1 vulnerability (1 high). (exit 0)
$ dpkg --verify python3-six
??5?????? /usr/lib/python3/dist-packages/six.py
$ socket-patch vex --product pkg:generic/[email protected] -O - | jq -c '.statements[] | {status, products: [.products[] | .subcomponents[]? | ."@id"]}'
{"status":"not_affected","products":["pkg:pypi/[email protected]"]}
A member whose dependency (iniconfig==2.0.0) the OS Python does not have:
$ uv run python -c 'import iniconfig; print(iniconfig.__file__)'
<w>/w3/.venv/lib/python3.11/site-packages/iniconfig/__init__.py
$ socket-patch scan --mode agent
No packages found: the 25 packages installed in the Python on PATH are not ones this project declares. Install its requirements first; `--global` scans them with every other package on the machine. (exit 0)
A relative UV_PROJECT_ENVIRONMENT=.venv-ci, synced from the member (uv puts it at <w>/w4/.venv-ci):
$ UV_PROJECT_ENVIRONMENT=.venv-ci socket-patch scan --mode agent --dry-run # in packages/lib
Found 1 package (1 python) # the OS copy
$ UV_PROJECT_ENVIRONMENT=.venv-ci socket-patch scan --mode agent --dry-run # in the workspace root
Found 2 packages (2 python) # six and lib, in .venv-ci
Controls, all correct:
| Run | Result |
|---|---|
scan --mode agent from the workspace root |
patches <w>/w1/.venv; uv run from the member imports the patched file; the OS file is untouched |
the member, with VIRTUAL_ENV=<w>/w1/.venv |
the same |
scan --mode vendored from the member |
exit 1: ". is a member of the uv workspace rooted at <w>/w1, which installs it from <w>/w1/uv.lock […] nothing was written" |
a lone uv project (uv.lock beside pyproject.toml, no .venv) |
[email protected] is listed from the lock as not installed and skipped; nothing is read from the OS Python (#964) |
A unit test beside uv_project_environment_is_the_project_env (core crawlers/python_crawler.rs) fails on main:
#[tokio::test]
async fn a_uv_workspace_member_never_reads_the_interpreter_on_path() {
let tmp = tempfile::tempdir().unwrap();
let root = tmp.path().join("ws");
let member = root.join("packages").join("lib");
std::fs::create_dir_all(&member).unwrap();
std::fs::write(
root.join("pyproject.toml"),
"[project]\nname = \"app\"\nversion = \"0.1.0\"\ndependencies = [\"lib\"]\n\n\
[tool.uv.sources]\nlib = { workspace = true }\n\n\
[tool.uv.workspace]\nmembers = [\"packages/*\"]\n",
)
.unwrap();
std::fs::write(root.join("uv.lock"), "version = 1\n").unwrap();
std::fs::write(
member.join("pyproject.toml"),
"[project]\nname = \"lib\"\nversion = \"0.1.0\"\ndependencies = [\"six==1.16.0\"]\n",
)
.unwrap();
let workspace_site = fake_venv(&root, ".venv");
// Control: from the workspace root, the env is the workspace's.
let (root_sites, root_shared) = local_sites_with(&root, &env_of(&[])).await;
assert_eq!(root_sites, vec[workspace_site]);
assert!(!root_shared);
let (sites, shared) = local_sites_with(&member, &env_of(&[])).await;
assert!(
!shared,
"a uv workspace member was given the interpreter on PATH: {sites:?}"
);
}
$ cargo test -p socket-patch-core --lib a_uv_workspace_member_never_reads
a uv workspace member was given the interpreter on PATH: ["/usr/local/lib/python3.11/dist-packages", "/usr/lib/python3/dist-packages", "/usr/lib/python3.11/dist-packages", "/root/.local/lib/python3.11/site-packages"]
test result: FAILED. 0 passed; 1 failed
Cause
local_sites_with (core crawlers/python_crawler.rs, lines 3613 to 3650) tries the project's own environments, then asks whether a package manager owns the project (is_pipenv_project, uv_owns_project_env, poetry_owns_project_env, pixi_owns_project_env), and otherwise hands a directory with a Python marker the interpreter on PATH (project_interpreter_sites, line 3647). Each ownership test reads only --cwd:
uv_owns_project_env(line 1121) wants<cwd>/uv.lock;uv_project_environment_site_packages(line 1081) joins a relativeUV_PROJECT_ENVIRONMENTonto--cwd(line 1091);- the
.venvprobe (line 789) looks in--cwd.
A workspace member fails all three and falls through.
The class has a history of one-sided fixes. "A project its package manager installs elsewhere falls back to the system Python" was fixed for Pipenv (#504, #947; 54bc27f0), for a lone uv project (#964; 00df0c42) and for Poetry (#1023; 83969ec3). "A uv workspace member is read as a project of its own" was fixed for vendored and hosted mode (#1138; 2a11629f), which added the walk in utils/uv_workspace.rs. pixi members got their rule with pixi support (e123f6b2). The agent-mode crawler is the copy none of them reached.
Planned fix
The part that is not in doubt: a directory that utils/uv_workspace.rs finds governed by a uv workspace is a uv project, so the interpreter on PATH is never its environment.
What it reads instead is the workspace's environment, as uv does and as pixi members already get: UV_PROJECT_ENVIRONMENT resolved against the workspace root, else <root>/.venv. With neither present nothing is installed for it, as for a fresh uv clone. When the walk leaves the repository with a pyproject.toml above it (the contract's "readers withhold" case), it reads nothing. The human hint then names the workspace root instead of telling the user to install.
One point a maintainer may want to weigh in on: reading the workspace's environment means a run from one member patches the .venv every member shares, and records the patch in the member's own .socket/. If a run from a member should refuse instead (the vendored-mode answer), say so here; the first paragraph of the fix holds either way.
No change to JSON shapes, flags or exit codes. CLI_CONTRACT.md's "cwd-only" paragraph gains the uv member sentence beside the pixi one.
Also seen, not part of this issue
- An agent-mode scan from an npm workspace member (
node_moduleshoisted to the root) saysNo packages found. Run your package manager's install first.Nothing is written and nothing is reported as patched. - With
COMPOSER=composer-alt.json(Composer's variable for another manifest name), the scan readscomposer.json, finds none and says the same line.
Generated by Claude Code
- Ngôn ngữ chính
- Rust
- Star
- 9
- Fork
- 2
- Merge trung bình
- 1 ngày 8 giờ
- Pull request đã merge (30 ngày)
- 313
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của SocketDev/socket-patch
-
agent:triaged arch-audit bug priority:p2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
SocketDev/socket-patch#2306 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
agent:triaged arch-audit bug priority:p3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
SocketDev/socket-patch#2296 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
agent:needs-human agent:triaged ci-janitor priority:p1
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
SocketDev/socket-patch#2270 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
agent:triaged arch-audit bug priority:p1
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
SocketDev/socket-patch#2259 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
agent:triaged arch-audit priority:p3 refactor
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
SocketDev/socket-patch#1860 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của SocketDev/socket-patch
Issue tương tự
-
Bash init calls `cygpath` unconditionally on Windows, which breaks non-Cygwin shells like `brush`Có thể đã có người làm @iliqiliev đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
ajeetdsouza/zoxide#1381 ·
Maintainer thường phản hồi trong vòng 5 ngày
-
triage
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
kornia/kornia-rs#1416 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
paritytech/revive#749 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
swc-project/swc-next-issues#1043 ·