RustSec logo

History ⋅ Edit ⋅ JSON (OSV)

RUSTSEC-2026-0594

Private cookie nonces can repeat in processes that fork

Reported
Issued
Package
cookie (crates.io)
Type
Vulnerability
Categories
Keywords
#nonce-reuse #aes-gcm #fork
Aliases
References
CVSS Score
6.5 MEDIUM
CVSS Details
Attack Vector
Network
Attack Complexity
High
Privileges Required
None
User Interaction
None
Scope
Unchanged
Confidentiality Impact
Low
Integrity Impact
High
Availability Impact
None
CVSS Vector
CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:H/A:N
Patched
  • >=0.18.3
Unaffected
  • <0.11.3
  • >=0.12.0, <0.14.0
Affected OSes
  • linux
  • macos
  • freebsd
  • netbsd
  • openbsd
  • dragonfly
  • solaris
  • illumos
  • android
  • ios
Affected Functions
Version
cookie::PrivateJar::add
  • >=0.11.3, <0.12.0
  • >=0.14.0, <0.18.3
cookie::PrivateJar::add_original
  • >=0.11.3, <0.12.0
  • >=0.14.0, <0.18.3

Description

Who is affected

Only applications that call fork() and then add private (encrypted) cookies on the thread that forked, in more than one of the resulting processes. This is an uncommon way to deploy a Rust web application. In particular:

The exact conditions are listed under "Conditions" below.

Description

Private cookies are sealed with AES-256-GCM using a random 96-bit nonce. Affected versions drew the nonce from rand's thread-local generator, rand::thread_rng(). That generator hands out bytes from an internal buffer and only notices that the process has forked when the buffer is refilled. A process that forks therefore continues, in both the parent and the child, from the same buffered bytes, and the private cookies sealed first on each side of the fork use the same nonces.

Impact

Reusing a nonce under the same key breaks AES-GCM. From two private cookies that share a nonce, an attacker can:

The nonce is the first 12 bytes of a private cookie's (base64-decoded) value, so a repeated nonce is visible to anyone who holds two such cookies.

Exploitation requires the uncommon deployment described above, and only the first private cookies added after a fork are affected: at most 21 per process. An attacker must obtain two of them, from two different processes.

Conditions

All of the following must hold:

  1. The target is a Unix-like system and the process calls fork() without a subsequent exec().
  2. The thread that calls fork() used rand::thread_rng() at any point before the fork. Any use counts, including Key::generate(), adding a private cookie, or a call made by an unrelated crate.
  3. After the fork, private cookies are added on that same thread in two or more of the resulting processes: the parent and a child, or several children.
  4. Those processes use the same Key.

When they hold, at most the first 21 private cookies added on that thread in each process share nonces. After that the generator reseeds and the processes diverge.

The following are not affected:

Rocket and axum

Rocket and axum were tested with cookie 0.18.2 by collecting the private cookies sent by each server process and comparing their nonces.

Rocket (0.5.4, CookieJar::add_private()) is not affected. Rocket does not fork, and it handles requests on worker threads of a runtime it creates when launched. No nonce was reused:

axum (0.8.9, with PrivateCookieJar from axum-extra 0.12.6) is not affected as normally run. No nonce was reused:

An axum application is affected only if it does all of the following:

  1. forks worker processes itself,
  2. runs each worker on a current-thread runtime on the thread that forked, so that requests are handled on that thread, and
  3. used rand::thread_rng() on that thread before forking.

In that configuration, the first private cookies sent by two workers reused nonces: 19 when the parent had added one private cookie before forking, and 15 when the parent had only called Key::generate(). No nonce was reused when the parent did neither.

Other frameworks and libraries that use this crate's PrivateJar were not tested. The conditions above apply to them as well.

Fix

Version 0.18.3 obtains nonces directly from the operating system's random number generator, which is not affected by fork.

Workarounds

If upgrading is not possible, any one of the following prevents the reuse:

Applications that ran in an affected configuration should rotate their Key.

Advisory available under CC0-1.0 license.