{"id":"CVE-2024-21530","aliases":["CVE-2024-21530","GHSA-6878-6wc2-pf5h","GHSA-r2jw-c95q-rj29","RUSTSEC-2023-0068"],"related":[],"kind":"vulnerability","state":"published","title":"Sequential calls of encryption API (`encrypt`, `wrap`, and `dump`) result in nonce reuse","summary":"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.\n\n**Note:**\nThe issue does NOT affect objects created with Cocoon::new which utilizes ThreadRng.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"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.\n\n**Note:**\nThe issue does NOT affect objects created with Cocoon::new which utilizes ThreadRng.","source":"cvelist"},{"lang":"en","text":"**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).\n\n**Note**: The issue does **NOT** affect objects created with **`Cocoon::new`** which utilizes `ThreadRng`.\n\n**Cause**: `StdRng` produces the same nonce because `StdRng::clone` resets its state.\n\n**Measure**: Make encryption API mutable (`encrypt`, `wrap`, and `dump`).\n\n**Workaround**: Create a new cocoon object with a new **seed** per each encryption.\n\n## How to Reproduce\n\n```rust\nlet cocoon = MiniCocoon::from_password(b\"password\", &[1; 32]);\nlet mut data1 = \"my secret data\".to_owned().into_bytes();\nlet _ = cocoon.encrypt(&mut data1)?;\n\nlet mut data2 = \"my secret data\".to_owned().into_bytes();\nlet _ = cocoon.encrypt(&mut data2)?;\n\n// data1: [23, 217, 251, 151, 179, 62, 85, 15, 253, 92, 192, 112, 200, 52]\n// data2: [23, 217, 251, 151, 179, 62, 85, 15, 253, 92, 192, 112, 200, 52]\n```\n\n## Workaround\n\nFor `cocoon <= 0.3.3`, create a new cocoon with a different **seed** per each `encrypt`/`wrap`/`dump` call.\n\n```rust\nlet cocoon = MiniCocoon::from_password(b\"password\", &[1; 32]);\nlet mut data1 = \"my secret data\".to_owned().into_bytes();\nlet _ = cocoon.encrypt(&mut data1)?;\n\n// Another seed: &[2; 32].\nlet cocoon = MiniCocoon::from_password(b\"password\", &[2; 32]);\nlet mut data2 = \"my secret data\".to_owned().into_bytes();\nlet _ = cocoon.encrypt(&mut data2)?;\n\n// data1: [23, 217, 251, 151, 179, 62, 85, 15, 253, 92, 192, 112, 200, 52]\n// data2: [53, 223, 209, 96, 130, 99, 209, 108, 83, 189, 123, 81, 19, 1]\n```","format":"markdown","source":"ghsa"},{"lang":"en","text":"### Duplicate Advisory\nThis advisory has been withdrawn because it is a duplicate of GHSA-6878-6wc2-pf5h. This link is maintained to preserve external references.\n\n### Original Description\nVersions 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.\n\n**Note:**\nThe issue does NOT affect objects created with Cocoon::new which utilizes ThreadRng.","format":"markdown","source":"ghsa"},{"lang":"es","text":"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.","source":"nvd"}],"published":"2023-10-15T12:00:00.000Z","modified":"2026-06-17T07:09:41.230Z","severity":{"scorer":"snyk","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:H/PR:N/UI:N/S:C/C:L/I:L/A:N/E:P","score":4.5,"rating":"MEDIUM"},"severities":[{"scorer":"snyk","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:H/PR:N/UI:N/S:C/C:L/I:L/A:N/E:P","score":4.5,"rating":"MEDIUM"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:H/PR:N/UI:N/S:C/C:L/I:L/A:N","score":4.5,"rating":"MEDIUM"},{"scorer":"GitHub","scheme":"CVSS:4.0","vector":"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","rating":"MEDIUM"},{"scorer":"RustSec Advisory Database","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:H/PR:N/UI:N/S:C/C:L/I:L/A:N","score":4.5,"rating":"MEDIUM"}],"cwes":["CWE-323"],"affected":[{"ranges":[{"type":"semver","introduced":"0","fixed":"0.4.0","status":"affected"}],"product":"cocoon","source":"cvelist"},{"ranges":[{"type":"custom","introduced":"0","fixed":"0.4.0","status":"affected"}],"vendor":"cocoon","product":"cocoon","cpe":"cpe:2.3:a:cocoon:cocoon:*:*:*:*:*:*:*:*","source":"cvelist"},{"ranges":[{"type":"semver","introduced":"0","status":"affected","fixed":"0.4.0"}],"ecosystem":"crates.io","package":"cocoon","purl":"pkg:cargo/cocoon","source":"ghsa"},{"ranges":[{"type":"semver","introduced":"0","status":"affected","fixed":"0.4.0"}],"ecosystem":"crates.io","package":"cocoon","purl":"pkg:cargo/cocoon","source":"ghsa"},{"ranges":[{"type":"semver","introduced":"0.0.0-0","status":"affected","fixed":"0.4.0"}],"ecosystem":"crates.io","package":"cocoon","purl":"pkg:cargo/cocoon","source":"rustsec"}],"references":[{"url":"https://security.snyk.io/vuln/SNYK-RUST-COCOON-6028364","tags":["web"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/fadeevab/cocoon/issues/22","tags":["report","web"],"sources":["cvelist","ghsa","rustsec","nvd"]},{"url":"https://github.com/fadeevab/cocoon/commit/1b6392173ce35db4736a94b62b2d2973f9a71441","tags":["web"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://rustsec.org/advisories/RUSTSEC-2023-0068.html","tags":["advisory","web"],"sources":["cvelist","ghsa","rustsec","nvd"]},{"url":"https://github.com/advisories/GHSA-6878-6wc2-pf5h","tags":["advisory"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2024-21530","tags":["advisory"],"sources":["ghsa"]},{"url":"https://github.com/fadeevab/cocoon/commit","tags":["package"],"sources":["ghsa"]},{"url":"https://github.com/fadeevab/cocoon","tags":["package"],"sources":["ghsa"]},{"url":"https://crates.io/crates/cocoon","tags":["package"],"sources":["rustsec"]}],"credits":["Kyle Petryszak"],"assigner":"snyk","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"no","technicalImpact":"partial","date":"2024-10-02T13:38:37.583Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2024-21530","url":"https://www.cve.org/CVERecord?id=CVE-2024-21530","licence":"CVE Terms of Use","modified":"2024-10-02T13:42:12.774Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-6878-6wc2-pf5h","url":"https://github.com/advisories/GHSA-6878-6wc2-pf5h","licence":"CC-BY-4.0","modified":"2025-12-29T22:29:24.519Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-r2jw-c95q-rj29","url":"https://github.com/advisories/GHSA-r2jw-c95q-rj29","licence":"CC-BY-4.0","modified":"2025-12-29T22:29:44.035Z"},{"source":"rustsec","name":"RustSec Advisory Database","id":"RUSTSEC-2023-0068","url":"https://rustsec.org/advisories/RUSTSEC-2023-0068.html","licence":"CC0-1.0","modified":"2025-10-28T06:02:18.000Z"},{"source":"nvd","name":"NVD","id":"CVE-2024-21530","url":"https://nvd.nist.gov/vuln/detail/CVE-2024-21530","licence":"Public domain","modified":"2026-06-17T07:09:41.230Z"}],"updatedAt":"2026-11-25T22:58:45.949Z","epss":{"score":0.0014,"percentile":0.03604,"date":"2026-12-01T12:00:22.000Z"}}