A PDM project with no usable .pdm-python is read from the Python on PATH: OS packages are patched and attested as the project's, while PDM's own venv stays unpatched
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 56/100
Piste de recherche
Start in core crawlers/python_crawler.rs, especially pdm_project_site_packages, managed_or_local_site_packages, and local_sites_with; compare PDM environment resolution with the behavior described for PDM 2.29.2. Add the fresh checkout regression test beside poetry_fresh_checkout_has_no_env_and_no_global_fallback, and cover the hashed out of tree venv case. Update the two contract paragraphs in CLI_CONTRACT.md; done means PDM projects no longer scan the shared PATH interpreter and the tests cover their resolved environments.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
[agent] Found by the architecture refactor routine, which ran agent mode against real PDM 2.29.2 and compared the copy pdm run imports with the copy the scan patched. This settles lead L50 of the register.
The problem
For a PDM project the Python crawler finds the environment through .pdm-python (or PDM_PYTHON). When that file is absent, ignored or stale, it tries $VIRTUAL_ENV, ./.venv, ./venv and __pypackages__, finds nothing, and then reads the Python on PATH as "a project with no environment of its own".
PDM never installs a project into that interpreter. With no saved interpreter it takes an activated venv, then ./.venv, ./venv or ./env, then the project's venvs under venv.location (<data dir>/pdm/venvs/<directory name>-<hash of the path>-*), and creates a venv when none exists (Project.resolve_interpreter and iter_venvs in PDM 2.29.2). With python.use_venv off it uses __pypackages__.
Two states reach the fallback:
- PDM keeps the venv outside the project (
venv.in_project = false) and.pdm-pythondoes not name it. The scan patches the copy in the Python onPATH, reports the project as patched,apply --checksays in sync andvexattestsnot_affected.pdm runstill imports the unpatched copy from PDM's venv. - A checkout before its first
pdm install. The scan reads every package of the Python onPATH, unscoped because ofpdm.lock, and patches each one that has a patch, whether or not the project declares it.
In both, socket-patch writes to an interpreter the project never uses. In a container or a CI job that runs as root, that is the OS Python.
Evidence on main (cfc870f)
All runs use the binary built from main, PDM 2.29.2, a stand-in patch API with one patch for pkg:pypi/[email protected], and a PATH whose python3 is the OS Python 3.11 (it holds python3-six 1.16.0). The project is a pyproject.toml with dependencies = ["six==1.16.0"] and a [tool.pdm] table.
State 1: the venv is outside the project and .pdm-python is ignored
$ cat pdm.toml
[venv]
in_project = false
$ pdm install
Virtualenv is created successfully at <home>/.local/share/pdm/venvs/p2-5hYsFcQL-3.11
$ export PDM_IGNORE_SAVED_PYTHON=1
$ pdm run python -c 'import six; print(hasattr(six, "SOCKET_PATCHED"), six.__version__, six.__file__)'
False 1.16.0 <home>/.local/share/pdm/venvs/p2-5hYsFcQL-3.11/lib/python3.11/site-packages/six.py
$ socket-patch scan --mode agent
Found 25 packages (25 python)
Applied 1 patch.
HIGH [email protected] CVE-2026-0001
Patched 1 package, fixing 1 vulnerability (1 high). (exit 0)
$ pdm run python -c 'import six; print(hasattr(six, "SOCKET_PATCHED"), six.__version__, six.__file__)'
False 1.16.0 <home>/.local/share/pdm/venvs/p2-5hYsFcQL-3.11/lib/python3.11/site-packages/six.py
$ 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/app@1 -O - | jq -c '.statements[] | {status, impact_statement}'
{"status":"not_affected","impact_statement":"Patched via Socket patch eeeeeeee-0000-4000-8000-000000000001"}
socket-patch apply over a committed .socket/ gives the same result after a fresh pdm install: 1 of 1 targeted patch applied, exit 0, the OS copy patched and PDM's copy not.
Three ways into this state, each run:
.pdm-python |
How it gets there | Lasts |
|---|---|---|
| ignored | PDM_IGNORE_SAVED_PYTHON=1 in the environment (socket-patch honors the variable too) |
as long as the variable is set |
| absent | git clean -fdx, or a fresh checkout at a path whose venv still exists (the file is in PDM's default .gitignore) |
until the next PDM command saves it again |
| stale | it names a venv that was deleted | until the next PDM command |
In the last two, once PDM saves the file again apply --check exits 1 and rollback keeps the record with a warning that names rollback pkg:pypi/[email protected] -g. That part is right. The OS copy stays patched until the user runs it.
With .pdm-python present and honored, the same project is patched in PDM's venv. So are an in-project .venv with no .pdm-python, a PEP 582 project, a base interpreter chosen with pdm use, and an activated venv with and without PDM_IGNORE_ACTIVE_VENV.
State 2: nothing installed yet
The catalog here also holds a patch for [email protected], an OS package the project does not declare.
$ ls -a
. .. .git pdm.lock pyproject.toml
$ grep dependencies pyproject.toml
dependencies = ["six==1.16.0"]
$ socket-patch scan --mode agent --dry-run
Found 25 packages (25 python)
[dry-run] Would download and apply 2 patches. No changes made.
CRITICAL [email protected] CVE-2026-0002
HIGH [email protected] CVE-2026-0001
Would patch 2 packages, fixing 2 vulnerabilities (1 critical, 1 high). (exit 0)
$ socket-patch scan --mode vendored --dry-run
Found 25 packages (25 python)
[dry-run] Would download and vendor 1 of 2 patches (1 would be refused). No changes made.
[would-refuse] pkg:pypi/[email protected] (pypi_pdm_lock_package_missing): pdm.lock has no [[package]] entry for httplib2; run `pdm lock` first
$ pdm install
Virtualenv is created successfully at <w>/p9/.venv
$ pdm run python -c 'import six; print(six.__file__)'
<w>/p9/.venv/lib/python3.11/site-packages/six.py
The transcripts keep the lines that matter; the "Next steps" and time-saved lines are left out.
The same checkout as a uv project (uv.lock in place of pdm.lock):
$ socket-patch scan --mode agent --dry-run
Found 1 package (1 python)
Note: 1 package from project lockfiles is not yet installed (lockfile-only).
[skip] pkg:pypi/[email protected] (not installed; run your package manager's install first, or `socket-patch scan --mode vendored` to vendor it from the lockfile)
A unit test that fails on main
In the tests of core crawlers/python_crawler.rs, beside poetry_fresh_checkout_has_no_env_and_no_global_fallback:
#[tokio::test]
async fn pdm_fresh_checkout_has_no_env_and_no_global_fallback() {
let tmp = tempfile::tempdir().unwrap();
let project = tmp.path().join("app");
std::fs::create_dir_all(&project).unwrap();
std::fs::write(
project.join("pyproject.toml"),
"[project]\nname = \"app\"\nversion = \"0.1.0\"\ndependencies = [\"six==1.16.0\"]\n\n[tool.pdm]\ndistribution = false\n",
)
.unwrap();
std::fs::write(project.join("pdm.lock"), "[metadata]\n").unwrap();
let home = tmp.path().join("home").to_string_lossy().into_owned();
let var = env_of(&[("HOME", home)]);
assert!(pdm_drives_project(&project).await);
let (sites, shared) = local_sites_with(&project, &var).await;
assert!(
sites.is_empty() && !shared,
"a PDM project read a shared interpreter: {sites:?}"
);
}
$ cargo test -p socket-patch-core --lib -- pdm_fresh_checkout_has_no_env poetry_fresh_checkout_has_no_env
test crawlers::python_crawler::tests::poetry_fresh_checkout_has_no_env_and_no_global_fallback ... ok
test crawlers::python_crawler::tests::pdm_fresh_checkout_has_no_env_and_no_global_fallback ... FAILED
a PDM project read a shared interpreter: ["/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. 1 passed; 1 failed
The out-of-tree venv needs PDM's path hash (the first eight characters of the URL-safe base64 of the MD5 of the project path), so its test belongs with the fix.
The cause
Core crawlers/python_crawler.rs:
pdm_project_site_packages(lines 881 to 914) returnsNonewhen no saved interpreter is usable, and leaves the rest to the generic probes.managed_or_local_site_packages(lines 749 to 803) then tries$VIRTUAL_ENV,./.venv,./venvand__pypackages__. It never looks under PDM'svenv.location, and not at./env.local_sites_with(lines 3613 to 3650) returns nothing for a project that only Pipenv, uv, Poetry or pixi installs. It has no such line for PDM, so a PDM project falls through toproject_interpreter_sites.
The same class has been fixed one manager at a time: PDM's saved interpreter (#502, b0a32db3), Pipenv (#504, #947), a lone uv project (#964, 00df0c42), Poetry (#1023, 83969ec3), pixi. #2308 is the uv workspace member. PDM without a usable .pdm-python is the branch left. #2293 (a saved venv with python.use_venv off) is open against the same function, pdm_project_site_packages; one change can take both.
CLI_CONTRACT.md (line 1432 and the paragraph from line 1438) lists the environments read and says a project with none of them "installs into the interpreter on PATH". For a PDM project that is not so, as the runs above show.
Planned fix
- Resolve a PDM project's environment the way PDM does when no saved interpreter is usable: the activated venv (unless
PDM_IGNORE_ACTIVE_VENV), then./.venv,./venv,./env, then the venvs undervenv.locationwhose name starts with PDM's prefix for the project, then__pypackages__. - A project PDM drives (
pdm_drives_project) never reads the Python onPATH. With no environment yet it has no installed packages, and its lock-only packages come frompdm.lock, as for uv, Poetry and Pipenv. - Update the two contract paragraphs.
The second point changes what the contract documents for a pdm.lock project with no environment. Four of the five managers already behave that way. A maintainer who wants PDM to keep the PATH fallback should say so here; the first point stands either way.
Generated by Claude Code
- Langage dominant
- Rust
- Étoiles
- 9
- Forks
- 2
- Merge moyen
- 1 j 8 h
- PR mergées (30 j)
- 313
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Aucun modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de SocketDev/socket-patch
-
agent:triaged arch-audit bug priority:p2
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
SocketDev/socket-patch#2306 ·
Les mainteneurs répondent en général sous 1 jour
-
agent:triaged arch-audit bug priority:p3
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
SocketDev/socket-patch#2296 ·
Les mainteneurs répondent en général sous 1 jour
-
agent:needs-human agent:triaged ci-janitor priority:p1
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
SocketDev/socket-patch#2270 · 3 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
agent:triaged arch-audit bug priority:p1
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
SocketDev/socket-patch#2259 ·
Les mainteneurs répondent en général sous 1 jour
-
agent:triaged arch-audit priority:p3 refactor
Difficulté 2/5 1-3 heures Accessibilité débutants 83/100
SocketDev/socket-patch#1860 ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de SocketDev/socket-patch
Issues similaires
-
Bash init calls `cygpath` unconditionally on Windows, which breaks non-Cygwin shells like `brush`Peut-être pris @iliqiliev l’a pris aujourd’hui. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
ajeetdsouza/zoxide#1381 ·
Les mainteneurs répondent en général sous 5 jours
-
triage
Difficulté 1/5 1-3 heures Accessibilité débutants 88/100
kornia/kornia-rs#1416 · 1 commentaire ·
Les mainteneurs répondent en général sous 2 jours
-
enhancement
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
Les mainteneurs répondent en général sous 2 jours
-
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
paritytech/revive#749 ·
Les mainteneurs répondent en général sous 3 jours
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
swc-project/swc-next-issues#1043 ·