CVE-2023-38698: @ensdomains/ens contracts .eth Registrar Controller Can Shorten Vulnerability

MODERATE
Advisory Identifier: GHSA-rrxv-q8m4-wch3
CVSS 4.9
CWE-190
Published
Advisory Summary

CVE-2023-38698 is a MODERATE (CVSS 4.9) .eth registrar controller can shorten vulnerability (CWE-190: Integer Overflow or Wraparound) affecting @ensdomains/ens contracts libraries in the npm ecosystem. The issue involves .eth registrar controller can shorten the duration of registered names. Remediation is available by upgrading affected packages to version 0.0.22.

CVE-2023-38698 at a Glance

CVE Identifier CVE-2023-38698
GHSA Identifier GHSA-rrxv-q8m4-wch3
Severity MODERATE
CVSS v3.1 Base Score 4.9
CWE Classification CWE-190: Integer Overflow or Wraparound
Affected Product @ensdomains/ens contracts
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 4.9

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

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

How to Fix CVE-2023-38698

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

@ensdomains/ens-contracts fixed: 0.0.22
npm install @ensdomains/ens-contracts@0.0.22
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 @ensdomains/ens-contracts

How to Check if You Are Affected

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

npm ls @ensdomains/ens-contracts

Analyze the terminal output to locate any version of @ensdomains/ens contracts in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 0.0.22), your application is affected.

Note: The npm ls @ensdomains/ens-contracts 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-190: Integer Overflow or Wraparound, where the product performs a calculation that can produce an integer overflow or wraparound when the logic assumes that the resulting value will always be larger than the original value. this occurs when an integer value is incremented to a value that is too large to store in the associated representation. when this occurs, the value may become a very small or negative number. In @ensdomains/ens contracts, 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

### Description According to the documentation, controllers are allowed to register new domains and extend the expiry of existing domains, but they cannot change the ownership or reduce the expiration time of existing domains. However, a preliminary analysis suggests that an attacker-controlled controller may be able to reduce the expiration time of existing domains due to an integer overflow in the renew function. The vulnerability resides in the following GitHub repository: https://github.com/ensdomains/ens-contracts/blob/master/contracts/ethregistrar/BaseRegistrarImplementation.sol#L171 The vulnerable line of code is: ```js require( expiries[id] + duration + GRACE_PERIOD > duration + GRACE_PERIOD ); // Prevent future overflow ``` In this code snippet, the `duration` variable is user-supplied, making it possible to provide a value that would cause an overflow on both sides of the '>' expression, ultimately rendering the condition true. Specifically, when the duration is set to `2^256 - GRACE_PERIOD`, the subsequent line `expiries[id] += duration;` also experiences an overflow, as `expiries[id]` is greater than `GRACE_PERIOD`. This results in the reduction of `expiries[id]` by `GRACE_PERIOD`. By repeatedly calling the renew function, an attacker could potentially force the expiration of an ENS record. You can find the PoC included in the attached document. To execute the test, please use the following command: ``` forge test -vvv --match-contract RegistrarExploit --fork-url <alchemy_url> ``` Replace `<alchemy_url>` with your Alchemy API URL. This command will run the Foundry test file and demonstrate the potential vulnerability. ### Impact If successfully exploited, this vulnerability would enable attackers to force the expiration of any ENS record, ultimately allowing them to claim the affected domains for themselves. Currently, it would require a malicious DAO to exploit it. Nevertheless, any vulnerability present in the controllers could potentially render this issue exploitable in the future. An additional concern is the possibility of renewal discounts. Should ENS decide to implement a system that offers unlimited .eth domains for a fixed fee in the future, the vulnerability could become exploitable by any user due to the reduced attack cost. ### Patches A mitigation is being developed. ### Workarounds As long as registration cost remains linear or superlinear based on registration duration, or limited to a reasonable maximum (eg, 1 million years), this vulnerability could only be exploited by a malicious DAO. The interim workaround is thus to take no action.

CVE-2023-38698 Affected @ensdomains/ens contracts Versions

1 component(s)
Fixed Versions:
0.0.22
Product / Package Ecosystem Affected Versions Fixed Version
@ensdomains/ens-contracts
npm
< 0.0.22
0.0.22

References

Frequently Asked Questions

What is CVE-2023-38698?
CVE-2023-38698 is a security vulnerability in @ensdomains/ens contracts involving .eth registrar controller can shorten the duration of registered names under CWE-190: Integer Overflow or Wraparound.
Which @ensdomains/ens contracts versions are affected?
Affected versions include releases prior to 0.0.22 across affected packages: @ensdomains/ens-contracts.
What version fixes CVE-2023-38698?
Upgrading to 0.0.22 (or the latest patched release for your respective branch) resolves the vulnerability.
Is @ensdomains/ens-contracts affected?
Yes, @ensdomains/ens-contracts is affected in releases prior to 0.0.22. Upgrade your dependency to 0.0.22 or later.
What is the CVSS score of CVE-2023-38698?
CVE-2023-38698 has a CVSS v3.1 base score of 4.9 (MODERATE) with vector string CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:U/C:N/I:H/A:N.
What CWE is associated with CVE-2023-38698?
CVE-2023-38698 is classified under CWE-190: Integer Overflow or Wraparound (The product performs a calculation that can produce an integer overflow or wraparound when the logic assumes that the resulting value will always be larger than the original value. This occurs when an integer value is incremented to a value that is too large to store in the associated representation. When this occurs, the value may become a very small or negative number.).
How can I check npm dependencies for CVE-2023-38698?
Run the dependency tree command: 'npm ls @ensdomains/ens-contracts'. 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-rrxv-q8m4-wch3",
  "modified" : "2023-08-10T22:10:22Z",
  "published" : "2023-08-01T19:48:31Z",
  "aliases" : [ "CVE-2023-38698" ],
  "summary" : ".eth registrar controller can shorten the duration of registered names",
  "details" : "### Description\nAccording to the documentation, controllers are allowed to register new domains and extend the expiry of existing domains, but they cannot change the ownership or reduce the expiration time of existing domains. However, a preliminary analysis suggests that an attacker-controlled controller may be able to reduce the expiration time of existing domains due to an integer overflow in the renew function.\n\nThe vulnerability resides in the following GitHub repository: https://github.com/ensdomains/ens-contracts/blob/master/contracts/ethregistrar/BaseRegistrarImplementation.sol#L171 \n\nThe vulnerable line of code is:\n```js\nrequire(\n            expiries[id] + duration + GRACE_PERIOD > duration + GRACE_PERIOD\n        ); // Prevent future overflow\n```\n\nIn this code snippet, the `duration` variable is user-supplied, making it possible to provide a value that would cause an overflow on both sides of the '>' expression, ultimately rendering the condition true. Specifically, when the duration is set to `2^256 - GRACE_PERIOD`, the subsequent line `expiries[id] += duration;` also experiences an overflow, as `expiries[id]` is greater than `GRACE_PERIOD`. This results in the reduction of `expiries[id]` by `GRACE_PERIOD`. By repeatedly calling the renew function, an attacker could potentially force the expiration of an ENS record.\n\nYou can find the PoC included in the attached document. To execute the test, please use the following command:\n```\nforge test -vvv --match-contract RegistrarExploit --fork-url <alchemy_url>\n```\n\nReplace `<alchemy_url>` with your Alchemy API URL. This command will run the Foundry test file and demonstrate the potential vulnerability.\n\n### Impact\nIf successfully exploited, this vulnerability would enable attackers to force the expiration of any ENS record, ultimately allowing them to claim the affected domains for themselves.\n\nCurrently, it would require a malicious DAO to exploit it. Nevertheless, any vulnerability present in the controllers could potentially render this issue exploitable in the future.\n\nAn additional concern is the possibility of renewal discounts. Should ENS decide to implement a system that offers unlimited .eth domains for a fixed fee in the future, the vulnerability could become exploitable by any user due to the reduced attack cost.\n\n### Patches\nA mitigation is being developed.\n\n### Workarounds\nAs long as registration cost remains linear or superlinear based on registration duration, or limited to a reasonable maximum (eg, 1 million years), this vulnerability could only be exploited by a malicious DAO. The interim workaround is thus to take no action.\n",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:H/UI:N/S:U/C:N/I:H/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "@ensdomains/ens-contracts"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "0.0.22"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 0.0.21"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/ensdomains/ens-contracts/security/advisories/GHSA-rrxv-q8m4-wch3"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2023-38698"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/ensdomains/ens-contracts/commit/e6b136e979084de3761c125142620304173990ca"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/ensdomains/ens-contracts"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/ensdomains/ens-contracts/blob/master/contracts/ethregistrar/BaseRegistrarImplementation.sol#L171"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-190" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2023-08-01T19:48:31Z",
    "nvd_published_at" : "2023-08-04T18:15:15Z"
  }
}