# CVE-2024-1631: agent-js: Insecure Key Generation in `Ed25519KeyIdentity.generate`

> Insecure key generation in agent-js allows attackers to compromise private keys, leading to loss of funds or canister control.

- **Severity:** Critical 9.1 (`CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N`)
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 21 Feb 2024
- **Updated:** 16 Aug 2024
- **Also known as:** CVE-2024-27084, GHSA-c9vv-fhgv-cjc3

## What is CVE-2024-1631?

CVE-2024-1631 is a critical vulnerability in Internet Computer agent-js, published on 21 Feb 2024. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

Impact: The library offers a function to generate an ed25519 key pair via Ed25519KeyIdentity.generate with an optional param to provide a 32 byte seed value, which will then be used as the secret key. When no seed value is provided, it is expected that the library generates the secret key using secure randomness. However, a recent change broke this guarantee and uses an insecure seed for key pair generation. Since the private key of this identity (535yc-uxytb-gfk7h-tny7p-vjkoe-i4krp-3qmcl-uqfgr-cpgej-yqtjq-rqe) is compromised, one could lose funds associated with the principal on ledgers or lose access to a canister where this principal is the controller.

Weakness: CWE-330 (Use of Insufficiently Random Values), CWE-321 (Use of Hard-coded Cryptographic Key)

## Which versions are affected by CVE-2024-1631?

4 open source packages ship an affected version, including @dfinity/auth-client and @dfinity/identity. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `@dfinity/auth-client` | npm | From 0.20.0-beta.0 | 1.0.1 |
| `@dfinity/auth-client` | npm | From 0.20.0-beta.0 | 1.0.1 |
| `@dfinity/identity` | npm | From 0.20.0-beta.0 | 1.0.1 |
| `@dfinity/identity` | npm | From 0.20.0-beta.0 | 1.0.1 |

Products: Dfinity Icp-Js-Core.

## How do I fix CVE-2024-1631?

Upgrade @dfinity/auth-client to 1.0.1 or later.

## Is CVE-2024-1631 being exploited?

There is no known exploitation of CVE-2024-1631 in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2024-1631 and fix it if it is affected.

What it is: CVE-2024-1631 is a critical vulnerability in Internet Computer agent-js, published on 21 Feb 2024. An attacker can exploit it over the internet without logging in, with no action from the victim.
Exploitation: There is no known exploitation of CVE-2024-1631 in the wild and no public exploit code.

Affected packages and fixed versions:
- @dfinity/auth-client (npm): affected from 0.20.0-beta.0; fixed in 1.0.1
- @dfinity/auth-client (npm): affected from 0.20.0-beta.0; fixed in 1.0.1
- @dfinity/identity (npm): affected from 0.20.0-beta.0; fixed in 1.0.1
- @dfinity/identity (npm): affected from 0.20.0-beta.0; fixed in 1.0.1

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/CVE-2024-1631/ (Markdown: https://insights.sbomify.com/CVE-2024-1631/index.md)
```

## Sources

- CVE record: https://www.cve.org/CVERecord?id=CVE-2024-1631
- NVD: https://nvd.nist.gov/vuln/detail/CVE-2024-1631
- OSV: https://osv.dev/vulnerability/CVE-2024-1631

---
From sbomify Insights: https://insights.sbomify.com/CVE-2024-1631/
Summaries are generated and may contain mistakes; the official description above is the record.
