{"id":"CVE-2026-102938","aliases":["CVE-2026-102938","GHSA-9h9j-4vrj-gf7g","BIT-VIRTUALENV-2026-102938","PYSEC-2026-4012"],"related":[],"kind":"vulnerability","state":"published","title":"virtualenv writes prompt values into pyvenv.cfg without sanitizing line boundaries, allowing configuration injection","summary":"virtualenv is a tool for creating isolated virtual python environments. Prior to 21.7.11, PyEnvCfg.write() writes prompt values verbatim to the line-oriented pyvenv.cfg format while PyEnvCfg._read_values() parses the file with str.splitlines() and accepts the last value for duplicate keys. An attacker who influences --prompt, VIRTUALENV_PROMPT, or configuration input can insert a recognized line boundary and additional keys, including home, causing consumers to use an attacker-selected base interpreter or corrupted environment metadata. The security impact requires prompt input from outside the operator's trust boundary; directly supplied prompt content primarily corrupts the operator's own environment. This issue is fixed in version 21.7.11.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"virtualenv is a tool for creating isolated virtual python environments. Prior to 21.7.11, PyEnvCfg.write() writes prompt values verbatim to the line-oriented pyvenv.cfg format while PyEnvCfg._read_values() parses the file with str.splitlines() and accepts the last value for duplicate keys. An attacker who influences --prompt, VIRTUALENV_PROMPT, or configuration input can insert a recognized line boundary and additional keys, including home, causing consumers to use an attacker-selected base interpreter or corrupted environment metadata. The security impact requires prompt input from outside the operator's trust boundary; directly supplied prompt content primarily corrupts the operator's own environment. This issue is fixed in version 21.7.11.","source":"cvelist"},{"lang":"en","text":"### Summary\n\n`pyvenv.cfg` is a line-based format with no escape syntax. `PyEnvCfg.write()` wrote values verbatim, while `PyEnvCfg._read_values()` parses the file with `str.splitlines()`. A value containing a line boundary therefore became additional configuration lines, and because reading is last-wins, the injected keys replaced any key written earlier in the file.\n\n### Impact\n\nThe `prompt` value is the reachable input: it is set by `--prompt`, by the `VIRTUALENV_PROMPT` environment variable, or from the config file, and `write()` emits `prompt` before `home`. A crafted prompt can therefore set `home` in the generated `pyvenv.cfg`:\n\n```console\n$ virtualenv --prompt $'x\"\\nhome = /attacker/path\\nprompt = \"z' venv\n$ grep '^home' venv/pyvenv.cfg\nhome = /attacker/path\n```\n\n`home` is what tooling reads to locate the base interpreter, so a consumer that trusts it can be pointed elsewhere. `implementation`, `version_info`, `version`, `executable`, `command` and `virtualenv` are also written before `prompt` and can be replaced the same way.\n\nThis requires the prompt to come from somewhere other than the person running the command, for example a CI job templating a branch name into it, tooling deriving an environment name from user-supplied data, or an inherited `VIRTUALENV_PROMPT`. Where the operator supplies the prompt directly they already control the command line, and the effect is corruption rather than privilege gain: the value is truncated at the boundary and read back with a dangling quote.\n\n### Details\n\nThe boundary set is the one `str.splitlines()` recognizes, which is wider than `\\n`: `\\r`, `\\v`, `\\f`, the file, group and record separators, `U+0085`, `U+2028` and `U+2029` were all written through unchanged and all split the line when read back.\n\n### Patches\n\n`PyEnvCfg.write()` now collapses those boundaries to spaces as it serializes each line, so it cannot emit a structurally invalid file regardless of what a caller places in `content`.\n\n### Workarounds\n\nDo not pass externally influenced data as the virtualenv prompt. Strip line boundaries from any value before using it as `--prompt` or `VIRTUALENV_PROMPT`.","format":"markdown","source":"ghsa"},{"lang":"en","text":"`pyvenv.cfg` is a line-based format with no escape syntax. `PyEnvCfg.write()`\nwrote values verbatim, while `PyEnvCfg._read_values()` parses the file with\n`str.splitlines()`. A value containing a line boundary therefore became\nadditional configuration lines, and because reading is last-wins, the injected\nkeys replaced any key written earlier in the file.\n\nThe `prompt` value is the reachable input: it is set by `--prompt`, by the\n`VIRTUALENV_PROMPT` environment variable, or from the config file, and\n`write()` emits `prompt` before `home`. A crafted prompt can therefore set\n`home` in the generated `pyvenv.cfg`. `home` is what tooling reads to locate\nthe base interpreter, so a consumer that trusts it can be pointed elsewhere.\n`implementation`, `version_info`, `version`, `executable`, `command` and\n`virtualenv` are also written before `prompt` and can be replaced the same\nway.\n\nThis requires the prompt to come from somewhere other than the person running\nthe command, for example a CI job templating a branch name into it, tooling\nderiving an environment name from user-supplied data, or an inherited\n`VIRTUALENV_PROMPT`.\n\nThe boundary set is the one `str.splitlines()` recognizes, which is wider than\n`\\n`: `\\r`, `\\v`, `\\f`, the file, group and record separators, `U+0085`,\n`U+2028` and `U+2029` were all written through unchanged and all split the\nline when read back.\n\nFixed in 21.7.11: `PyEnvCfg.write()` now collapses those boundaries to spaces\nas it serializes each line, so it cannot emit a structurally invalid file\nregardless of what a caller places in `content`.","format":"markdown","source":"pysec"}],"published":"2026-09-17T16:42:47.000Z","modified":"2026-11-27T06:45:48.141Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:L/AC:L/AT:P/PR:N/UI:P/VC:L/VI:H/VA:L/SC:N/SI:N/SA:N","score":5.8,"rating":"MEDIUM"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:L/AC:L/AT:P/PR:N/UI:P/VC:L/VI:H/VA:L/SC:N/SI:N/SA:N","score":5.8,"rating":"MEDIUM"},{"scorer":"GitHub","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:L/AC:L/AT:P/PR:N/UI:P/VC:L/VI:H/VA:L/SC:N/SI:N/SA:N","rating":"MEDIUM"},{"scorer":"NVD","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:N","score":6.2,"rating":"MEDIUM"},{"scorer":"Bitnami Vulnerability Database","scheme":"rating","rating":"MEDIUM"}],"cwes":["CWE-93"],"affected":[{"ranges":[{"version":"< 21.7.11","status":"affected"}],"vendor":"pypa","product":"virtualenv","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"21.7.11"}],"ecosystem":"PyPI","package":"virtualenv","purl":"pkg:pypi/virtualenv","source":"ghsa"},{"ranges":[{"status":"affected","fixed":"21.7.11"}],"vendor":"virtualenv","product":"virtualenv","cpe":"cpe:2.3:a:virtualenv:virtualenv:*:*:*:*:*:*:*:*","source":"nvd"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"21.7.11"}],"ecosystem":"PyPI","package":"virtualenv","purl":"pkg:pypi/virtualenv","source":"pysec"},{"ranges":[{"type":"semver","introduced":"0","status":"affected","fixed":"21.7.11"}],"ecosystem":"Bitnami","package":"virtualenv","purl":"pkg:bitnami/virtualenv","source":"bitnami"}],"references":[{"url":"https://github.com/pypa/virtualenv/security/advisories/GHSA-9h9j-4vrj-gf7g","tags":["advisory","vendor-advisory","web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd","pysec","bitnami"]},{"url":"https://github.com/pypa/virtualenv/pull/3247","tags":["fix","issue-tracking","patch","web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd","pysec","bitnami"]},{"url":"https://github.com/pypa/virtualenv/commit/a30f995461043acb6cacbf3a890951563ccf7140","tags":["fix","patch","web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd","pysec","bitnami"]},{"url":"https://github.com/pypa/virtualenv/releases/tag/21.7.11","tags":["article","release-notes","web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd","pysec","bitnami"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-102938","tags":["advisory","web"],"sources":["ghsa","bitnami"]},{"url":"https://github.com/pypa/advisory-database/tree/main/vulns/virtualenv/PYSEC-2026-4012.yaml","tags":["web"],"sources":["ghsa"]},{"url":"https://github.com/pypa/virtualenv","tags":["package"],"sources":["ghsa","pysec"]},{"url":"https://pypi.org/project/virtualenv","tags":["package","web"],"sources":["ghsa","pysec"]}],"credits":["Bernát Gábor"],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"none","automatable":"no","technicalImpact":"partial","date":"2026-09-30T19:53:10.688Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-102938","url":"https://www.cve.org/CVERecord?id=CVE-2026-102938","licence":"CVE Terms of Use","modified":"2026-09-30T19:53:20.817Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-9h9j-4vrj-gf7g","url":"https://github.com/advisories/GHSA-9h9j-4vrj-gf7g","licence":"CC-BY-4.0","modified":"2026-10-06T15:25:56.172Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-102938","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-102938","licence":"Public domain","modified":"2026-11-19T19:51:23.310Z"},{"source":"pysec","name":"PyPA Advisory Database","id":"PYSEC-2026-4012","url":"https://osv.dev/vulnerability/PYSEC-2026-4012","licence":"CC-BY-4.0","modified":"2026-10-06T15:25:56.172Z"},{"source":"bitnami","name":"Bitnami Vulnerability Database","id":"BIT-VIRTUALENV-2026-102938","url":"https://osv.dev/vulnerability/BIT-VIRTUALENV-2026-102938","licence":"Apache-2.0","modified":"2026-11-27T06:45:48.141Z"}],"updatedAt":"2026-11-27T07:07:23.918Z","epss":{"score":0.00153,"percentile":0.04685,"date":"2026-12-01T12:00:22.000Z"}}