Scanning an entire caller-supplied SVG for every placeholder and holding all matches in memory turns a template step into a resource-exhaustion target.
What goes wrong
Preprocessing walks the whole SVG looking for placeholder tokens and pushes every match into an array. Nothing caps how large the template can be or how many matches it will retain.
A template a few megabytes wide, stuffed with valid placeholders, produces a match list that dwarfs it. The scan is linear, but the retained results are not free, and both the pattern matching and the growing array pile onto CPU and heap. It reads like innocent template work right until someone sends you a template built to be scanned.
The pattern
function prepareTemplate(svg) {
const matches = []
for (const m of svg.matchAll(PLACEHOLDER)) {
matches.push(m) // no cap on count or template size
}
return applyAll(matches)
}function prepareTemplate(svg) {
if (svg.length > MAX_TEMPLATE) throw new Error('template too large')
const matches = []
for (const m of svg.matchAll(PLACEHOLDER)) {
if (matches.length >= MAX_MATCHES) throw new Error('too many tokens')
matches.push(m)
}
return applyAll(matches)
}Every gate held. The exploit path was reproduced against a negative control, the impact was calibrated, and the finding was signed report-ready.
Why it matters to you
Template rendering feels like plumbing, so it rarely gets input limits. But any feature that lets a user bring their own template or document is an attacker-controlled input to your renderer. If sending a large one is cheap for them and expensive for you, that gap is the whole attack.
Bound the template size at intake and cap the matches you keep. The user who legitimately needs a ten-megabyte template is rare and easy to handle as an explicit exception rather than a default.
Check your own code
- Cap the size of any user-supplied template before scanning it.
- Limit how many matches or tokens you will collect from one input.
- Avoid keeping full match objects when an index or count would do.
- Benchmark preprocessing with a pathological template, not a typical one.