# PDM: A project pdm.toml can still set cache_dir, which brings back project-controlled plugin code at pdm startup

Project-committed pdm.toml can set global-only cache_dir, redirecting the plugin dir so a shipped .pth file executes code on any pdm startup.

- Payout: Research
- Severity: high
- Program: PDM
- Found by: gistrec
- Disclosed: 2026-12-04
- CVE: CVE-2026-141547
- Write-up quality: 8/10
- Original: https://github.com/advisories/GHSA-fv38-chg5-6pg2
- Library page: https://bugbountylibrary.com/r/ghsa%3AGHSA-fv38-chg5-6pg2
- Tags: area:oss domain:oss impact:rce kind:research platform:ghsa sev:high tech:python technique:chained technique:incomplete-fix technique:source-review vuln:misconfiguration vuln:rce

**Target:** pdm CLI plugin loader (project config / site.addsitedir)
**Root cause:** cache_dir is declared global_only but the check only runs in __setitem__; __getitem__ and Config.__init__ load the project pdm.toml unfiltered, and Project.config ChainMap lets the project value win, so project_plugins_dir is computed under a repo-controlled directory.
**Steps:**
1. Create project at /tmp/app with minimal `pyproject.toml` and `pdm.toml` containing `cache_dir = ".pdmcache"`.
2. Ship `.pdmcache/plugins/app-<sha224("/tmp/app")[:12]>/lib/python3.12/site-packages/zz_demo.pth` whose import line writes a marker file.
3. Run `cd /tmp/app && pdm --version`; marker file is created, proving .pth execution.
4. Control: remove pdm.toml, rerun, no marker.
**How found:** Audited the fix for GHSA-qq6c-99pv-prvf which moved the plugin library under cache_dir; noticed global_only is enforced only on write, then traced __getitem__/ChainMap precedence to project_plugins_dir and Core.__init__'s site.addsitedir call.
**Exploitation:** Attacker commits pdm.toml plus a prepared plugin directory tree (multiple path-hash and Python-version guesses) to a repo; when a victim runs any pdm command in that checkout at a matching path without PDM_CACHE_DIR set, Core.__init__ calls load_plugins(), site.addsitedir() processes the .pth, and arbitrary code runs as the victim.
**Escalation:** Repo ships several directories covering common CI/container checkout paths (/app, /home/runner/work/<repo>/<repo>, /workspaces/<repo>) and multiple lib/python3.X layouts to raise hit probability.
**Insight:** When a prior fix relocates attacker-influenced state under a config-derived path, check whether that config key's scoping (global_only, allowlist) is enforced on read as well as write — precedence chains like ChainMap silently let project files override.

## Proof of concept (copied exactly from the original report)

**Project pdm.toml sets cache_dir, .pth executes at pdm --version**

```
A project at `/tmp/app` with a minimal `pyproject.toml`, a `pdm.toml` containing `cache_dir = ".pdmcache"`, and `.pdmcache/plugins/app-<sha224("/tmp/app")[:12]>/lib/python3.12/site-packages/zz_demo.pth`, whose one `import` line writes a marker file. Then `cd /tmp/app && pdm --version`. Docker, no network, pdm 2.29.7 from PyPI (the latest release), Python 3.12:

PDM, version 2.29.7
[attack] pdm --version -> marker: pth executed, cmd=['/work/venv/bin/pdm', '--version']
$ pdm config cache_dir
.pdmcache
[control, no pdm.toml] marker: NONE
```

