{"id":"GHSA-6878-6wc2-pf5h","summary":"Sequential calls of encryption API (`encrypt`, `wrap`, and `dump`) result in nonce reuse","details":"**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 \u003c= 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```","aliases":["CVE-2024-21530","GHSA-r2jw-c95q-rj29","RUSTSEC-2023-0068"],"modified":"2025-12-29T22:29:24.519932Z","published":"2023-10-24T19:22:26Z","database_specific":{"severity":"MODERATE","github_reviewed":true,"github_reviewed_at":"2023-10-24T19:22:26Z","nvd_published_at":null,"cwe_ids":[]},"references":[{"type":"ADVISORY","url":"https://nvd.nist.gov/vuln/detail/CVE-2024-21530"},{"type":"WEB","url":"https://github.com/fadeevab/cocoon/issues/22"},{"type":"WEB","url":"https://github.com/fadeevab/cocoon/commit/1b6392173ce35db4736a94b62b2d2973f9a71441"},{"type":"PACKAGE","url":"https://github.com/fadeevab/cocoon/commit"},{"type":"WEB","url":"https://rustsec.org/advisories/RUSTSEC-2023-0068.html"},{"type":"WEB","url":"https://security.snyk.io/vuln/SNYK-RUST-COCOON-6028364"}],"affected":[{"package":{"name":"cocoon","ecosystem":"crates.io","purl":"pkg:cargo/cocoon"},"ranges":[{"type":"SEMVER","events":[{"introduced":"0"},{"fixed":"0.4.0"}]}],"database_specific":{"source":"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2023/10/GHSA-6878-6wc2-pf5h/GHSA-6878-6wc2-pf5h.json"}}],"schema_version":"1.9.0","severity":[{"type":"CVSS_V3","score":"CVSS:3.1/AV:L/AC:H/PR:N/UI:N/S:C/C:L/I:L/A:N"}]}