Skip to main content
CVE Vulnerability Database
Vulnerability Database/CVE-2024-45593

CVE-2024-45593: NixOS Nix Path Traversal Vulnerability

CVE-2024-45593 is a path traversal vulnerability in NixOS Nix that allows attackers to write to arbitrary file system locations with root permissions. This article covers technical details, affected versions, and mitigation.

Published:

CVE-2024-45593 Overview

CVE-2024-45593 is a path traversal vulnerability [CWE-22] in the Nix package manager affecting versions 2.24 through 2.24.5. A bug in the Nix Archive (NAR) unpacking logic allows a substituter or malicious user to craft a NAR file that causes Nix to write to arbitrary file system locations accessible to the Nix process. When Nix runs through the Nix daemon, those writes occur with root permissions. The issue was fixed in Nix 2.24.6.

Critical Impact

A crafted NAR archive can force the Nix daemon to write files to attacker-chosen locations on the host, enabling privilege escalation to root on systems using the standard multi-user Nix installation.

Affected Products

  • NixOS Nix 2.24 through 2.24.5
  • Systems using the multi-user Nix daemon (nix-daemon)
  • Any distribution shipping Nix 2.24.x prior to 2.24.6

Discovery Timeline

  • 2024-09-10 - CVE-2024-45593 published to NVD
  • 2026-06-17 - Last updated in NVD database

Technical Details for CVE-2024-45593

Vulnerability Analysis

Nix uses the Nix Archive (NAR) format to serialize and transfer file trees between stores and substituters. The RestoreSink component in src/libutil/fs-sink.cc is responsible for reconstructing directories and files from a NAR stream on the local file system. Prior to the fix, path components inside the NAR were joined to the destination directory without validating that the resulting path stayed within the intended destination.

Because Nix on multi-user installations invokes the sink through nix-daemon, which runs as root, a malicious NAR served by an untrusted substituter or supplied by a low-privileged local user could redirect file creation to arbitrary locations. The result is arbitrary file write as root, which is trivially convertible to full system compromise through techniques such as overwriting /etc/shadow, cron files, or systemd unit files.

Root Cause

The root cause is missing canonicalization and boundary enforcement when appending a NAR-supplied relative path to the destination directory. The pre-patch code executed std::filesystem::create_directory(dstPath / path.rel()) and equivalent file-creation calls without checking that path.rel() was a well-formed, non-escaping relative path.

Attack Vector

An attacker crafts a NAR archive containing entries whose relative paths break out of the destination store path. When a victim system fetches and unpacks the archive through the Nix daemon, files are written outside the Nix store with daemon privileges. Delivery vectors include a compromised or malicious binary cache configured as a substituter, or a local user submitting a malicious NAR through the daemon socket.

cpp
// Patch excerpt from src/libutil/fs-sink.cc (post-fix)
static std::filesystem::path append(const std::filesystem::path & src, const CanonPath & path)
{
    auto dst = src;
    if (!path.rel().empty())
        dst /= path.rel();
    return dst;
}

void RestoreSink::createDirectory(const CanonPath & path)
{
    auto p = append(dstPath, path);
    if (!std::filesystem::create_directory(p))
        throw Error("path '%s' already exists", p.string());
};

Source: NixOS/nix commit eb11c14. The fix routes all path construction through CanonPath, which enforces canonicalization, and rejects pre-existing paths so an attacker cannot overwrite existing targets.

Detection Methods for CVE-2024-45593

Indicators of Compromise

  • Unexpected files created outside /nix/store with timestamps matching recent nix-daemon activity.
  • New or modified files in sensitive locations such as /etc, /root, or /var/spool/cron owned by root but not attributable to package management.
  • Substituter URLs in nix.conf or ~/.config/nix/nix.conf pointing to untrusted caches.

Detection Strategies

  • Audit installed Nix versions across hosts and flag any running nix --version output between 2.24.0 and 2.24.5.
  • Inspect nix-daemon process activity for openat and mkdir syscalls targeting paths outside /nix/store using auditd or eBPF tracing.
  • Review substituter configuration and public key trust lists for entries not managed by administrators.

Monitoring Recommendations

  • Enable file integrity monitoring on /etc, /root/.ssh, and systemd unit directories to catch out-of-store writes.
  • Log every nix copy, nix-store --import, and nix build --substituters invocation and correlate against the daemon audit trail.
  • Alert on modifications to nix.conf that add new substituters or trusted-public-keys entries.

How to Mitigate CVE-2024-45593

Immediate Actions Required

  • Upgrade Nix to version 2.24.6 or later on all systems using the multi-user daemon.
  • Remove any untrusted substituters from nix.conf and restrict trusted-substituters to caches you control.
  • Restrict membership of the nix-users group and review which local accounts can submit builds to the daemon.

Patch Information

The fix is included in Nix 2.24.6 and is delivered by commit eb11c1499876cd4c9c188cbda5b1003b36ce2e59. Details of the coordinated disclosure are documented in the GitHub Security Advisory GHSA-h4vv-h3jq-v493. Users on distributions that vendor Nix (NixOS, nix-darwin, third-party Linux packages) should verify their distribution has picked up the patched release.

Workarounds

  • If immediate upgrade is not possible, disable the Nix daemon and use single-user Nix so writes occur with the invoking user's privileges rather than root.
  • Set substituters = to an empty value or restrict it to first-party caches, and remove any untrusted entries from trusted-public-keys.
  • Block untrusted users from the nix-daemon socket by tightening the permissions on /nix/var/nix/daemon-socket/socket.
bash
# Verify the installed Nix version and upgrade if vulnerable
nix --version

# On NixOS, pin to a channel that ships Nix >= 2.24.6
sudo nix-channel --update
sudo nixos-rebuild switch

# On non-NixOS installations, upgrade via the daemon
sudo -i nix upgrade-nix

# Harden nix.conf: restrict substituters to trusted caches only
cat <<'EOF' | sudo tee /etc/nix/nix.conf
substituters = https://cache.nixos.org/
trusted-substituters =
trusted-users = root
EOF
sudo systemctl restart nix-daemon

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Default Legacy - Prefooter | Experience the World’s Most Advanced Cybersecurity Platform

Experience the Most Advanced Cybersecurity Platform

See how the world’s most intelligent, autonomous cybersecurity platform can protect your organization today and into the future.