Blog / A04:2021 Insecure Design
A04:2021 · Insecure Design

A big enough template makes preprocessing your bottleneck

Scanning an entire caller-supplied SVG for every placeholder and holding all matches in memory turns a template step into a resource-exhaustion target.

caller submits anSVG templatecode scans forall placeholdersevery match keptin an arraylarge templateexhausts memoryATTACKER INPUTIMPACTresource exhausted
Attack path · caller submits an SVG template → code scans for all placeholders → every match kept in an array → large template exhausts memory

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

Vulnerable
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)
}
Hardened
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)
}
How the pipeline adjudicated itPROVEN
ABCDEFGH

Every gate held. The exploit path was reproduced against a negative control, the impact was calibrated, and the finding was signed report-ready.

Ed25519 · per-tenant signing key · gate ledger A–H · verify offline against the published payload hash

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