4.5medium
Sequential calls of encryption API (`encrypt`, `wrap`, and `dump`) result in nonce reuse
- Severity
- 4.5medium CVSS:3.1 by snyk
- Exploit likelihood
- 0.14% (higher than 3% of CVEs; EPSS, by FIRST)
- Published
- Last changed
- Assigned by
- snyk
- Also known as
- GHSA-6878-6wc2-pf5hGHSA-r2jw-c95q-rj29RUSTSEC-2023-0068
Description
Versions of the package cocoon before 0.4.0 are vulnerable to Reusing a Nonce, Key Pair in Encryption when the encrypt, wrap, and dump functions are sequentially called. An attacker can generate the same ciphertext by creating a new encrypted message with the same cocoon object. **Note:** The issue does NOT affect objects created with Cocoon::new which utilizes ThreadRng.
Affected
| Product or package | Versions | Reported by |
|---|---|---|
| cocoon | before 0.4.0 | CVE List |
| cocoon cocoon | before 0.4.0 | CVE List |
| cocoon (crates.io) | before 0.4.0, from 0.0.0-0 before 0.4.0 | GitHub Advisory Database, RustSec Advisory Database |
All scores
| snyk | 4.5medium CVSS:3.1 | CVSS:3.1/AV:L/AC:H/PR:N/UI:N/S:C/C:L/I:L/A:N/E:P |
| GitHub | 4.5medium CVSS:3.1 | CVSS:3.1/AV:L/AC:H/PR:N/UI:N/S:C/C:L/I:L/A:N |
| GitHub | medium CVSS:4.0 | CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:N/VI:N/VA:N/SC:L/SI:L/SA:N |
| RustSec Advisory Database | 4.5medium CVSS:3.1 | CVSS:3.1/AV:L/AC:H/PR:N/UI:N/S:C/C:L/I:L/A:N |
Classification
SSVC (CISA-ADP): exploitation poc, automatable no, technical impact partial.
What each source says
CVE List
Versions of the package cocoon before 0.4.0 are vulnerable to Reusing a Nonce, Key Pair in Encryption when the encrypt, wrap, and dump functions are sequentially called. An attacker can generate the same ciphertext by creating a new encrypted message with the same cocoon object. **Note:** The issue does NOT affect objects created with Cocoon::new which utilizes ThreadRng.
GitHub Advisory Database
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]
GitHub Advisory Database
Duplicate Advisory
This advisory has been withdrawn because it is a duplicate of GHSA-6878-6wc2-pf5h. This link is maintained to preserve external references.
Original Description
Versions of the package cocoon before 0.4.0 are vulnerable to Reusing a Nonce, Key Pair in Encryption when the encrypt, wrap, and dump functions are sequentially called. An attacker can generate the same ciphertext by creating a new encrypted message with the same cocoon object.
Note: The issue does NOT affect objects created with Cocoon::new which utilizes ThreadRng.
NVD (es)
Las versiones del paquete cocoon anteriores a la 0.4.0 son vulnerables a la reutilización de un par de claves nonce en el cifrado cuando se invocan secuencialmente las funciones de cifrado, envoltura y volcado. Un atacante puede generar el mismo texto cifrado creando un nuevo mensaje cifrado con el mismo objeto cocoon. **Nota:** El problema NO afecta a los objetos creados con Cocoon::new, que utiliza ThreadRng.
References
Sources
| Source | Record | Licence |
|---|---|---|
| CVE List | CVE-2024-21530 changed 2024-10-02 | CVE Terms of Use |
| GitHub Advisory Database | GHSA-6878-6wc2-pf5h changed 2025-12-29 | CC-BY-4.0 |
| GitHub Advisory Database | GHSA-r2jw-c95q-rj29 changed 2025-12-29 | CC-BY-4.0 |
| RustSec Advisory Database | RUSTSEC-2023-0068 changed 2025-10-28 | CC0-1.0 |
| NVD | CVE-2024-21530 changed 2026-06-17 | Public domain |