Skip to content
XSS Write-up Intermediate

Every XSS is different

A search bar reflected user input inside an input tag's value attribute, and a filter blocked common XSS payloads. By double URL-encoding a plus sign between the quote and an onfocus attribute, the attacker bypassed the filter and triggered XSS, though the payload only worked when delivered via a URL shortener.

Leonardo Follow

Published on medium.com

Bug Bounty

Leonardo, on medium.com

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.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 5 min read.

Context

This is a write-up of an XSS found on a public bug-bounty program roughly a year before the article was published (June 2022). The program covers multiple websites across different countries, including Brazil, France and Spain. The researcher reported four different vulnerabilities to the program in total, but this article focuses on one XSS.

The affected site was one of the company's domains, discovered through Google dorking. It stood out because it was different from all the other websites the company runs. It did not offer much functionality, but it had a search bar, and the search value was reflected inside an input tag as its value attribute. That reflection is the feature under test here.

Setup

No accounts, roles or special tooling are described. The work was done against a public bug-bounty program, using a browser and manual payload testing. The only precondition was knowing the company's domain space, which the researcher gathered with a Google search using the site: operator:

Text
site:*.[company domain].*

This returns all or almost all of the company's domains and subdomains. The researcher then browsed the results and picked the site that looked different from the rest.

Finding it

The search bar reflected the submitted value into an input tag's value attribute, which is a classic XSS sink. The first test was a double quote, to see whether any filter applied. The double quote came back encoded, so a plain quote could not break out of the attribute.

The next attempt was to send the double quote URL encoded, and that was enough to bypass the encoding step. At that point the researcher expected an easy XSS.

Exploitation

Step 1: the classic payload and the 403

The first full payload was the classic script injection:

HTML
"><script>alert(0)</script>

The "> is meant to close the value attribute and the input tag, and the script element would execute alert(0). The site responded with a 403 page instead of the reflected result.

Step 2: locating the filter

The researcher then narrowed down which part of the payload triggered the block. The 403 appeared at the very beginning of the payload: just the sequence

was treated as malicious. Various encodings of that sequence were tried and none worked, so a different payload was needed.

Step 3: event-handler payloads and the second filter

The next idea was to use the focus and autofocus HTML attributes, which fire an event handler without user interaction when the element receives focus:

HTML
" onfocus=confirm(document.domain) autofocus

This also returned the 403 page. Testing showed that anything shaped like <space>on<any word>=<any word> was blocked, so the filter was matching event-handler attributes generally, not just script.

Step 4: double URL encoding to evade the filter

While testing different encodings, the researcher noticed that a character that was double URL encoded simply disappeared. That behaviour was used to break up the pattern the filter was matching: a plus sign, double URL encoded as %252b, was inserted between the quote and onfocus. The filter no longer recognised the payload as malicious and the XSS triggered when typed directly into the search bar.

Step 5: the payload only worked in the researcher's own browser

When the XSS was typed directly into the search bar it fired, but when the resulting URL was copied and sent to someone else, clicking the link did not trigger it. The researcher then tried a URL shortener, and through the shortened link the XSS finally worked.

Root cause

The search value is reflected into an input tag's value attribute. The application encodes a raw double quote but accepts a URL-encoded one, so the attribute can be broken out of. On top of that, a server-side filter blocks ">< and event-handler patterns of the form <space>on<word>=<word>, but the filter is pattern-based and can be evaded by inserting a double URL-encoded character (%252b) into the payload. The double-encoded character disappears during decoding, which was enough to evade the filter. The report does not describe the exact decoding order that produces this.

The reason the payload failed through a copied URL but worked through a shortener is not explained in the report.

Impact

An attacker who can get a victim to open a crafted link can execute JavaScript in the victim's browser in the context of the affected site. The researcher demonstrated this with confirm(document.domain). The report does not describe what data or actions were reachable from that origin, so the practical impact beyond script execution is not stated. The payload worked through a shortened link when opened by another person.

Fix

Based on the behaviour described, the reflection should be context-aware encoded so that a quote cannot break out of the value attribute regardless of its URL encoding, and the blocklist should not be the only defence: output encoding at the sink is what stops this class of bug, not pattern matching on the input.

Variants to test

  1. Send a URL-encoded double quote into any reflected parameter and check whether it comes back unencoded. A positive result is a raw " in the response where the plain quote was encoded.
  2. Probe which prefixes trigger a block by sending ">< alone. A 403 on that fragment but not on the full payload tells you the filter is matching the break-out sequence.
  3. Test event-handler attributes such as onfocus with autofocus when script is blocked. A positive result is a 403 for <space>on<word>=<word>, which reveals the filter's pattern.
  4. Insert a double URL-encoded character such as %252b between the quote and the handler name. A positive result is that the 403 disappears and the handler fires.
  5. Compare behaviour between typing the payload directly and opening the same URL from a fresh browser or another machine, and try a URL shortener if the direct link fails. A positive result is the payload firing through the shortened link.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 9 min read.

What happened, in plain words

A security researcher found a cross-site scripting (XSS) bug on a website that belonged to a company running a public bug-bounty programme. The programme covered many websites in different countries, including Brazil, France and Spain. The researcher reported four different vulnerabilities to the programme in total, but this article is about one XSS in particular.

The affected site was one of the company's domains, found by searching Google for the company's domain space. It stood out because it looked different from all the other websites the company runs. It did not offer much functionality, but it had a search bar, and whatever you typed into the search bar was reflected back into the page inside an input tag, as the value attribute. That reflection is the feature under test here.

XSS, or cross-site scripting, is a vulnerability where an attacker can make a website display or run their own code in someone else's browser. Think of it like a noticeboard where visitors can pin notes: if the board does not check what is written, someone can pin a note that says "ignore the real notice and do what I say", and other visitors will read it as if it came from the board owner. In a browser, the "note" is usually a short piece of JavaScript, and the browser runs it because it appears to come from the trusted site.

The researcher tested the search bar by sending a double quote, then a URL-encoded double quote, then a classic script payload, and got blocked by a 403 page. By narrowing down which part of the payload triggered the block, the researcher found two filters: one that blocked the sequence ">< and one that blocked event-handler attributes of the form <space>on<word>=<word>. A double URL-encoded plus sign (%252b) inserted between the quote and the handler name slipped past the filter, and the XSS fired when typed directly into the search bar. But when the resulting URL was copied and sent to someone else, clicking the link did not trigger it. The researcher then tried a URL shortener, and through the shortened link the XSS finally worked.

Setup

No accounts, roles or special tooling are described. The work was done against a public bug-bounty programme, using a browser and manual payload testing. The only precondition was knowing the company's domain space, which the researcher gathered with a Google search using the site: operator:

Text
site:*.[company domain].*

This search tells Google to return results only from the given domain pattern. The asterisks act as wildcards, so the pattern matches any subdomain of the company's domain. The researcher then browsed the results and picked the site that looked different from the rest.

Finding it

The search bar reflected the submitted value into an input tag's value attribute, which is a classic XSS sink. A sink is a place where data ends up in the page; if the data is not properly encoded, it can break out of its intended context and become code. The first test was a double quote, to see whether any filter applied. The double quote came back encoded, so a plain quote could not break out of the attribute.

The next attempt was to send the double quote URL encoded. URL encoding replaces special characters with a percent sign and two hexadecimal digits, so a double quote becomes %22. That was enough to bypass the encoding step. At that point the researcher expected an easy XSS.

Exploitation

Step 1: the classic payload and the 403

The first full payload was the classic script injection:

HTML
"><script>alert(0)</script>

The "> is meant to close the value attribute and the input tag, and the script element would execute alert(0). In plain words: the double quote ends the attribute value early, the greater-than sign closes the tag, and the browser then sees a new script element and runs the JavaScript inside it. alert(0) is a simple function that shows a pop-up with the number 0; it is used as a harmless proof that code is running. The site responded with a 403 page instead of the reflected result. A 403 is an HTTP status code meaning "forbidden": the server refused to serve the request, probably because a filter recognised the payload as an attack.

Step 2: locating the filter

The researcher then narrowed down which part of the payload triggered the block. The 403 appeared at the very beginning of the payload: just the sequence

was treated as malicious. Various encodings of that sequence were tried and none worked, so a different payload was needed. This step is like testing a lock: you try one piece at a time to see which piece the lock rejects.

Step 3: event-handler payloads and the second filter

The next idea was to use the focus and autofocus HTML attributes, which fire an event handler without user interaction when the element receives focus:

HTML
" onfocus=confirm(document.domain) autofocus

In plain words: the double quote tries to break out of the value attribute, onfocus is an event handler that runs when the element gets focus, confirm(document.domain) shows a confirmation dialog containing the current domain name, and autofocus makes the browser focus the element automatically. This also returned the 403 page. Testing showed that anything shaped like <space>on<any word>=<any word> was blocked, so the filter was matching event-handler attributes generally, not just script. The filter was looking for the pattern of a space, the letters "on", any word, an equals sign, and any word.

Step 4: double URL encoding to evade the filter

While testing different encodings, the researcher noticed that a character that was double URL encoded simply disappeared. Double URL encoding means encoding the percent sign itself: for example, a plus sign is %2b when URL encoded once, and %252b when that %2b is encoded again. That behaviour was used to break up the pattern the filter was matching: a plus sign, double URL encoded as %252b, was inserted between the quote and onfocus. The filter no longer recognised the payload as malicious and the XSS triggered when typed directly into the search bar.

Step 5: the payload only worked in the researcher's own browser

When the XSS was typed directly into the search bar it fired, but when the resulting URL was copied and sent to someone else, clicking the link did not trigger it. A URL shortener is a service that takes a long URL and gives you a short one that redirects to it. The report does not explain why the direct link failed but the shortened one worked.

Root cause

The search value is reflected into an input tag's value attribute. The application encodes a raw double quote but accepts a URL-encoded one, so the attribute can be broken out of. On top of that, a server-side filter blocks ">< and event-handler patterns of the form <space>on<word>=<word>, but the filter is pattern-based and can be evaded by inserting a double URL-encoded character (%252b) into the payload. The double-encoded character disappears during decoding, which was enough to evade the filter. The report does not describe the exact decoding order that produces this.

The reason the payload failed through a copied URL but worked through a shortener is not explained in the report.

Impact

An attacker who can get a victim to open a crafted link can execute JavaScript in the victim's browser in the context of the affected site. The researcher demonstrated this with confirm(document.domain). The payload worked through a shortened link when opened by another person.

Fix

Based on the behaviour described, the reflection should be context-aware encoded so that a quote cannot break out of the value attribute regardless of its URL encoding, and the blocklist should not be the only defence: output encoding at the sink is what stops this class of bug, not pattern matching on the input.

Variants to test

  1. Send a URL-encoded double quote into any reflected parameter and check whether it comes back unencoded. A positive result is a raw " in the response where the plain quote was encoded.
  2. Probe which prefixes trigger a block by sending ">< alone. A 403 on that fragment but not on the full payload tells you the filter is matching the break-out sequence.
  3. Test event-handler attributes such as onfocus with autofocus when script is blocked. A positive result is a 403 for <space>on<word>=<word>, which reveals the filter's pattern.
  4. Insert a double URL-encoded character such as %252b between the quote and the handler name. A positive result is that the 403 disappears and the handler fires.
  5. Compare behaviour between typing the payload directly and opening the same URL from a fresh browser or another machine, and try a URL shortener if the direct link fails. A positive result is the payload firing through the shortened link.

Glossary

  • XSS (cross-site scripting): a vulnerability where an attacker can make a website display or run their own code in someone else's browser.
  • Bug-bounty programme: a scheme where organisations reward people for finding and reporting security vulnerabilities in their systems.
  • Domain: a name that identifies a website, like example.com.
  • Subdomain: a domain that is part of a larger domain, like blog.example.com.
  • Google dorking: using advanced search operators in Google to find specific information, such as all subdomains of a company.
  • site: operator: a Google search operator that restricts results to a particular domain or pattern.
  • Input tag: an HTML element that lets users type or select data, often used in forms.
  • value attribute: the attribute of an input tag that holds its current value.
  • Reflection: when data sent by the user is echoed back in the server's response.
  • Sink: a place in the code where data ends up, such as an HTML attribute or a script, where it can become code if not properly encoded.
  • URL encoding: a way to represent special characters in a URL using a percent sign and two hexadecimal digits, so a double quote becomes %22.
  • Double URL encoding: encoding a URL-encoded string again, so the percent sign itself is encoded, for example %2b becomes %252b.
  • 403: an HTTP status code meaning "forbidden", indicating the server refused to serve the request.
  • Event handler: an HTML attribute that runs JavaScript when a particular event occurs, such as onfocus when an element receives focus.
  • focus and autofocus: HTML attributes; autofocus makes the browser automatically focus an element when the page loads, and focus is the event that fires when it does.
  • alert(0): a JavaScript function that shows a pop-up with the value 0, often used as a harmless proof of code execution.
  • confirm(document.domain): a JavaScript function that shows a confirmation dialog containing the current domain name, used here to prove script execution.
  • URL shortener: a service that takes a long URL and returns a short one that redirects to it.
  • Context-aware encoding: encoding data differently depending on where it will appear (HTML, attribute, JavaScript, URL) so that it cannot break out of its context.
  • Blocklist: a filter that blocks known-bad patterns, as opposed to allowing only known-good input.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.