CVE-2024-21530: Cocoon Sequential Calls Of Encryption API Vulnerability

MODERATE
Advisory Identifier: GHSA-6878-6wc2-pf5h
CVSS 4.5
Published
Advisory Summary

CVE-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

CVE Identifier CVE-2024-21530
GHSA Identifier GHSA-6878-6wc2-pf5h
Severity MODERATE
CVSS v3.1 Base Score 4.5
CWE Classification General Security Weakness
Affected Product Cocoon
Package Ecosystem crates.io
Published Date
Last Updated

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).

Attack Vector Local (AV:L)
Attack Complexity High (AC:H)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Changed (S:C)
Confidentiality Low (C:L)
Integrity Low (I:L)
Availability None (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.

cocoon fixed: 0.4.0
Upgrade cocoon to 0.4.0
Verify Direct and Transitive Dependencies

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

**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 ```rust 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. ```rust 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] ```

CVE-2024-21530 Affected Cocoon Versions

1 component(s)
Fixed Versions:
0.4.0
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?
CVE-2024-21530 is a security vulnerability in Cocoon involving Sequential calls of encryption API (`encrypt`, `wrap`, and `dump`) result in nonce reuse under General Security Weakness.
Which Cocoon versions are affected?
Affected versions include releases prior to 0.4.0 across affected packages: cocoon.
What version fixes CVE-2024-21530?
Upgrading to 0.4.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is cocoon affected?
Yes, cocoon is affected in releases prior to 0.4.0. Upgrade your dependency to 0.4.0 or later.
What is the CVSS score of CVE-2024-21530?
CVE-2024-21530 has a CVSS v3.1 base score of 4.5 (MODERATE) with vector string CVSS:3.1/AV:L/AC:H/PR:N/UI:N/S:C/C:L/I:L/A:N.
What CWE is associated with CVE-2024-21530?
CVE-2024-21530 is classified under General Security Weakness.
How can I check crates.io dependencies for CVE-2024-21530?
Run the dependency tree command: 'inspect dependencies for cocoon'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "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
  }
}