PortSwigger-Writeups

Lab: Reflected XSS with some SVG markup allowed

Difficulty: Practitioner

Vulnerability: Reflected XSS with WAF Evasion & SVG Animation

Lab Link: https://portswigger.net/web-security/cross-site-scripting/contexts/lab-some-svg-markup-allowed

1. The Goal

The objective of this lab was to execute a Cross-Site Scripting (XSS) attack in a search function protected by a comprehensive blocklist WAF.

My goal was to identify whitelisted SVG tags, find a compatible event handler that fires automatically, and bypass a specific WAF filter to execute the alert() function.

2. Reconnaissance (Fuzzing)

I started by testing standard tags (

To map the attack surface, I used Burp Suite Intruder to fuzz for allowed tags.

d1 d2 d3 d7

3. Vulnerability Analysis

I focused on because it is an animation element. Animation elements have their own lifecycle events, which can be abused to execute code automatically without user interaction.

Event Enumeration

I fuzzed the tag for allowed event handlers.

The WAF Bypass (The Slash Trick)

When I attempted to use the event normally (

), the WAF blocked it. I suspected the WAF was using a Regular Expression to look for the pattern: `[SPACE]on[a-z]+=`. To bypass this, I used the Slash Trick. HTML parsers treat a forward slash (/) as a valid separator between the tag name and the attribute, but many WAFs fail to detect it. - Blocked: `` - Allowed: `<animatetransform/onbegin=1>` ##### 4. The Exploit Strategy I constructed a payload using the allowed componenets: 1. Container: (Required parent for SVG animations). 2. Trigger: (The allowed animation tag). 3. Event: onbegin (Fires immediately). 4. Validation: I added attributeName=transform because the browser requires a target attribute to consider the animation "valid" and start the timeline. ##### 5. The Payload I crafted the following payload: ```HTML <animatetransform/onbegin=alert(1) attributeName=transform> ``` Note on Encoding: When injection this into the URL, I encountered a "Protocol Error" because of the raw characters. I had to URL-encode the entire payload to ensure the server processed it correctly. Final Encoded Payload: `%3Csvg%3E%3Canimatetransform%2Fonbegin%3Dalert(1)%20attributeName%3Dtransform%3E` d10 ##### 6. Execution 1. I injected the encoded payload into the search bar. 2. The WAF passed the request (due to the slash trick and allowed tags). 3. The browser rendered the SVG and validated the animation instruction. 4. The animation timeline started, triggering the onbegin event immediately. 5. The alert(1) function executed. d11