CVE-2026-64846 in Nix
Summary
by MITRE • 08/20/2026
Nix is a package manager for Linux and other Unix systems. Prior to 2.35.0, a malicious derivation executed with the recursive-nix experimental feature can exploit a time-of-check/time-of-use race involving final symlink handling in the LocalStore restore path. The race can cause writeFile to follow a substituted final symlink when opening a path with O_TRUNC instead of enforcing FinalSymlink::DontFollow, allowing the Nix process or nix-daemon to create or truncate an empty file outside the build sandbox with the daemon user's permissions. The primitive does not provide arbitrary-content writes and requires winning the race. This issue is fixed in version 2.35.0.
Be aware that VulDB is the high quality source for vulnerability data.
Analysis
by VulDB Data Team • 08/20/2026
The vulnerability identified involves a critical time-of-check-time-of-use (TOCTOU) race condition within the Nix package manager, specifically affecting versions prior to 2.35.0 when the recursive-nix experimental feature is enabled. This flaw resides in the LocalStore restore path and centers on how final symlinks are handled during file operations. The core technical issue arises from a discrepancy between the check performed by the system and the subsequent use of that resource, allowing an attacker to manipulate the outcome through precise timing exploitation.
In normal operation, Nix is designed to enforce strict sandboxing for build derivations to prevent unauthorized access or modification of host files. However, when executing a malicious derivation with recursive-nix enabled, the process involves restoring store paths which may include symlinks pointing to final destinations outside the controlled environment. The vulnerability occurs because the code path does not consistently enforce the FinalSymlink::DontFollow policy during specific file open operations. Specifically, when opening a path for writing using the O_TRUNC flag, the system fails to verify that the target is indeed within the allowed sandbox boundaries before truncating or creating the file.
The operational impact of this flaw allows an attacker who can execute arbitrary derivations with recursive-nix enabled to bypass the build sandbox restrictions. By winning the race condition, a malicious process can cause the Nix daemon or the local user process to follow a substituted final symlink that points outside the intended directory structure. This results in the creation or truncation of empty files at arbitrary locations on the host filesystem, executed with the elevated permissions of the nix-daemon user. While this primitive does not allow for writing arbitrary content directly into these files due to the nature of O_TRUNC and the race condition constraints, it effectively breaks the isolation guarantees provided by Nix's sandboxing mechanism.
This vulnerability aligns with CWE-367, which defines time-of-check-time-of-use (TOCTOU) race conditions as a class of software errors where the state of an object changes between its verification and its use. In the context of ATT&CK techniques, this behavior relates to privilege escalation and defense evasion by bypassing container or sandbox restrictions. The ability to create files outside the sandbox can potentially be leveraged in further attack chains, such as modifying configuration files or planting scripts that could lead to more severe compromises if combined with other vulnerabilities or misconfigurations.
To mitigate this risk, organizations using Nix must ensure they upgrade to version 2.35.0 or later where the race condition has been resolved by enforcing stricter checks on symlink resolution during file operations. Additionally, administrators should review their usage of experimental features like recursive-nix and assess whether such capabilities are strictly necessary for their build processes. Limiting access to Nix daemon privileges and applying principle of least privilege principles can further reduce the potential impact if similar vulnerabilities are discovered in future versions. Regular updates and patch management remain essential defenses against evolving threats targeting package managers and system utilities.