GHSA-4528-X5FX-H6HG

Vulnerability from github – Published: 2026-10-30 23:10 – Updated: 2026-10-30 23:10
VLAI
Summary
joi: quadratic-time split in `string().email({ multiple: true })` allows denial of service
Details

Summary

Joi.string().email({ multiple: true }) takes quadratic time to split a value that contains a long run of whitespace. One request with 100 KB of spaces blocks the Node.js event loop for several seconds, which causes a denial of service.

Details

When the multiple option is set, the email rule splits the value into addresses with a regular expression that removes whitespace on each side of the separator:

const regex = new RegExp(`\\s*[${options.separator ? escapeRegex(options.separator) : ','}]\\s*`);
// ...
const emails = options.multiple ? value.split(regex) : [value];

String.prototype.split tries a match at each position of the value. At each position inside a whitespace run, the leading \s* reads the rest of the run, does not find a separator, and backtracks through all of it. A run of n whitespace characters without a separator therefore costs n² steps. This applies to the default separator and to all custom separator values.

The fix lets the leading whitespace match start only at the beginning of a whitespace run, so the split is linear:

const regex = new RegExp(`(?:(?<!\\s)\\s+)?[${options.separator ? escapeRegex(options.separator) : ','}]\\s*`);

The split results do not change. The regular expression is now built only when multiple is set.

Every joi release from 17.1.1 up to and including 17.13.8, and from 18.0.0 up to and including 18.3.0, is affected. Every @hapi/joi release from 16.0.0 is affected.

Workarounds for users who cannot upgrade:

  • Add .max() before .email(), for example Joi.string().max(1000).email({ multiple: true }). The max rule then rejects long values before the email rule runs.
  • Do not use the abortEarly: false option with this schema. With abortEarly: false, the email rule runs even when the max rule fails.
  • Do not use .trim() as a workaround. It removes only the whitespace at the start and at the end of the value.

Proof of concept

const Joi = require('joi');

const schema = Joi.string().email({ multiple: true });
for (const n of [25000, 50000, 100000, 200000]) {
    const start = Date.now();
    schema.validate(' '.repeat(n));
    console.log(`${n} spaces: ${Date.now() - start} ms`);
}

Output on joi@18.3.0 (Node.js 26):

25000 spaces: 244 ms
50000 spaces: 887 ms
100000 spaces: 3349 ms
200000 spaces: 13579 ms

Output on the patched version:

25000 spaces: 0 ms
50000 spaces: 0 ms
100000 spaces: 0 ms
200000 spaces: 1 ms

Over HTTP, send the whitespace in a field that the route validates with this schema:

POST /invite HTTP/1.1
Content-Type: application/json

{"emails": "<100000 spaces>"}

Impact

This is a denial of service by CPU exhaustion. It affects each application that validates untrusted input with Joi.string().email({ multiple: true }) and that has no length limit before the email rule. One request with 100 KB of whitespace blocks the Node.js event loop for several seconds, and the server cannot process other requests during that time. The attacker needs no authentication when the route is public, and a small number of concurrent requests can keep the service unavailable.

Show details on source website

{
  "affected": [
    {
      "package": {
        "ecosystem": "npm",
        "name": "joi"
      },
      "ranges": [
        {
          "events": [
            {
              "introduced": "17.1.1"
            },
            {
              "fixed": "17.13.9"
            }
          ],
          "type": "ECOSYSTEM"
        }
      ]
    },
    {
      "package": {
        "ecosystem": "npm",
        "name": "@hapi/joi"
      },
      "ranges": [
        {
          "events": [
            {
              "introduced": "16.0.0"
            },
            {
              "last_affected": "17.1.1"
            }
          ],
          "type": "ECOSYSTEM"
        }
      ]
    },
    {
      "package": {
        "ecosystem": "npm",
        "name": "joi"
      },
      "ranges": [
        {
          "events": [
            {
              "introduced": "18.0.0"
            },
            {
              "fixed": "18.3.1"
            }
          ],
          "type": "ECOSYSTEM"
        }
      ]
    }
  ],
  "aliases": [
    "CVE-2026-118772"
  ],
  "database_specific": {
    "cwe_ids": [
      "CWE-1333"
    ],
    "github_reviewed": true,
    "github_reviewed_at": "2026-10-30T23:10:23Z",
    "nvd_published_at": "2026-10-29T19:17:19Z",
    "severity": "HIGH"
  },
  "details": "### Summary\n\n`Joi.string().email({ multiple: true })` takes quadratic time to split a value that contains a long run of whitespace. One request with 100 KB of spaces blocks the Node.js event loop for several seconds, which causes a denial of service.\n\n### Details\n\nWhen the `multiple` option is set, the `email` rule splits the value into addresses with a regular expression that removes whitespace on each side of the separator:\n\n```js\nconst regex = new RegExp(`\\\\s*[${options.separator ? escapeRegex(options.separator) : \u0027,\u0027}]\\\\s*`);\n// ...\nconst emails = options.multiple ? value.split(regex) : [value];\n```\n\n`String.prototype.split` tries a match at each position of the value. At each position inside a whitespace run, the leading `\\s*` reads the rest of the run, does not find a separator, and backtracks through all of it. A run of `n` whitespace characters without a separator therefore costs `n\u00b2` steps. This applies to the default separator and to all custom `separator` values.\n\nThe fix lets the leading whitespace match start only at the beginning of a whitespace run, so the split is linear:\n\n```js\nconst regex = new RegExp(`(?:(?\u003c!\\\\s)\\\\s+)?[${options.separator ? escapeRegex(options.separator) : \u0027,\u0027}]\\\\s*`);\n```\n\nThe split results do not change. The regular expression is now built only when `multiple` is set.\n\nEvery `joi` release from `17.1.1` up to and including `17.13.8`, and from `18.0.0` up to and including `18.3.0`, is affected. Every `@hapi/joi` release from `16.0.0` is affected.\n\nWorkarounds for users who cannot upgrade:\n\n- Add `.max()` before `.email()`, for example `Joi.string().max(1000).email({ multiple: true })`. The `max` rule then rejects long values before the `email` rule runs.\n- Do not use the `abortEarly: false` option with this schema. With `abortEarly: false`, the `email` rule runs even when the `max` rule fails.\n- Do not use `.trim()` as a workaround. It removes only the whitespace at the start and at the end of the value.\n\n### Proof of concept\n\n```js\nconst Joi = require(\u0027joi\u0027);\n\nconst schema = Joi.string().email({ multiple: true });\nfor (const n of [25000, 50000, 100000, 200000]) {\n    const start = Date.now();\n    schema.validate(\u0027 \u0027.repeat(n));\n    console.log(`${n} spaces: ${Date.now() - start} ms`);\n}\n```\n\nOutput on `joi@18.3.0` (Node.js 26):\n\n```text\n25000 spaces: 244 ms\n50000 spaces: 887 ms\n100000 spaces: 3349 ms\n200000 spaces: 13579 ms\n```\n\nOutput on the patched version:\n\n```text\n25000 spaces: 0 ms\n50000 spaces: 0 ms\n100000 spaces: 0 ms\n200000 spaces: 1 ms\n```\n\nOver HTTP, send the whitespace in a field that the route validates with this schema:\n\n```http\nPOST /invite HTTP/1.1\nContent-Type: application/json\n\n{\"emails\": \"\u003c100000 spaces\u003e\"}\n```\n\n### Impact\n\nThis is a denial of service by CPU exhaustion. It affects each application that validates untrusted input with `Joi.string().email({ multiple: true })` and that has no length limit before the `email` rule. One request with 100 KB of whitespace blocks the Node.js event loop for several seconds, and the server cannot process other requests during that time. The attacker needs no authentication when the route is public, and a small number of concurrent requests can keep the service unavailable.",
  "id": "GHSA-4528-x5fx-h6hg",
  "modified": "2026-10-30T23:10:23Z",
  "published": "2026-10-30T23:10:23Z",
  "references": [
    {
      "type": "WEB",
      "url": "https://github.com/hapijs/joi/security/advisories/GHSA-4528-x5fx-h6hg"
    },
    {
      "type": "ADVISORY",
      "url": "https://nvd.nist.gov/vuln/detail/CVE-2026-118772"
    },
    {
      "type": "WEB",
      "url": "https://github.com/hapijs/joi/pull/3162"
    },
    {
      "type": "WEB",
      "url": "https://github.com/hapijs/joi/pull/3163"
    },
    {
      "type": "WEB",
      "url": "https://github.com/hapijs/joi/commit/03dc1d909818503b06240dadc81e9227ed2649cf"
    },
    {
      "type": "WEB",
      "url": "https://github.com/hapijs/joi/commit/807858d7480f5075b0610817e3e44230890fb18e"
    },
    {
      "type": "PACKAGE",
      "url": "https://github.com/hapijs/joi"
    },
    {
      "type": "WEB",
      "url": "https://github.com/hapijs/joi/releases/tag/v17.13.9"
    },
    {
      "type": "WEB",
      "url": "https://github.com/hapijs/joi/releases/tag/v18.3.1"
    }
  ],
  "schema_version": "1.4.0",
  "severity": [
    {
      "score": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H",
      "type": "CVSS_V3"
    }
  ],
  "summary": "joi: quadratic-time split in `string().email({ multiple: true })` allows denial of service"
}



Log in or create an account to share your comment.




Tags
Taxonomy of the tags.


Loading…

Loading…

Loading…

Drag nodes to arrange them. Double-click a related vulnerability to open it, or a source to visit its link. The Physics button on the left tunes the layout and the simulation; the legend at the bottom left hides or shows nodes by kind and by sighting type.

Forecast uses a logistic model when the trend is rising, or an exponential decay model when the trend is falling. Fitted via linearized least squares.

Sightings

Author Source Type Date Other

Nomenclature

  • Seen: The vulnerability was mentioned, discussed, or observed by the user.
  • Confirmed: The vulnerability has been validated from an analyst's perspective.
  • Published Proof of Concept: A public proof of concept is available for this vulnerability.
  • Exploited: The vulnerability was observed as exploited by the user who reported the sighting.
  • Patched: The vulnerability was observed as successfully patched by the user who reported the sighting.
  • Not exploited: The vulnerability was not observed as exploited by the user who reported the sighting.
  • Not confirmed: The user expressed doubt about the validity of the vulnerability.
  • Not patched: The vulnerability was not observed as successfully patched by the user who reported the sighting.
Vulnerability timeline

Sightings and recorded dates, grouped by day · UTC

JSON
Events included in the timeline

Loading timeline…


    Loading…

    Loading…

    Loading…

    Related by attack behaviour

    Vulnerabilities whose description is nearest to this one in the vector space of the CIRCL/vulnerability-attack-technique-biencoder model. This is a similarity search over the bi-encoder space (plain cosine), not a classification, and it has no measured accuracy.