fast-xml-parser: Quadratic-time (ReDoS-class) denial of service in XMLValidator attribute scanner, default options
Affected packages
| Package | Affected → Fixed | |
|---|---|---|
| NaturalIntelligencefast-xml-parser | — | Not listed |
| npmfast-xml-parser |
< 5.12.1→ 5.12.1 |
5.12.1 |
Original description The description as published by the source.
Summary
Reported by Nikhil Agrawal, Mettle Labs; reproduced only against a clean local install of fast-xml-parser@5.11.2 on their own machine. scanAttributeTokens in src/validator.js rescans a leading-whitespace run on every loop iteration when it hits a stray =, giving Theta(n^2) time. A few-hundred-KB input stalls the event loop for tens of seconds. Reachable on the default path via both XMLValidator.validate(xml) and new XMLParser().parse(xml, true), no non-default options.
Details
src/validator.js, scanAttributeTokens — on a = with no attribute name before it, i is reset to one past the token start, not past the =, so the leading-whitespace scan repeats:
function scanAttributeTokens(attrStr) {
const tokens = [];
const len = attrStr.length;
let i = 0;
while (i < len) {
const tokenStart = i;
// Leading whitespace before the name.
while (i < len && isWhiteSpace(attrStr[i])) i++;
if (i >= len) break;
if (attrStr[i] === '=') {
// No name before this '=' — not a valid attribute start.
i = tokenStart + 1; // <-- rewinds to tokenStart+1, NOT past the '=' -> re-scans the whitespace
continue;
}
...
For an attribute string of the shape =, each outer iteration advances tokenStart by one but re-walks the entire remaining whitespace run up to the =, so total work is quadratic in the run length. It is reached whenever an element's attribute section is scanned, which both `X…
Source: CVE.org (CVE Program・cvelistV5) NVD GitHub Advisory
References
- advisory github.com
- package github.com
- web github.com
- web github.com
- web github.com
- web nvd.nist.gov
- web github.com