Vulnerabilities in pkg:npm/@dfinity/auth-client

PACKAGE
Advisory Identifier: GHSA-c9vv-fhgv-cjc3
Advisory Summary

CVE-2024-1631 is a CRITICAL (CVSS 9.1) insecure key generation vulnerability (CWE-321: Use of Hard-coded Cryptographic Key) affecting agent-js libraries in the npm ecosystem. The issue involves insecure key generation in `ed25519keyidentity.generate`. Remediation is available by upgrading affected packages to version 1.0.1.

1 Known Advisory Record(s)
Package Vulnerability Intelligence

pkg:npm/@dfinity/auth-client

1 Known Advisory Record(s)

Vulnerability advisories affecting package pkg:npm/@dfinity/auth-client. Select an advisory below to view technical details or fixes.

Advisory ID CVE / NVD Severity Summary
GHSA-c9vv-fhgv-cjc3 CVE-2024-1631 CRITICAL agent-js: Insecure Key Generation in `Ed25519KeyIdentity.generate`

CVE-2024-1631 at a Glance

CVE Identifier CVE-2024-1631
GHSA Identifier GHSA-c9vv-fhgv-cjc3
Severity CRITICAL
CVSS v3.1 Base Score 9.1
CWE Classification CWE-321: Use of Hard-coded Cryptographic Key
Affected Product agent-js
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 9.1

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity High (I:H)
Availability None (A:N)

How to Fix CVE-2024-1631

To remediate this vulnerability, upgrade all affected agent-js dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

@dfinity/identity fixed: 1.0.1
npm install @dfinity/identity@1.0.1
@dfinity/auth-client fixed: 1.0.1
npm install @dfinity/auth-client@1.0.1
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

npm ls @dfinity/identity

How to Check if You Are Affected

To determine whether your Node.js application is affected by CVE-2024-1631, inspect your project dependencies using npm:

npm ls @dfinity/identity

Analyze the terminal output to locate any version of agent-js in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 1.0.1), your application is affected.

Note: The npm ls @dfinity/identity command inspects dependencies declared in your package.json and lockfile; it does not perform automated runtime dynamic scanning.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-321: Use of Hard-coded Cryptographic Key, where the product uses a hard-coded, unchangeable cryptographic key. In agent-js, 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

## 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. Users are asked to take proactive measures mentioned below in Workarounds:Users to protect their assets. ## Patches Patch for the vulnerability is **available in v1.0.1** for all the packages listed in the advisory. Please upgrade and deploy your canisters immediately. ## Workarounds ### Developers The recommended fix is to upgrade the package to the patched version. If that is not possible, there are couple of workarounds to handle the insecure key generation. 1. Invoking the function as `Ed25519KeyIdentity.generate(null)` would fix the broken conditional evaluation and force the function to generate a securely random seed. However, this is not guaranteed to work for future upgrades. 2. Passing a securely generated randomness as a seed to `Ed25519KeyIdentity.generate` would force the library to use it as the seed to generate the key pair. ### Users #### Removing a controller of a canister if it's the affected principal For all canisters you control, fetch the controllers of the canisters using ```sh dfx canister info --ic <CANISTER> ``` If you see the principal `535yc-uxytb-gfk7h-tny7p-vjkoe-i4krp-3qmcl-uqfgr-cpgej-yqtjq-rqe` as one of the controllers, follow the steps below ```sh dfx identity whoami # record CURRENT_IDENTITY dfx identity new <NEW_IDENTITY_NAME> dfx identity use <NEW_IDENTITY_NAME> dfx identity get-principal <NEW_IDENTITY_NAME> # record NEW_IDENTITY_PRINCIPAL dfx identity use <CURRENT_IDENTITY> dfx canister update-settings --ic <CANISTER> --add-controller <NEW_IDENTITY_PRINCIPAL> dfx canister update-settings --ic <CANISTER> --remove-controller `535yc-uxytb-gfk7h-tny7p-vjkoe-i4krp-3qmcl-uqfgr-cpgej-yqtjq-rqe` ``` For more details on canister management, please visit [here](https://internetcomputer.org/docs/current/tutorials/developer-journey/level-1/1.6-managing-canisters) #### Checking funds on wallets / ledgers If you have funds on ledgers using a browser wallet, please check if the account principal matches `535yc-uxytb-gfk7h-tny7p-vjkoe-i4krp-3qmcl-uqfgr-cpgej-yqtjq-rqe`. If it does, please create a new account and transfer the funds to the new account immediately. ## References 1. [fix PR link](https://github.com/dfinity/agent-js/pull/851) 2. [NPM patched version](https://www.npmjs.com/package/@dfinity/identity/v/1.0.1) 3. [agent-js Github repo](https://github.com/dfinity/agent-js) 4. [agent-js docs](https://agent-js.icp.xyz/identity/index.html)

CVE-2024-1631 Affected agent-js Versions

2 component(s)
Fixed Versions:
1.0.1
Product / Package Ecosystem Affected Versions Fixed Version
@dfinity/identity
npm
≥ 0.20.0-beta.0
< 1.0.1
1.0.1
@dfinity/auth-client
npm
≥ 0.20.0-beta.0
< 1.0.1
1.0.1

References

Frequently Asked Questions

What is CVE-2024-1631?
CVE-2024-1631 is a security vulnerability in agent-js involving Insecure Key Generation in `Ed25519KeyIdentity.generate` under CWE-321: Use of Hard-coded Cryptographic Key.
Which agent-js versions are affected?
Affected versions include releases prior to 1.0.1 across affected packages: @dfinity/identity, @dfinity/auth-client.
What version fixes CVE-2024-1631?
Upgrading to 1.0.1 (or the latest patched release for your respective branch) resolves the vulnerability.
Is @dfinity/identity affected?
Yes, @dfinity/identity is affected in releases prior to 1.0.1. Upgrade your dependency to 1.0.1 or later.
Is @dfinity/auth-client affected?
Yes, @dfinity/auth-client is affected in releases prior to 1.0.1. Upgrade your dependency to 1.0.1 or later.
What is the CVSS score of CVE-2024-1631?
CVE-2024-1631 has a CVSS v3.1 base score of 9.1 (CRITICAL) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N.
What CWE is associated with CVE-2024-1631?
CVE-2024-1631 is classified under CWE-321: Use of Hard-coded Cryptographic Key (The product uses a hard-coded, unchangeable cryptographic key.).
How can I check npm dependencies for CVE-2024-1631?
Run the dependency tree command: 'npm ls @dfinity/identity'. 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-c9vv-fhgv-cjc3",
  "modified" : "2024-02-21T18:57:59Z",
  "published" : "2024-02-21T02:54:56Z",
  "aliases" : [ "CVE-2024-1631" ],
  "summary" : "agent-js: Insecure Key Generation in `Ed25519KeyIdentity.generate`",
  "details" : "## Impact\n\nThe 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**.\n\nSince 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. Users are asked to take proactive measures mentioned below in Workarounds:Users to protect their assets. \n\n## Patches\nPatch for the vulnerability is **available in v1.0.1** for all the packages listed in the advisory. Please upgrade and deploy your canisters immediately. \n\n## Workarounds\n\n### Developers\n\nThe recommended fix is to upgrade the package to the patched version. If that is not possible, there are couple of workarounds to handle the insecure key generation.\n\n1. Invoking the function as `Ed25519KeyIdentity.generate(null)` would fix the broken conditional evaluation and force the function to generate a securely random seed. However, this is not guaranteed to work for future upgrades.\n2. Passing a securely generated randomness as a seed to `Ed25519KeyIdentity.generate` would force the library to use it as the seed to generate the key pair.\n\n### Users\n\n#### Removing a controller of a canister if it's the affected principal\n\nFor all canisters you control, fetch the controllers of the canisters using \n```sh\ndfx canister info --ic <CANISTER>\n```\nIf you see the principal `535yc-uxytb-gfk7h-tny7p-vjkoe-i4krp-3qmcl-uqfgr-cpgej-yqtjq-rqe` as one of the controllers, follow the steps below \n```sh\ndfx identity whoami # record CURRENT_IDENTITY\n\ndfx identity new <NEW_IDENTITY_NAME> \ndfx identity use <NEW_IDENTITY_NAME> \ndfx identity get-principal <NEW_IDENTITY_NAME> # record NEW_IDENTITY_PRINCIPAL\n\ndfx identity use <CURRENT_IDENTITY>\ndfx canister update-settings --ic <CANISTER> --add-controller <NEW_IDENTITY_PRINCIPAL>\ndfx canister update-settings --ic <CANISTER> --remove-controller `535yc-uxytb-gfk7h-tny7p-vjkoe-i4krp-3qmcl-uqfgr-cpgej-yqtjq-rqe`\n```\nFor more details on canister management, please visit [here](https://internetcomputer.org/docs/current/tutorials/developer-journey/level-1/1.6-managing-canisters)\n\n#### Checking funds on wallets /  ledgers\n\nIf you have funds on ledgers using a browser wallet, please check if the account principal matches `535yc-uxytb-gfk7h-tny7p-vjkoe-i4krp-3qmcl-uqfgr-cpgej-yqtjq-rqe`. If it does, please create a new account and transfer the funds to the new account immediately.\n\n## References\n\n1. [fix PR link](https://github.com/dfinity/agent-js/pull/851)\n2. [NPM patched version](https://www.npmjs.com/package/@dfinity/identity/v/1.0.1)\n3. [agent-js Github repo](https://github.com/dfinity/agent-js)\n4. [agent-js docs](https://agent-js.icp.xyz/identity/index.html)\n\n",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "@dfinity/identity"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0.20.0-beta.0"
      }, {
        "fixed" : "1.0.1"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "npm",
      "name" : "@dfinity/auth-client"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0.20.0-beta.0"
      }, {
        "fixed" : "1.0.1"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/dfinity/agent-js/security/advisories/GHSA-c9vv-fhgv-cjc3"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-1631"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/dfinity/agent-js/pull/851"
  }, {
    "type" : "WEB",
    "url" : "https://agent-js.icp.xyz/identity/index.html"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/dfinity/agent-js"
  }, {
    "type" : "WEB",
    "url" : "https://www.npmjs.com/package/@dfinity/identity/v/1.0.1"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-321", "CWE-330" ],
    "severity" : "CRITICAL",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-02-21T02:54:56Z",
    "nvd_published_at" : "2024-02-21T03:15:08Z"
  }
}