{"id":"CVE-2026-58203","aliases":["CVE-2026-58203","GHSA-4xgf-cpjx-pc3j"],"related":[],"kind":"vulnerability","state":"published","title":"NestedSecretsSettingsSource follows symlinks outside secrets_dir, enabling local file read and bypassing secrets_dir_max_size","summary":"pydantic-settings provides settings management using Pydantic. From 2.12.0 until 2.14.2, NestedSecretsSettingsSource reads secret values from files in a configured secrets_dir. When secrets_nested_subdir=True, a directory entry inside secrets_dir that is a symbolic link pointing outside secrets_dir is followed, so files outside the configured directory are read into settings values. The same code path bypasses the documented secrets_dir_max_size protection. An attacker or lower-privileged component able to influence entries in the configured secrets directory (for example, a writable or shared secrets mount) can turn this into an unintended local file read into settings and can defeat the advertised loading-size cap.  This vulnerability is fixed in 2.14.2.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"pydantic-settings provides settings management using Pydantic. From 2.12.0 until 2.14.2, NestedSecretsSettingsSource reads secret values from files in a configured secrets_dir. When secrets_nested_subdir=True, a directory entry inside secrets_dir that is a symbolic link pointing outside secrets_dir is followed, so files outside the configured directory are read into settings values. The same code path bypasses the documented secrets_dir_max_size protection. An attacker or lower-privileged component able to influence entries in the configured secrets directory (for example, a writable or shared secrets mount) can turn this into an unintended local file read into settings and can defeat the advertised loading-size cap.  This vulnerability is fixed in 2.14.2.","source":"cvelist"},{"lang":"en","text":"### Summary\n\n`NestedSecretsSettingsSource` reads secret values from files in a configured `secrets_dir`. When `secrets_nested_subdir=True`, a directory entry inside `secrets_dir` that is a symbolic link pointing **outside** `secrets_dir` is followed, so files outside the configured directory are read into settings values. The same code path bypasses the documented `secrets_dir_max_size` protection. An attacker or lower-privileged component able to influence entries in the configured secrets directory (for example, a writable or shared secrets mount) can turn this into an unintended local file read into settings and can defeat the advertised loading-size cap. This report does not claim network reachability by itself.\n\n### Details\n\n`NestedSecretsSettingsSource` performed two passes over `secrets_dir` using two different, inconsistent directory-traversal implementations:\n\n* The size check in `validate_secrets_path()` used `Path.glob('**/*')`, which does **not** descend into a symbolically-linked directory.\n* The loader in `load_secrets()` used `glob.iglob(f'{path}/**/*', recursive=True)` followed by `read_text()`, which **does** follow symlinked directories and reads through the link target.\n\nBecause the two passes disagreed on symlinks, a symlinked directory inside `secrets_dir` whose target lives elsewhere was invisible to the size accounting (counted as 0 bytes) while still being fully read by the loader. This produces two distinct problems:\n\n1. **Out-of-tree read (CWE-22 / CWE-59).** A symlinked directory (or file) inside `secrets_dir` that resolves outside it is followed, and the external file's contents are loaded into the corresponding settings field.\n2. **`secrets_dir_max_size` bypass (CWE-400).** The size check never sees the out-of-tree content, so the documented size cap is neither respected nor able to reject the oversized external file. A related amplification exists for cyclic in-tree symlinks, which `glob.iglob(recursive=True)` re-traverses, inflating the size accounting and the number of loaded secrets.\n\n#### Reproduction\n\nIn a clean Linux container, with a `secrets_dir` containing a symlink `secrets/db -> /path/outside` and an `outside/passwd` file of 512 bytes, while `secrets_dir_max_size=100`:\n\n```python\nfrom pydantic import BaseModel\nfrom pydantic_settings import (\n    BaseSettings,\n    SettingsConfigDict,\n    NestedSecretsSettingsSource,\n)\n\n\nclass Db(BaseModel):\n    passwd: str | None = None\n\n\nclass Settings(BaseSettings):\n    model_config = SettingsConfigDict(\n        secrets_dir='secrets',\n        secrets_nested_subdir=True,\n        secrets_dir_max_size=100,  # outside/passwd is 512 bytes\n    )\n    db: Db = Db()\n\n    @classmethod\n    def settings_customise_sources(\n        cls, settings_cls, init_settings, env_settings, dotenv_settings, file_secret_settings\n    ):\n        return (NestedSecretsSettingsSource(file_secret_settings),)\n```\n\nOn affected versions, `Settings().db.passwd` is populated with the 512-byte out-of-tree file and **no** `SettingsError` is raised, even though the file exceeds `secrets_dir_max_size`.\n\n### Impact\n\nApplications that opt into `NestedSecretsSettingsSource` with `secrets_nested_subdir=True` and load secrets from a directory whose entries can be influenced by an attacker or a lower-privileged component (for example, a writable or shared secrets mount, or a secrets directory partially populated from untrusted input) are affected. The impact is:\n\n* **Confidentiality:** files outside the configured `secrets_dir` can be read into settings values (local file read).\n* **Integrity / availability of the safeguard:** the advertised `secrets_dir_max_size` cap can be bypassed, and cyclic symlinks can inflate resource usage during loading.\n\nThe vulnerability requires the ability to place a symbolic link inside the configured secrets directory; it is not remotely reachable on its own. Applications that do not use `NestedSecretsSettingsSource`, or that point `secrets_dir` at a directory fully under the application's control, are not affected.\n\n### Mitigation\n\nUpgrade to **pydantic-settings 2.14.2**, which:\n\n* walks the secrets directory explicitly and only descends into directories whose resolved path stays within `secrets_dir`, so symlinked directories pointing outside are never followed;\n* uses a single, cycle-safe iterator for both the size check and the loader, so the size accounting and the loaded set are always consistent and each real directory is visited at most once;\n* skips any file whose resolved path escapes `secrets_dir`, as defense in depth.\n\nIf upgrading is not immediately possible, ensure the configured `secrets_dir` is fully owned and controlled by the application (no writable or attacker-influenced entries), or avoid `secrets_nested_subdir=True`.","format":"markdown","source":"ghsa"},{"lang":"es","text":"pydantic-settings proporciona gestión de configuraciones utilizando Pydantic. Desde 2.12.0 hasta 2.14.2, NestedSecretsSettingsSource lee valores secretos de archivos en un secrets_dir configurado. Cuando secrets_nested_subdir=True, se sigue una entrada de directorio dentro de secrets_dir que es un enlace simbólico que apunta fuera de secrets_dir, por lo que los archivos fuera del directorio configurado se leen como valores de configuración. La misma ruta de código omite la protección documentada secrets_dir_max_size. Un atacante o un componente con privilegios inferiores capaz de influir en las entradas del directorio de secretos configurado (por ejemplo, un montaje de secretos escribible o compartido) puede convertir esto en una lectura de archivo local no intencionada en la configuración y puede anular el límite de tamaño de carga anunciado. Esta vulnerabilidad está corregida en 2.14.2.","source":"nvd"}],"published":"2026-06-19T22:10:42.000Z","modified":"2026-10-25T20:10:00.147Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:L/I:L/A:L","score":5.3,"rating":"MEDIUM"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:L/I:L/A:L","score":5.3,"rating":"MEDIUM"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:L/I:L/A:L","score":5.3,"rating":"MEDIUM"}],"cwes":["CWE-22","CWE-59","CWE-400"],"affected":[{"ranges":[{"version":">= 2.12.0, < 2.14.2","status":"affected"}],"vendor":"pydantic","product":"pydantic-settings","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"2.12.0","status":"affected","fixed":"2.14.2"}],"ecosystem":"PyPI","package":"pydantic-settings","purl":"pkg:pypi/pydantic-settings","source":"ghsa"},{"ranges":[{"status":"affected","introduced":"2.12.0","fixed":"2.14.2"}],"vendor":"pydantic","product":"pydantic-settings","cpe":"cpe:2.3:a:pydantic:pydantic-settings:*:*:*:*:*:*:*:*","source":"nvd"}],"references":[{"url":"https://github.com/pydantic/pydantic-settings/security/advisories/GHSA-4xgf-cpjx-pc3j","tags":["exploit","mitigation","vendor-advisory","web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/pydantic/pydantic-settings","tags":["package"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"no","technicalImpact":"partial","date":"2026-07-06T16:19:35.619Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-58203","url":"https://www.cve.org/CVERecord?id=CVE-2026-58203","licence":"CVE Terms of Use","modified":"2026-07-06T16:19:59.090Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-4xgf-cpjx-pc3j","url":"https://github.com/advisories/GHSA-4xgf-cpjx-pc3j","licence":"CC-BY-4.0","modified":"2026-09-10T03:50:48.282Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-58203","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-58203","licence":"Public domain","modified":"2026-10-25T20:10:00.147Z"}],"updatedAt":"2026-11-25T22:59:27.229Z","epss":{"score":0.00196,"percentile":0.09832,"date":"2026-12-01T12:00:22.000Z"}}