Ecosyste.ms: Advisories
An open API service providing security vulnerability metadata for many open source software ecosystems.
Security Advisories: GSA_kwCzR0hTQS02ODc4LTZ3YzItcGY1aM4AA2oU
Sequential calls of encryption API (`encrypt`, `wrap`, and `dump`) result in nonce reuse
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]
Permalink: https://github.com/advisories/GHSA-6878-6wc2-pf5hJSON: https://advisories.ecosyste.ms/api/v1/advisories/GSA_kwCzR0hTQS02ODc4LTZ3YzItcGY1aM4AA2oU
Source: GitHub Advisory Database
Origin: Unspecified
Severity: Moderate
Classification: General
Published: about 1 year ago
Updated: about 1 year ago
CVSS Score: 4.5
CVSS vector: CVSS:3.1/AV:L/AC:H/PR:N/UI:N/S:C/C:L/I:L/A:N
Identifiers: GHSA-6878-6wc2-pf5h
References:
- https://github.com/fadeevab/cocoon/issues/22
- https://github.com/fadeevab/cocoon/commit/1b6392173ce35db4736a94b62b2d2973f9a71441
- https://rustsec.org/advisories/RUSTSEC-2023-0068.html
- https://github.com/advisories/GHSA-6878-6wc2-pf5h
Blast Radius: 3.8
Affected Packages
cargo:cocoon
Dependent packages: 5Dependent repositories: 7
Downloads: 82,446 total
Affected Version Ranges: < 0.4.0
Fixed in: 0.4.0
All affected versions: 0.1.0, 0.1.1, 0.1.2, 0.1.3, 0.1.4, 0.1.5, 0.1.6, 0.1.7, 0.1.8, 0.1.9, 0.1.10, 0.1.11, 0.2.1, 0.2.2, 0.2.3, 0.2.4, 0.2.5, 0.3.0, 0.3.1, 0.3.2, 0.3.3
All unaffected versions: 0.4.0, 0.4.1, 0.4.2, 0.4.3