CVE-2024-21530: Cocoon Sequential Calls Of Encryption API Vulnerability
MODERATECVE-2024-21530 is a MODERATE (CVSS 4.5) sequential calls of encryption api vulnerability (General Security Weakness) affecting Cocoon libraries in the crates.io ecosystem. The issue involves sequential calls of encryption api (`encrypt`, `wrap`, and `dump`) result in nonce reuse. Remediation is available by upgrading affected packages to version 0.4.0.
CVE-2024-21530 at a Glance
Security Impact
CVSS: 4.5
The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:L/AC:H/PR:N/UI:N/S:C/C:L/I:L/A:N).
How to Fix CVE-2024-21530
To remediate this vulnerability, upgrade all affected Cocoon dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.
Upgrade cocoon to 0.4.0
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
inspect dependencies for cocoon
How to Check if You Are Affected
To determine whether your application is affected by CVE-2024-21530, inspect your project dependencies for Cocoon:
inspect dependencies for cocoon
Analyze the terminal output to locate any version of Cocoon in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 0.4.0), your application is affected.
Note: Verify declared build manifests and deployed runtime container environments.
Technical Details
Vulnerability Mechanism & Technical Analysis
This vulnerability is classified under General Security Weakness. In Cocoon, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.
Source Advisory Statement
CVE-2024-21530 Affected Cocoon Versions
1 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
cocoon
|
crates.io |
< 0.4.0
|
0.4.0
|
References
Frequently Asked Questions
What is CVE-2024-21530?
Which Cocoon versions are affected?
What version fixes CVE-2024-21530?
Is cocoon affected?
What is the CVSS score of CVE-2024-21530?
What CWE is associated with CVE-2024-21530?
How can I check crates.io dependencies for CVE-2024-21530?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-6878-6wc2-pf5h",
"modified" : "2025-12-29T22:23:46Z",
"published" : "2023-10-24T19:22:26Z",
"aliases" : [ "CVE-2024-21530" ],
"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 <= 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```",
"severity" : [ {
"type" : "CVSS_V3",
"score" : "CVSS:3.1/AV:L/AC:H/PR:N/UI:N/S:C/C:L/I:L/A:N"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "crates.io",
"name" : "cocoon"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0"
}, {
"fixed" : "0.4.0"
} ]
} ]
} ],
"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"
} ],
"database_specific" : {
"cwe_ids" : [ ],
"severity" : "MODERATE",
"github_reviewed" : true,
"github_reviewed_at" : "2023-10-24T19:22:26Z",
"nvd_published_at" : null
}
}