ResolveURI RXSS Imperva Waf Bypass
A reflected cross-site scripting flaw existed where a value was placed into a stylesheet link's href attribute, and an Imperva WAF blocked common script keywords. The author found a way to run script through the print and console objects, eventually reading the document cookie to prove DOM access.
Published on systemweakness.com
Bugbounty
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
This write-up is about a reflected cross-site scripting issue that appears through a URI resolution mechanism, and about getting that payload past an Imperva WAF. The author, Ahsan Shahid, notes that this is his first write-up and that English is not his first language. He does not explain ResolveURI XSS in detail and instead points readers to an external article, https://blog.isec.pl/all-is-xss-that-comes-to-the-net/, for the background.
The target is described only through the example paths: an /AdminNet/ path, with theme assets under /App_Themes/Default/. The reflected value lands inside the href attribute of a <link> element. The report does not name the program, the host, or the exact page beyond the example paths.
Setup
The author did not run the initial discovery himself. A friend messaged him saying that URI-based XSS would not execute because of the Imperva WAF, and that the value was being reflected in a link href tag. The author worked on the bypass and sent the working payload back; the friend reported the bug, and the two split the bounty 50/50. The report gives no bounty amount, no program name and no dates beyond the publication date of 10 May 2022.
The only precondition stated is the reflection point itself: a value the attacker controls is placed into the href of a stylesheet link.
Finding it
The reflection looks like this, with the injected value sitting in the middle of the stylesheet path:
<link href="/AdminNet/Reflected-Value/App_Themes/Default/filename.css" rel="stylesheet" type="text/css" />====================================================================(A("onerror="alert`1`"))
Without a WAF, that payload executes. With Imperva in front, the keywords alert, confirm and prompt are blocked. The author also notes a structural limit that shapes everything that follows: because this is a ResolveURI XSS, he cannot use +, so string concatenation and global variables are not available to him as bypass tricks.
Exploitation
Step 1: swap the blocked function for print
The first working bypass replaces the blocked dialog functions with print:
(Z("onerror="a=print,a`1`"))https://domain.com/AdminNET/(Z("onerror="a=print,a`1`"))/filename.aspx
The payload stores print in a and then calls it through a with a backtick argument. The author says that print with brackets, print(1), and with backticks, print1``, were both blocked, so the assignment to a variable followed by the tagged-template call is what gets through. In the page, the reflected value produces:
<link href="/AdminNet/(Z("onerror="a=print,a`1`"))/App_Themes/Default/filename.css" rel="stylesheet" type="text/css" />
That gave a WAF bypass and proof of XSS, but the program did not accept alert(1) or print as proof: the researcher needed to demonstrate DOM access.
Step 2: try console.log directly
(Z("onerror="console.log"))
The WAF blocked console.log in that form.
Step 3: assign console to a variable
(Z("onerror="a=console,a.log`1`"))https://domain.com/AdminNET/(Z("onerror="a=console,a.log`1`"))/filename.aspx
This again proved XSS, but still did not give DOM access. The author then tried (Z("onerror="a=console,a.log()")): when he put a() in, the page redirected to another page and his value was not reflected there. The variant (Z("onerror="a=console.log,a1")) worked fine, but it still did not satisfy the requirement.
Step 4: read the cookie through the template literal
The final payload reaches the DOM by passing ${cookie} into the tagged template call:
(Z("onerror="a=console,a.log`${cookie}`"))https://domain.com/AdminNET/(Z("onerror="a=console,a.log`${cookie}`"))/filename.aspx
The author states that he was able to access the DOM via ${cookie} or ${domain}. He sent the payload to his friend, who reported the bug, and they were later rewarded and split the bounty 50/50. He says he spent a whole day on the bypass because of the constraints: no +, and the console.log() form redirecting to a page where the value is not reflected.
Root cause
The report does not describe the server-side code. What it shows is that a user-controlled value is placed into the href attribute of a <link> element without being neutralised, so the injected text becomes part of the markup and the onerror handler can be attached. The WAF blocked alert, confirm, prompt and console.log, but not the same functions reached through a variable assignment and a backtick call. The absence of + in a ResolveURI context did not prevent this because the payload never needed concatenation.
Impact
Under the conditions shown, an attacker who can get a crafted URI in front of a victim can execute script in the victim's browser in the context of the affected application, and can read the DOM, including the cookie, as demonstrated with ${cookie}. The author frames the result as a WAF bypass that the program accepted once DOM access was proven.
Fix
The report does not discuss remediation.
Variants to test
- Replace blocked dialog functions with
printand call it through a variable and a template literal, as ina=print,a1``. A positive result is script execution wherealertandprint(1)are blocked. - Reach
consolethrough a variable,a=console,a.log1``, whenconsole.logis blocked directly. A positive result is output in the console without a redirect. - Pass
${cookie}or${domain}into the tagged template call to prove DOM access. A positive result is the cookie or domain value appearing in the console output. - Try the bracketed call form,
a=console,a.log(), and watch for a redirect to a page where the value is not reflected; if that happens, fall back to the template literal form, which the author found worked. - On other targets, check whether the reflection point is an attribute such as
hrefon a<link>element, and whether the WAF blocks function names rather than the assignment-and-call pattern. A positive result is execution with a function name the blocklist does not cover.
What happened, in plain words
A security researcher named Ahsan Shahid heard from a friend that a certain kind of attack was not working on a website because a security product was standing in the way. That product is a WAF, short for Web Application Firewall. Think of a WAF as a bouncer at the door of a club: every request that arrives is checked against a list of things the bouncer has been told to refuse, and anything on the list is turned away before it reaches the inside of the building.
The attack in question is cross-site scripting, usually shortened to XSS. In an XSS attack, someone manages to get their own little piece of JavaScript (the programming language that browsers run inside web pages) into a page that other people will load. When a victim opens that page, the victim's browser runs the attacker's script as if the website itself had written it. That lets the script do things on the victim's behalf inside that site.
This particular flavour is called ResolveURI XSS. The author does not explain it in detail and instead points readers to an external article, https://blog.isec.pl/all-is-xss-that-comes-to-the-net/, for the background. What matters for this story is where the attacker's text ends up: inside the href attribute of a <link> element. A <link> element is how a web page pulls in an extra file, usually a stylesheet (the file that says what colours and fonts the page uses). The href attribute is simply the address of that file. If a page builds that address partly out of something the visitor supplied, and does not clean it up, the visitor can slip extra characters into the address, and those characters become part of the page's markup.
The friend could get his text reflected (that is, echoed back into the page) but the WAF kept blocking the part that actually runs code. The author spent a whole day finding a way around it, sent the working payload back, the friend reported the bug, and the two split the bounty 50/50. A bounty is a reward a company pays to someone who reports a security problem to it responsibly. The report gives no bounty amount, no program name and no dates beyond the publication date of 10 May 2022.
The starting point
The author did not discover the bug himself. His friend messaged him saying that URI-based XSS would not execute because of the Imperva WAF, and that the value was being reflected in a link href tag. Imperva is the vendor of that WAF. The target is described only through the example paths: an /AdminNet/ path, with theme assets under /App_Themes/Default/. ASP.NET is a framework for building websites, and a theme is a bundle of styling files a site uses to look consistent.
The only precondition stated is the reflection point itself: a value the attacker controls is placed into the href of a stylesheet link. The report does not name the program, the host, or the exact page beyond the example paths.
The reflection looks like this, with the injected value sitting in the middle of the stylesheet path:
<link href="/AdminNet/Reflected-Value/App_Themes/Default/filename.css" rel="stylesheet" type="text/css" />====================================================================(A("onerror="alert`1`"))
Line by line, in plain words:
<link ... />is the element that tells the browser to load an extra file. It is a self-closing tag, which is why it ends with/>.href="/AdminNet/Reflected-Value/App_Themes/Default/filename.css"is the address of the file to load. The partReflected-Valueis the placeholder where the visitor's input lands. Everything around it is fixed text the site supplies.rel="stylesheet"says what kind of file this is: a stylesheet.type="text/css"repeats that in the older, more explicit way.- The long run of
=signs and the(A("onerror="alert1"))after the tag are the attacker's text, shown here as it appears once it has been reflected. The attacker's text is shown reflected after the tag, including anonerrorattribute. Anonerrorattribute holds JavaScript that the browser runs if loading the file fails. Since the address has been mangled, loading will fail, and the script runs. alert1is a call to the browser's `alert` function, which pops up a small dialog box. The backticks are a JavaScript way of writing a string (a piece of text); `alert`1means the same asalert("1").
Without a WAF, that payload executes. With Imperva in front, the keywords alert, confirm and prompt are blocked. Those three are the classic browser dialog functions, and a blocklist that names them is a very common, very shallow defence.
The author also notes a structural limit that shapes everything that follows: because this is a ResolveURI XSS, he cannot use +. In JavaScript, + is how you glue two strings together, and it is also how attackers often build forbidden words out of harmless pieces (for example, putting al and ert together at runtime so the finished word never appears in the request). With + unavailable, string concatenation and global variables are not available to him as bypass tricks. A global variable is a named storage slot that any script on the page can read and write.
Getting past the WAF
Step 1: swap the blocked function for print
The first working bypass replaces the blocked dialog functions with print:
(Z("onerror="a=print,a`1`"))https://domain.com/AdminNET/(Z("onerror="a=print,a`1`"))/filename.aspx
Line by line:
(Z("onerror="a=print,a1"))is the text the attacker wants reflected. The outer(Z(...))is part of the URI structure the application is resolving; the author does not explain it further.onerror=starts a new attribute on the element, exactly as before.a=printstores the browser'sprintfunction (which opens the print dialog) in a variable calleda. The wordprintappears here as an assignment toa, not as a direct call.,separates two JavaScript expressions, so both run in order.a1`` then calls whatever is ina, which isprint, using a template literal. A template literal is a string written with backticks instead of quotes; it can contain placeholders written${...}that get filled in with values.https://domain.com/AdminNET/(Z("onerror="a=print,a1"))/filename.aspxis the full URL the attacker sends. The payload sits in the middle of the path, where the application will resolve it and reflect it into the page.
The author says that print with brackets, print(1), and with backticks, print1``, were both blocked, so the assignment to a variable followed by the tagged-template call is what gets through. A tagged template is simply a template literal placed directly after a function name, which makes JavaScript call that function with the string.
In the page, the reflected value produces:
<link href="/AdminNet/(Z("onerror="a=print,a`1`"))/App_Themes/Default/filename.css" rel="stylesheet" type="text/css" />
Line by line:
- The
hrefvalue now begins with the fixed/AdminNet/and then contains the attacker's(Z("onerror="a=print,a1"))before the fixed/App_Themes/Default/filename.css. - The attacker's text sits inside the
hrefvalue in the reflected markup. - The browser tries to load the stylesheet from the mangled address, fails, and runs the
onerrorscript, which callsprint.
That gave a WAF bypass and proof of XSS, but the program did not accept alert(1) or print as proof: the researcher needed to demonstrate DOM access. The DOM, short for Document Object Model, is the browser's live, in-memory model of the page. Reading the DOM means the script can look at what is actually on the page, which is a much stronger demonstration than a dialog box: a dialog proves code ran, but reading the DOM proves the code can see the victim's data.
Step 2: try console.log directly
(Z("onerror="console.log"))
Line by line:
console.logis the browser's built-in way of printing a message to the developer console, a panel in the browser where programmers watch output and errors.- Here it is written without any brackets or arguments, so it is only a reference to the function, not a call. The author was testing whether the WAF would let the name through at all.
The WAF blocked console.log in that form.
Step 3: assign console to a variable
(Z("onerror="a=console,a.log`1`"))https://domain.com/AdminNET/(Z("onerror="a=console,a.log`1`"))/filename.aspx
Line by line:
a=consolestores the browser'sconsoleobject in the variablea. An object is a bundle of related functions and values;consoleis the bundle that holdslog.a.log1`` reaches thelogfunction through the variable and calls it with a template literal containing1.- The rest of the URL works exactly as in step 1: the payload sits in the path and is reflected into the
href.
This again proved XSS, but still did not give DOM access. The author then tried (Z("onerror="a=console,a.log()")): when he put a() in, the page redirected to another page and his value was not reflected there. A redirect is the server telling the browser to go somewhere else; if the payload is not reflected on the destination page, the test is dead. The variant (Z("onerror="a=console.log,a1")) worked fine, but it still did not satisfy the requirement.
Step 4: read the cookie through the template literal
The final payload reaches the DOM by passing ${cookie} into the tagged template call:
(Z("onerror="a=console,a.log`${cookie}`"))https://domain.com/AdminNET/(Z("onerror="a=console,a.log`${cookie}`"))/filename.aspx
Line by line:
a=consoleis the same assignment as before.a.log${cookie}`` callslogwith a template literal whose placeholder is${cookie}. A cookie is a small piece of data a website asks the browser to store and send back with later requests; it is often used to remember who is logged in.${cookie}is a template literal placeholder that is filled in with the value of the variablecookie.- Because the placeholder is evaluated when the template is built, the browser fills in the actual cookie value and
console.logprints it. That is the DOM access the program wanted: the script has read data that belongs to the page and the victim.
The author states that he was able to access the DOM via ${cookie} or ${domain}. He sent the payload to his friend, who reported the bug, and they were later rewarded and split the bounty 50/50. He says he spent a whole day on the bypass because of the constraints: no +, and the console.log() form redirecting to a page where the value is not reflected.
Why it worked
The report does not describe the server-side code. What it shows is that a user-controlled value is placed into the href attribute of a <link> element without being neutralised, so the injected text becomes part of the markup and the onerror handler can be attached. Neutralising here would mean encoding the characters that have special meaning in HTML, such as the double quote, so they appear as text instead of ending the attribute.
The WAF blocked alert, confirm, prompt and console.log, but not the same functions reached through a variable assignment and a backtick call. A blocklist is a list of bad things; it only stops what someone thought to write down. The absence of + in a ResolveURI context did not prevent this because the payload never needed concatenation: the forbidden word was never split, it was simply reached by a different route.
What an attacker could do
Under the conditions shown, an attacker who can get a crafted URI in front of a victim can execute script in the victim's browser in the context of the affected application, and can read the DOM, including the cookie, as demonstrated with ${cookie}. The author frames the result as a WAF bypass that the program accepted once DOM access was proven.
How to fix it
The report does not discuss remediation. Canonicalising means reducing an address to one standard, predictable form before using it, so that odd spellings cannot smuggle anything through.
Things worth trying elsewhere
- Replace blocked dialog functions with
printand call it through a variable and a template literal, as ina=print,a1``. A positive result is script execution wherealertandprint(1)are blocked. - Reach
consolethrough a variable,a=console,a.log1``, whenconsole.logis blocked directly. A positive result is output in the console without a redirect. - Pass
${cookie}or${domain}into the tagged template call to prove DOM access. A positive result is the cookie or domain value appearing in the console output. - Try the bracketed call form,
a=console,a.log(), and watch for a redirect to a page where the value is not reflected; if that happens, fall back to the template literal form, which the author found worked. - On other targets, check whether the reflection point is an attribute such as
hrefon a<link>element, and whether the WAF blocks function names rather than the assignment-and-call pattern. A positive result is execution with a function name the blocklist does not cover.
Glossary
- WAF (Web Application Firewall): a security product that sits in front of a website and blocks requests that match patterns it has been told are bad.
- XSS (cross-site scripting): getting your own JavaScript into a page so that other people's browsers run it as if the site had written it.
- ResolveURI XSS: an XSS variant where the attacker's input is placed into a URI (an address) that the application resolves, and the result ends up in the page markup.
- JavaScript: the programming language that browsers run inside web pages.
<link>element: the HTML tag a page uses to pull in an extra file, usually a stylesheet.hrefattribute: the part of a link that holds the address of the file to load.- Stylesheet: a file that describes how a page looks, such as colours and fonts.
- Attribute: a named setting inside an HTML tag, written as
name="value". onerrorattribute: an HTML attribute that holds JavaScript to run when loading something fails.- Reflection: when a website echoes back input it received, without storing it.
- Payload: the piece of text an attacker sends in the hope that it will be executed or interpreted.
alert,confirm,prompt: browser functions that open small dialog boxes; commonly used as harmless proof that script ran.print: a browser function that opens the print dialog.console.log: a browser function that prints a message to the developer console.- Developer console: a panel in the browser where programmers see output and errors.
- Blocklist: a list of things that are forbidden; it only stops what someone thought to include.
- String: a piece of text in programming.
- Concatenation: gluing two strings together, in JavaScript usually with
+. - Global variable: a named storage slot that any script on the page can read and write.
- Variable: a named storage slot in a program.
- Template literal: a string written with backticks, which can contain
${...}placeholders that get filled in with values. - Tagged template: a template literal placed directly after a function name, which makes JavaScript call that function with the string.
- Object: a bundle of related functions and values in JavaScript.
- DOM (Document Object Model): the browser's live, in-memory model of the page, which scripts can read and change.
- Cookie: a small piece of data a site asks the browser to store and send back with later requests, often used to remember who is logged in.
${cookie}: a placeholder that fills in the page's cookie string.${domain}: a placeholder that fills in the page's domain name.- Redirect: the server telling the browser to go to a different page.
- URI / URL: an address; URL is the more familiar term for a web address.
- ASP.NET: a framework for building websites.
- Theme: a bundle of styling files a site uses to look consistent.
- Imperva: the vendor of the WAF in this story.
- Bounty: a reward a company pays to someone who reports a security problem to it responsibly.
- Encoding: rewriting special characters so they appear as text instead of being interpreted as markup.
- Canonicalise: reduce an address to one standard, predictable form before using it.