MEDIUM 5.3

CVE-2026-58203: pydantic-settings Symlink Traversal in Nested Secrets Directory

pydantic-settings is a Python library that manages application configuration through Pydantic models. Versions 2.12.0 through 2.14.1 contain a flaw in how they handle secret files stored in a designated secrets directory. When the nested subdirectory feature is enabled, the library will follow symbolic links (shortcuts) that point outside the intended secrets directory, allowing it to read arbitrary files from the system. An attacker with write access to the secrets directory—such as in a shared or world-writable mount—can create malicious symbolic links to trick the application into loading sensitive files from anywhere on the system. This also bypasses the documented size limit protection meant to prevent loading oversized files.

Source data · NVD / CISA · public domain

CVSS
3.1 · 5.3 MEDIUM · CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:L/I:L/A:L
Weaknesses (CWE)
CWE-22, CWE-400, CWE-59
Affected products
1 configuration(s)
Published / Modified
2026-07-06 / 2026-07-27

NVD description (verbatim)

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.

2 reference(s) · View on NVD →

SEC.co analysis · AI-assisted, reviewed against source

Technical summary

The vulnerability exists in NestedSecretsSettingsSource, which reads secret values from files within a configured secrets_dir. When secrets_nested_subdir=True is set, the code fails to validate that directory entries are legitimate directories rather than symbolic links. By following symlinks without validation, an attacker can redirect file reads outside the intended secrets_dir boundary. Additionally, this code path bypasses the secrets_dir_max_size enforcement, allowing an attacker to load files larger than the documented protection limit. The vulnerability affects path traversal (CWE-22), uncontrolled resource consumption (CWE-400), and improper link resolution (CWE-59). The flaw is present in versions 2.12.0 through 2.14.1 and is resolved in 2.14.2.

Business impact

Organizations relying on pydantic-settings to manage application secrets and configuration are at risk if they enable the nested subdirectory feature. A malicious or compromised component with write access to the secrets directory can exfiltrate sensitive data—database credentials, API keys, encryption keys—into application memory. In containerized or multi-tenant environments where multiple services share a secrets mount, a lower-privileged service or attacker could exploit this to access secrets belonging to other applications. The bypass of size protections adds complexity to resource management and denial-of-service scenarios. This is particularly concerning in Kubernetes deployments using shared volumes or in CI/CD pipelines where build artifacts share storage.

Affected systems

The vulnerability affects pydantic-settings versions 2.12.0 through 2.14.1 inclusive. Any application using pydantic-settings with secrets_nested_subdir=True is vulnerable if the secrets directory is writable by untrusted processes or shared across multiple security domains. The vulnerability does not affect versions prior to 2.12.0 or version 2.14.2 and later. Applications that do not enable the nested subdirectory feature are not affected by this specific flaw.

Exploitability

Exploitation requires local access to the system and write permissions to the configured secrets directory. The attacker must create a symbolic link within the secrets_dir that points to a sensitive file outside that directory. When the application initializes or reloads its settings with secrets_nested_subdir=True enabled, it will follow the link and load the target file. The attack is reliable and does not require any user interaction or special timing. The CVSS score of 5.3 (Medium) reflects that exploitation requires local access and lower privileges but grants file read capabilities and can affect confidentiality, integrity (through configuration manipulation), and availability (through resource exhaustion via the size limit bypass).

Remediation

Upgrade pydantic-settings to version 2.14.2 or later. This version implements proper symlink detection and validation, preventing directory traversal attacks and restoring the secrets_dir_max_size protection. Organizations unable to upgrade immediately should disable the secrets_nested_subdir feature if it is not essential for their deployment model, and should restrict write access to the secrets directory to only trusted processes with appropriate security controls.

Patch guidance

Apply the upgrade to pydantic-settings 2.14.2 or later as soon as feasible. Verify the upgrade in development and staging environments before deploying to production. If the nested subdirectory feature is not in use, confirm it remains disabled (secrets_nested_subdir=False or not set) in your configuration. Check application logs and secrets-loading behavior post-upgrade to ensure no regressions. For organizations using dependency management tools, update your requirements.txt, pyproject.toml, or equivalent dependency manifest and re-run your build pipeline.

Detection guidance

Monitor the secrets directory for unexpected symbolic links or entries that do not match your documented configuration schema. Audit file access patterns to the secrets directory, particularly any attempts to read files outside its intended boundary. Review system logs for symlink creation events in shared or mounted secrets directories. In containerized environments, use volume mount options to prevent symlink traversal (e.g., mount with nosymfollow if your orchestrator supports it). Implement alerting on failed or unusual settings initialization events in application logs. A security scanner that validates dependency versions can identify vulnerable pydantic-settings versions in your codebase.

Why prioritize this

Although the CVSS score is Medium (5.3), this vulnerability should be prioritized for patching in environments where the nested subdirectory feature is actively used and the secrets directory is shared, writable, or accessible to multiple security domains. In Kubernetes, container orchestration, or shared hosting scenarios, the practical risk is elevated because attackers with lower privileges can abuse the feature. The bypass of size protections adds an additional attack surface. Organizations in highly restrictive environments where secrets directories are read-only to all but the application process can deprioritize slightly, but patching remains recommended as a best practice.

Risk score, explained

The CVSS 3.1 score of 5.3 (Medium) is calculated using Attack Vector: Local, Attack Complexity: Low, Privileges Required: Low, User Interaction: None, Scope: Unchanged, and impacts to Confidentiality, Integrity, and Availability of Low. This reflects that the attack requires local presence and some level of privilege to write to the secrets directory, but exploitation is straightforward and no user interaction is needed. The impact is bounded by local scope and file-read semantics, but in multi-tenant or shared environments, the practical risk is higher than the score suggests. Organizations should assess their specific deployment architecture when determining remediation urgency.

Frequently asked questions

Does this vulnerability affect applications that do not use secrets_nested_subdir?

No. The vulnerability specifically impacts the NestedSecretsSettingsSource code path when secrets_nested_subdir=True. If this feature is disabled or not configured, your application is not affected by this flaw. You should verify your pydantic-settings configuration to confirm the nested subdirectory feature is not in use.

Can this vulnerability be exploited remotely?

No. The vulnerability requires local access to the system and write permissions to the configured secrets directory. Remote attackers cannot directly exploit this flaw. However, in cloud or containerized environments, a compromised service running on the same host may have the necessary access to exploit it against other applications.

What files can an attacker read using this vulnerability?

An attacker can read any file on the system that the application process has permission to access. Typically, this means sensitive files readable by the application user, such as system configuration files, other applications' secrets, or private keys. The scope depends on the application's privilege level and file system permissions.

Is version 2.14.2 the only patched version, or are there later versions?

Version 2.14.2 is the minimum patched version. Any version 2.14.2 or later includes the fix. Always use the latest available version of pydantic-settings unless you have specific compatibility constraints with your application stack.

This analysis is based on the CVE record and vendor advisory information available as of the modification date. Specific version numbers, patch dates, and technical details should be verified against the official pydantic-settings release notes and GitHub repository. Organizations should perform their own risk assessment based on their deployment environment, secrets directory configuration, and security posture. This intelligence is provided for informational purposes to support vulnerability management and patch prioritization decisions. Source: NVD (public-domain), retrieved 2026-08-15. Analysis generated by SEC.co (claude-haiku-4-5).