CVE-2026-140014: AES-256-GCM Nonce Reuse Across Forked Processes in Rust cookie-rs PrivateJar
Vulnerability ID: CVE-2026-140014
CVSS Score: 6.5
Published: 2026-12-01
CVE-2026-140014 (also tracked as GHSA-8wcq-xq25-7fhm and RUSTSEC-2026-0594) is a cryptographic weakness in the Rust cookie library (cookie-rs). Affected versions use userspace thread-local pseudo-random number generators (rand::thread_rng() or rand::rng()) to generate 96-bit nonces for AES-256-GCM encrypted cookies in PrivateJar. Because these generators buffer entropy in userspace memory, invoking a Unix fork() system call without exec() clones the internal RNG buffer into child processes. When sibling or parent-child processes subsequently seal private cookies on the same thread using a shared key, they emit identical nonces. This nonce reuse under AES-GCM compromises ciphertext confidentiality via keystream XOR recovery and enables arbitrary cookie forgery via polynomial GHASH authentication key recovery.
TL;DR
The Rust cookie crate (versions 0.11.3 to <0.12.0 and 0.14.0 to <0.18.3) uses a buffered userspace thread-local RNG to generate AES-256-GCM nonces for PrivateJar cookies. Across Unix fork() boundaries, child processes inherit identical RNG state buffers, resulting in nonce reuse that allows attackers to decrypt cookie plaintexts and forge arbitrary authenticated cookies.
Technical Details
- CVE / Advisory IDs: CVE-2026-140014 / GHSA-8wcq-xq25-7fhm / RUSTSEC-2026-0594
- Weakness Class: CWE-323: Reusing a Nonce, Key Pair in Encryption
- CVSS v3.1 Score: 6.5 Medium (CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:H/A:N)
- EPSS Score: 0.435% (39.54th Percentile)
- Affected Component: cookie::PrivateJar::add & PrivateJar::add_original (Rust cookie crate)
- Cryptographic Impact: AES-256-GCM Plaintext XOR Recovery & GHASH Key Recovery (Cookie Forgery)
- Patched Version: cookie >= 0.18.3 (and >= 0.12.0, < 0.14.0)
- CISA KEV Status: Not Listed
Affected Systems
- Rust cookie crate (cookie-rs) versions >= 0.11.3, < 0.12.0
- Rust cookie crate (cookie-rs) versions >= 0.14.0, < 0.18.3
- Unix-like applications (Linux, macOS, FreeBSD, NetBSD, OpenBSD, Solaris, Illumos) using cookie::PrivateJar across fork() boundaries
- cookie: >= 0.11.3, < 0.12.0 (Fixed in:
0.12.0) - cookie: >= 0.14.0, < 0.18.3 (Fixed in:
0.18.3)
Code Analysis
Commit: 4a5e0f3
Generate private cookie nonces using the OS (SysRng) and require rand 0.10.1 without chacha20.
diff --git a/Cargo.toml b/Cargo.toml index 3202900a..ec5668de 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,7 +32,7 @@ aes-gcm = { version = "0.11", optional = true } hmac = { version = "0.13", optional = true } sha2 = { version = "0.11", optional = true } base64 = { version = "0.23", optional = true } -rand = { version = "0.10", optional = true } +rand = { version = "0.10.1", default-features = false, features = ["sys_rng"], optional = true } hkdf = { version = "0.13", optional = true } subtle = { version = "2.3", optional = true } diff --git a/src/secure/private.rs b/src/secure/private.rs index 57938b1b..8c9f18bb 100644 --- a/src/secure/private.rs +++ b/src/secure/private.rs @@ -6,7 +6,7 @@ use crate::{Cookie, CookieJar}; use aes_gcm::aead::{Aead, AeadInOut, KeyInit, Payload}; use aes_gcm::{Aes256Gcm, Nonce}; -use rand::Rng; +use rand::TryRng; // Keep these in sync, and keep the key len synced with the `private` docs as // well as the `KEYS_INFO` const in secure::Key. @@ -47,9 +47,10 @@ impl<J> PrivateJar<J> { let (in_out, tag) = in_out.split_at_mut(cookie_val.len()); in_out.copy_from_slice(cookie_val); - // Fill nonce piece with random data. - let mut rng = rand::rng(); - rng.fill_bytes(nonce); + // Fill nonce piece with random data from the OS. We don't use a + // userspace RNG as it may yield the same nonces after a process forks. + let mut rng = rand::rngs::SysRng; + rng.try_fill_bytes(nonce).expect("couldn't random fill nonce"); let nonce = Nonce::try_from(&*nonce).expect("nonce len"); // Perform the actual sealing operation, using the cookie's name as Commit: 98de603
Generate private cookie nonces using the OS (OsRng) in place of thread_rng.
diff --git a/src/secure/private.rs b/src/secure/private.rs index 8caf86e5..c033b03e 100644 --- a/src/secure/private.rs +++ b/src/secure/private.rs @@ -49,8 +49,8 @@ impl<J> PrivateJar<J> { let (in_out, tag) = in_out.split_at_mut(cookie_val.len()); in_out.copy_from_slice(cookie_val); - // Fill nonce piece with random data. - let mut rng = self::rand::thread_rng(); + // Fill nonce piece with random data from the OS. + let mut rng = self::rand::rngs::OsRng; rng.try_fill_bytes(nonce).expect("couldn't random fill nonce"); let nonce = GenericArray::clone_from_slice(nonce); Mitigation Strategies
- Upgrade the cookie crate to version 0.18.3 or later to enforce direct operating system entropy generation (OsRng / SysRng) for AES-GCM nonces.
- Rotate all secret keys used with PrivateJar if the application previously ran in a Unix pre-fork worker configuration.
- Avoid initializing or invoking userspace thread-local RNGs (rand::thread_rng / rand::rng) prior to invoking POSIX fork().
- Spawn worker threads (such as Tokio multi-threaded runtime threads) after calling fork() rather than handling requests on the initial forked thread.
Remediation Steps:
- Update Cargo.toml to specify cookie = "^0.18.3" or run 'cargo update -p cookie' to update Cargo.lock.
- Verify the resolved version in Cargo.lock is >= 0.18.3 (or within the unaffected ranges < 0.11.3 or >= 0.12.0, < 0.14.0).
- Rebuild and redeploy the Rust application binary.
- Generate and deploy a new 64-byte cryptographic master key for PrivateJar to invalidate any historically leaked GHASH subkeys.
References
- GitHub Security Advisory: GHSA-8wcq-xq25-7fhm
- Fix Commit 4a5e0f31fa18731cb8270090f1d173679bca913c (SysRng transition)
- Fix Commit 98de6032defb10ad5e49d83fa1a9bbed1873cbe4 (OsRng transition)
- cookie-rs Release v0.18.3
- NIST National Vulnerability Database: CVE-2026-140014
- CVE.org Official Record: CVE-2026-140014
- OSV Database Entry: RUSTSEC-2026-0594
- RustSec Advisory Markdown Source: RUSTSEC-2026-0594
- CVEProject cvelistV5 Record: CVE-2026-140014.json
- Wiz Vulnerability Database: CVE-2026-140014
- MITRE CWE-323: Reusing a Nonce, Key Pair in Encryption
Read the full report for CVE-2026-140014 on our website for more details including interactive diagrams and full exploit analysis.
