ajv has ReDoS when using `$data` option
Affected releases · ajv
- 8.x8.0.0 – 8.17.1Fixed in 8.18.0
- 7.x7.0.0 – 7.2.4No fix on this line yet
- 6.x6.0.0 – 6.12.6Fixed in 6.14.0
- 5.x and older0.0.4 – 5.5.2No fix, no longer updated
On 8.x, the newest line:
npm install ajv@8.18.0Affected
8.0.0 – 8.17.1
31 releases
Fixed
8.18.0 – 8.20.0
2 releases, latest
Affected
7.0.0 – 7.2.4
12 releases
Affected
6.0.0 – 6.12.6
34 releases
Fixed
6.14.0 – 6.15.0
2 releases
Affected
5.0.0 – 5.5.2
20 releases
Affected
4.0.0 – 4.11.8
53 releases
Affected
3.0.0 – 3.8.10
35 releases
Affected
2.0.0 – 2.5.0
15 releases
Affected
1.0.0 – 1.4.10
20 releases
Affected
0.0.4 – 0.7.2
93 releases
Is your project affected?
Paste your package.json, or type the range you declare for ajv. It is read in your browser and sent nowhere.
What happens
ajv (Another JSON Schema Validator) through version 8.17.1 is vulnerable to Regular Expression Denial of Service (ReDoS) when the $data option is enabled. The pattern keyword accepts runtime data via JSON Pointer syntax ($data reference), which is passed directly to the JavaScript RegExp() constructor without validation. An attacker can inject a malicious regex pattern (e.g., \"^(a|a)*$\") combined with crafted input to cause catastrophic backtracking. A 31-character payload causes approximately 44 seconds of CPU blocking, with each additional character doubling execution time. This enables complete denial of service with a single HTTP request against any API using ajv with $data: true for dynamic schema validation.