joi: quadratic-time split in `string().email({ multiple: true })` allows denial of serviceGHSA-4528-x5fx-h6hg
HIGHFix: hapijs/joi#3162GHSA-4528-x5fx-h6hg is a high-severity (CVSS 7.5) CWE-1333 vulnerability in joi. A fix is available for joi — see the affected versions and patch details below.
EPSS Exploitation Probability
Probability of exploitation in the next 30 days, from FIRST.org EPSS.
How urgent is this, really
GHSA-4528-x5fx-h6hg by exploitation likelihood (EPSS) against impact (CVSS). Outside the shaded patch-first corner.
Where this sits among everything scored
Of 398,142 CVEs with a current EPSS score, this one falls in the < 10% band (highlighted). Counts from FIRST.org, log-scaled.
Real-World Exposure
How broadly this vulnerability is actually deployed: weekly install volume shows current usage, and reverse-dependency count shows how many other packages break if it stays unpatched.
joinpm@hapi/joinpmDescription
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 exampleJoi.string().max(1000).email({ multiple: true }). Themaxrule then rejects long values before theemailrule runs. - Do not use the
abortEarly: falseoption with this schema. WithabortEarly: false, theemailrule runs even when themaxrule 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.
Affected Packages
| Ecosystem | Package | Vulnerable range | Fix |
|---|---|---|---|
| 📦npm | joi | ≥ 17.1.1&&< 17.13.9 | 17.13.9npm install joi@17.13.9 |
| 📦npm | @hapi/joi | ≥ 16.0.0 | No fix |
| 📦npm | joi | ≥ 18.0.0&&< 18.3.1 | 18.3.1npm install joi@18.3.1 |
Detection & mitigation playbook
Open-source dependencyDetect
Scan your dependency tree (package-lock.json, pnpm-lock.yaml, requirements.txt, go.sum, etc.) for joi, including transitive dependencies — a direct dependency you never call can still pull in a vulnerable version.
Fix
Update joi to 17.13.9 or later, then make sure no transitive (indirect) dependency still pins the vulnerable range — O3 confirms GHSA-4528-x5fx-h6hg is resolved across your whole dependency graph.
Workarounds
Cap what an attacker can consume: apply request size, rate and timeout limits in front of the affected component, and run it with memory and CPU limits so exhaustion degrades one worker rather than the whole service.
Fixing This On Your OS
If you run this on a Linux distribution, patch through your package manager against the distro's own security advisory below — it tracks the exact backported fix for your release, which can ship on a different timeline (and sometimes a different severity) than the upstream project.
This vulnerability is rated with an Important severity because an unauthenticated remote attacker can trigger severe CPU exhaustion, stalling the single-threaded Node.js event handling and causing a denial of service. Within Red Hat environments, the joi library is embedded across various web dashboards and…
Mitigation for this issue is either not available or the currently available options do not meet the Red Hat Product Security criteria comprising ease of use and deployment, applicability to widespread installation base, or stability.Source: Red Hat security advisory for GHSA-4528-x5fx-h6hg (CC BY 4.0)
Frequently Asked Questions
Is GHSA-4528-x5fx-h6hg in your dependencies?
Find it across npm, including transitive dependencies.