NewApp Monitoring is liveSign up free
AgentbeamBeta
Open-source package vulnerability · npm

CVE-2026-118772: joi: quadratic-time split in `string().email({ multiple: true })` allows denial of service

highCVSS 3.1 7.5GHSA-4528-x5fx-h6hg

The joi validation library for Node.js splits values slowly when a schema uses string().email({ multiple: true }). A long run of whitespace takes quadratic time, so one request with 100 KB of spaces blocks the event loop for seconds. Upgrade joi to 17.13.9 or 18.3.1. The old @hapi/joi package has no patched version.

Published Oct 30, 2026 · Analysis Oct 31, 2026

What an attacker can do

With the multiple option, the email rule splits the value with a regular expression that removes whitespace on both sides of the separator. String.prototype.split tries a match at each position. Inside a whitespace run, the leading whitespace pattern reads the rest of the run, finds no separator, and backtracks through all of it. A run of n spaces costs n squared steps. This holds for the default comma separator and for custom separators.

The reporter measured joi 18.3.0 on Node.js 26: 100,000 spaces took 3,349 ms and 200,000 spaces took 13,579 ms. The patched version took 1 ms for 200,000.

The attack needs only network access to a route that validates untrusted input with this schema and sets no length limit first. No login is needed on a public route. While the regular expression runs, the Node.js process answers no other requests. A few concurrent requests can keep a service down. The result is availability loss only, with no data exposure.

Who is affected

Affected releases of joi: 17.1.1 up to 17.13.8, and 18.0.0 up to 18.3.0. Every @hapi/joi release from 16.0.0 is also affected. Only code that calls email with multiple: true is exposed.

npm ls joi @hapi/joi

Search your code for the vulnerable use:

grep -rn "multiple: true" src

joi

Ecosystem
npm
Affected
>= 17.1.1, < 17.13.9
Fixed in
17.13.9
Check
npm ls joi

@hapi/joi

Ecosystem
npm
Affected
>= 16.0.0, <= 17.1.1
Fixed in
No patched version yet
Check
npm ls @hapi/joi

joi

Ecosystem
npm
Affected
>= 18.0.0, < 18.3.1
Fixed in
18.3.1
Check
npm ls joi

How to fix it

Upgrade joi to 17.13.9 on the 17.x line, or to 18.3.1 on the 18.x line.

npm install [email protected]

The fix changes the split regular expression so the leading whitespace match can start only at the beginning of a whitespace run, which makes the split linear. Split results do not change.

@hapi/joi has no patched version. Move to joi.

Workarounds from the advisory: put a length limit before the rule, for example Joi.string().max(1000).email({ multiple: true }). Do not use abortEarly: false with this schema, because the email rule then runs even when max fails. Do not rely on trim(), which removes only leading and trailing whitespace.

How to tell if you were hit

Look for requests with very large bodies or fields consisting mostly of whitespace sent to routes that validate email lists. Symptoms in the server are Node.js processes at 100 percent CPU for seconds, event loop lag, and request timeouts on unrelated endpoints right after a single request. Request logs showing a payload around 100 KB or more on invite or share-by-email endpoints are the thing to review.

Original advisory

From the GitHub Advisory Database (CC BY 4.0).

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 [email protected] (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.

Credited to manus-use.

Questions

Is my app affected if I use Joi.string().email() without multiple?

The advisory describes the flaw only for the multiple option. The vulnerable split runs only when multiple is set, and the patched code builds the regular expression only in that case.

Which joi versions fix this?

17.13.9 for the 17.x line and 18.3.1 for the 18.x line. @hapi/joi has no patched release.

Can I mitigate without upgrading?

Yes. Put .max() before .email(), for example max(1000), and avoid abortEarly: false for that schema. Do not rely on trim().

References

How this page is made: the data panel comes from the GitHub Advisory Database, CISA’s KEV catalog, the NVD and FIRST EPSS, and updates twice a day. The analysis is written by an AI model from the sources listed above and checked by automated rules before it is published. Check versions against the vendor's advisory before you act. Methodology

More npm vulnerabilities

All npm entries