Blog / A03:2021 Injection
A03:2021 · Injection

Credential text dropped straight into an SVG becomes script

A rendering step pasted credential values into an SVG template without escaping. A value carrying markup breaks out of its slot and adds a live script to whatever renders the image.

credential valueread from inputinserted verbatiminto an…markup escapesthe placeholderactive SVGelements addedscript runs wherethe image rendersATTACKER INPUTIMPACTcode path executes
Attack path · credential value read from input → inserted verbatim into an SVG template → markup escapes the placeholder → active SVG elements added → script runs where the image renders

A rendering step pasted credential values into an SVG template without escaping. A value carrying markup breaks out of its slot and adds a live script to whatever renders the image.

What goes wrong

The template has placeholders, and the code fills them by dropping selected credential values into the SVG string as-is. No escaping, no encoding. Whatever the value contains becomes part of the document.

SVG is XML, and XML can carry scripts, event handlers, and references to external resources. A credential value that contains a closing tag followed by a script element does not sit quietly inside its placeholder. It closes the surrounding element and injects live content. When that SVG is rendered in a browser context, the script runs with whatever access that context has. That is stored XSS, delivered as an image.

Placeholders are not a safety boundary. Any value going into markup has to be encoded for the exact context it lands in. For SVG and XML, escape the special characters, and strip or reject anything that tries to introduce active elements.

The pattern

Vulnerable
function render(template, cred) {
  let out = template;
  for (const field of FIELDS) {
    out = fill(out, field, cred[field]);   // inserted raw
  }
  return out;   // markup in a value becomes live SVG
}
Hardened
function render(template, cred) {
  let out = template;
  for (const field of FIELDS) {
    out = fill(out, field, xmlEscape(cred[field]));
  }
  return sanitizeSvg(out);   // strip active markup
}
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

If these documents get shown in a browser, to an admin reviewing a submission or another user viewing a shared credential, you have handed an attacker script execution in that viewer's session. Credential data is attacker-supplied more often than teams admit, because the entire point is that outsiders fill it in. Treat every field as hostile until it has been encoded.

Check your own code