Email me

Rust advisories / cocoon

Vulnerability MediumRUSTSEC-2023-0068 · cocoon

RUSTSEC-2023-0068: Sequential calls of encryption API (`encrypt`, `wrap`, and `dump`) result in nonce reuse

Short answerA security vulnerability in the cocoon crate: Sequential calls of encryption API (`encrypt`, `wrap`, and `dump`) result in nonce reuse. Medium severity (CVSS 4.5). Fixed in 0.4.0: update to a fixed version.

Cratecocoon
TypeVulnerability (crypto-failure)
Affected versionsBefore 0.4.0.
Fixed in0.4.0
SeverityMedium, CVSS 4.5
CVSS:3.1/AV:L/AC:H/PR:N/UI:N/S:C/C:L/I:L/A:N
Published2023-10-15
Last changed2025-10-28
Also known asCVE-2024-21530, GHSA-6878-6wc2-pf5h, GHSA-r2jw-c95q-rj29
Affected functionscocoon::Cocoon::dump, cocoon::Cocoon::encrypt, cocoon::Cocoon::wrap, cocoon::MiniCocoon::dump, cocoon::MiniCocoon::encrypt, cocoon::MiniCocoon::wrap

What to do

  1. See which version you have: cargo tree -i cocoon (it also shows which of your dependencies pulls it in).
  2. Update within your version requirement: cargo update -p cocoon. If the fix is a newer major or minor than your requirement allows, raise it in Cargo.toml (for example cocoon = "0.4.0") or update the dependency that pulls it in.
  3. Check again with cargo audit, or paste your Cargo.lock into our Cargo.toml checker.

Details from the advisory

**Problem**: Trying to create a new encrypted message with the same cocoon object generates the same ciphertext. It mostly affects MiniCocoon and Cocoon objects with custom seeds and RNGs (where StdRng is used under the hood).

**Note**: The issue does **NOT** affect objects created with **Cocoon::new** which utilizes ThreadRng.

**Cause**: StdRng produces the same nonce because StdRng::clone resets its state.

**Measure**: Make encryption API mutable (encrypt, wrap, and dump).

**Workaround**: Create a new cocoon object with a new **seed** per each encryption.

How to Reproduce

let cocoon = MiniCocoon::from_password(b"password", &[1; 32]);
let mut data1 = "my secret data".to_owned().into_bytes();
let _ = cocoon.encrypt(&mut data1)?;

let mut data2 = "my secret data".to_owned().into_bytes();
let _ = cocoon.encrypt(&mut data2)?;

// data1: [23, 217, 251, 151, 179, 62, 85, 15, 253, 92, 192, 112, 200, 52]
// data2: [23, 217, 251, 151, 179, 62, 85, 15, 253, 92, 192, 112, 200, 52]

Workaround

For cocoon <= 0.3.3, create a new cocoon with a different **seed** per each encrypt/wrap/dump call.

let cocoon = MiniCocoon::from_password(b"password", &[1; 32]);
let mut data1 = "my secret data".to_owned().into_bytes();
let _ = cocoon.encrypt(&mut data1)?;

// Another seed: &[2; 32].
let cocoon = MiniCocoon::from_password(b"password", &[2; 32]);
let mut data2 = "my secret data".to_owned().into_bytes();
let _ = cocoon.encrypt(&mut data2)?;

// data1: [23, 217, 251, 151, 179, 62, 85, 15, 253, 92, 192, 112, 200, 52]
// data2: [53, 223, 209, 96, 130, 99, 209, 108, 83, 189, 123, 81, 19, 1]

References

From the RustSec Advisory Database (CC0-1.0) via the OSV export, downloaded Oct 24, 2026. Severity score computed from the published CVSS vector.

Up next

Are you affected?Check your whole dependency treePaste Cargo.lock: every advisory, for your exact versions.Read it next →

Did this answer your question?

Get the receipts by email.

What my AI agents tried this week, with the real numbers: what worked, what flopped, what made money. One email when there is something worth reading.

No spam, never sold. Every email has a one-click unsubscribe.

Popular in the shop

All 124 tools →

Browse: Bundles and kitsHome, family and schoolMoney and businessAI toolsSports and fitnessMaking and hobbiesFood and drinkIndie dev and launchTrading and quant

Free: Landing page teardown iPhone app cost calculator LLM API cost calculator Paid online: $49 Launch Check App builds Articles FAQ