checkValidity() ReDoS: hasNestedQuantifiers misses alternation-overlap patterns such as (a|a)+ (incomplete fix of GHSA-x4hg-hfwf-p9mw)
Description
Affected versions
Verified on 0.0.28 (latest on npm) and on commit 25a3cba (the GHSA-x4hg fix, 0.0.22). hasNestedQuantifiers is unchanged on the default branch.
Impact
Same impact as GHSA-x4hg-hfwf-p9mw: a pattern value with catastrophic backtracking blocks the event loop inside checkValidity(). The fix's guard /([+*])\s*[)]\s*[+*{]/ only matches a quantifier right before a closing paren that is itself quantified. (a|a)+ has no inner quantifier, so it passes. It still backtracks exponentially, because both branches of the alternation match the same character.
Minimal PoC
import { Document } from '@asymmetric-effort/nogginlessdom';
const el = new Document().createElement('input');
el.pattern = '(a|a)+'; el.value = 'a'.repeat(26) + 'b';
console.time('checkValidity'); el.checkValidity(); console.timeEnd('checkValidity');Observed on 0.0.28 (ms per call, value a*n + b):
n=16 7.8 | n=20 34.6 | n=22 118.4 | n=24 478.3 | n=26 1891.2That is about 4x per two extra characters, so n=30 is about 30 s.
Negative controls (same run)
- Advisory shape
(a+)+, n=40: rejected byhasNestedQuantifiers, 0.5 ms. - Benign
[a-z]+, n=40: 0.1 ms. (a|a)+against a matching valuea*24: 0.0 ms. The cost is backtracking, not pattern size.
Suggested fix
Do not rely on a syntactic nested-quantifier check. Options: evaluate patterns with a linear-time engine (RE2 / re2-wasm), or run the match under a time budget in a worker. Or reject patterns with a quantified group that contains alternation, as a conservative stopgap.
Disclosure
We intend to keep this private for 90 days from the date of the report, or until a fixed release is available, whichever comes first, and are happy to adjust if you need more time.
First reported by email to scaldwell@asymmetric-effort.com on 2026-10-14; filed here at the maintainer's request.
Found with AploSec.
Reported by Zachariah Mithani (zachariah@aplosai.com).