Skip to content
XSS Write-up Intermediate

XSS Through Parameter Pollution

A callback parameter used for redirects reflected its value into a script tag without proper validation, and by adding a duplicate callback parameter the attacker bypassed the filter on quotes and injected JavaScript. This allowed reflected cross-site scripting, confirmed by an alert box.

Saajan Bhujel Follow

Published on infosecwriteups.com

This is my 2nd blog, if you find any spelling mistakes, so please bear with me for the next few minutes. And, also I found this vulnerability in the VDP Programs.

Saajan Bhujel, on infosecwriteups.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

Saajan Bhujel (@saajanbhujel11) found this issue while hunting on VDP (vulnerability disclosure) programs after a run of duplicate reports on HackerOne and Bugcrowd programs. The target is not named; the write-up substitutes site.com for the real domain.

The feature involved is a redirect endpoint. A URL of the form below takes a callback parameter and sends the user on to another subdomain of site.com:

Text
https://site.com/out?callback=https://subdomain.site.com

Opening that link redirects the browser to subdomain.site.com. The parameter value is also written back into the response, inside a script tag, where it sits in a variable the researcher calls callbackUrl.

Setup

No accounts, roles or special access are described. The work was done by hand against a live VDP target, with Burp Suite used to inspect responses. The only precondition is that the callback parameter is reflected into a script context and that the endpoint performs a redirect based on it.

Finding it

After two to three hours of hunting, the researcher noticed the callback parameter being used for redirects. The first test was to replace the subdomain value with an external domain, to see whether the site validates the destination at all. If redirects were restricted to subdomains of site.com, the endpoint would not be an open redirect; if there was no validation, it would be.

Text
https://site.com/out?callback=https://bing.com

Opening this link redirected to bing.com, so no validation was taking place and the endpoint was an open redirect.

Value of the callback parameter is reflecting in the response From the original on infosecwriteups.com

The response in Burp showed the callback value reflected back. Because the reflection sits inside a script tag, the researcher suspected the same parameter could also give reflected XSS by breaking out of the callbackUrl variable.

From the original on infosecwriteups.com

Exploitation

Step 1: try to break the variable directly

To close the string assigned to callbackUrl, the payload anything%22; was placed in the callback parameter. The request was blocked with an error. The same error appeared for other values such as ' and ".

Error that blocks my request From the original on infosecwriteups.com

At this point there were two options: report the open redirect, or look for a filter bypass that would yield XSS. Remembering a Pwnfunction video on HTTP parameter pollution, the researcher chose the second.

Or watch on YouTube
From the original on infosecwriteups.com

Step 2: add a second parameter of the same name

A second callback parameter was appended to the URL:

Text
https://site.com/out?callback=anything&callback=random
Response of two callback parameters From the original on infosecwriteups.com

The response contained the values of both parameters, separated by a comma. That behaviour is the key observation: the application concatenates the duplicate parameters rather than rejecting or ignoring one of them.

Step 3: break the variable through the second parameter

The blocked characters had been sent as the first (and only) callback value. This time the payload went into the second callback parameter, while the first held a harmless value:

Text
https://site.com/out?callback=anything&callback=%22;something%2f%2f
Able to break the callbackUrl variable From the original on infosecwriteups.com

The payload broke the variable and bypassed the filter. The variable was broken and the filter bypassed, which indicates that the validation was not applied to the second callback parameter.

Step 4: attempt an alert

With the breakout working, the next payload tried to execute script:

Text
https://site.com/out?callback=anything&callback=%22;alert%281%29;%2f%2f
Again getting a block request From the original on infosecwriteups.com

The request was blocked again, and the report attributes it to the brackets. Replacing the brackets with their URL-encoded form, or with backticks, still produced an error: some validation was still being applied to all the parameters.

Step 5: backticks, URL-encoded

Using backticks in URL-encoded form finally passed the filter. The final URL was:

Text
https://site.com/out?callback=anything&callback=%22;alert%60XSS_POC_BY_SAAJAN_BHUJEL%60;%2f%2f
Bypass the filter From the original on infosecwriteups.com
Getting an XSS alert

The report shows an alert image and states that XSS was performed through parameter pollution. In this case the bypass covered filters on values such as ' and " by moving the payload into a duplicate parameter.

Root cause

Two weaknesses combine. The redirect endpoint does not validate the destination, so any external URL is accepted, which is the open redirect. Separately, the callback value is reflected into a script tag without adequate encoding, and the input filter that blocks quotes and brackets is applied in a way that a duplicate parameter slips past. The response shows both parameter values joined with a comma, and the payload in the second copy broke out of the variable. The exact server-side logic is not shown in the write-up; the concatenation behaviour is what the responses demonstrate.

Impact

The confirmed impact is XSS on the redirect endpoint, plus an open redirect. An attacker who can get a victim to open a crafted link can run script in the context of site.com, and can also send users to an arbitrary external site through the redirect. The write-up does not describe session theft, credential access or any other post-exploitation step, and the target is a VDP program, so no bounty is mentioned.

Fix

The write-up does not say what the program changed. Reasonable fixes would be validating the callback destination and encoding the reflected value. Duplicate parameters of the same name should be rejected or handled consistently, and the input filter should apply to every occurrence of a parameter rather than only the first.

Variants to test

  1. Duplicate parameter on any reflected endpoint. Send ?param=safe&param=payload and look for both values in the response, joined or repeated. A positive result is the payload appearing unencoded in a script or HTML context where the single-parameter request was blocked.
  2. Redirect endpoints with a URL parameter. Replace the destination with an external domain and check whether the redirect happens. A positive result is a 3xx to the external host.
  3. Filter probing with quotes and brackets. Send ', ", (, ) and their URL-encoded forms one at a time and note which are blocked. A positive result is a value that is blocked alone but accepted when placed in a second parameter.
  4. Backtick substitution. Where brackets are filtered, try URL-encoded backticks around the alert argument. A positive result is script execution without brackets.
  5. Comment terminators. Append // or %2f%2f after the injected statement to neutralise the remainder of the line. A positive result is a clean breakout with no syntax error in the response.

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. 15 min read.

What happened, in plain words

A security researcher called Saajan Bhujel was looking for bugs in VDP programs. VDP stands for vulnerability disclosure program: a scheme where an organisation invites people to report security problems, usually without paying a reward. Before this, he had been hunting on HackerOne and Bugcrowd programs, which are bug bounty platforms where companies offer money for valid reports. He found real issues there, such as CSRF and business logic flaws, but every report was marked as a duplicate, meaning someone else had already reported the same thing. So he decided to spend some time on VDP programs instead.

After two to three hours of hunting he noticed something interesting. One website had a page that took a value from the address bar and used it to send the visitor somewhere else. That kind of page is called a redirect endpoint. He could not name the real site, so in his write-up he calls it site.com.

By changing the value in the address bar, he found two problems. First, the site would send visitors to any website at all, not just its own pages. That is called an open redirect. Second, the value he typed was copied back into the page inside a piece of JavaScript, which opened the door to cross-site scripting, usually shortened to XSS: a way of making a website run code that the attacker wrote.

The site had a filter that blocked the obvious ways of injecting code. He got around it by putting the same parameter in the URL twice, a trick called HTTP parameter pollution. The validation was not applied to the second copy, so the payload got through and the code ran.

This article walks through the same steps he did, in the same order, with the same URLs. Everything technical is explained from scratch, so you only need a browser and a computer to follow along.

The two ideas you need first

What is cross-site scripting (XSS)?

When you open a web page, your browser downloads a mixture of content and instructions. The content is the text and images you see. The instructions are small programs, usually written in a language called JavaScript, that make the page interactive: they can react to clicks, load new data, or change what is on screen.

Normally the website's authors write those programs. XSS happens when a website takes something a visitor supplied, such as a value from the address bar, and places it into the page in a way that the browser treats as part of the program rather than as harmless text. If an attacker can supply that value, the attacker's code runs inside the victim's browser, on the victim's session, as if the website itself had written it.

A simple comparison: imagine a noticeboard where visitors can pin a note, and the person in charge copies whatever is written on the note straight onto the official announcement board without checking it. If someone writes "and also, the office is closed tomorrow", that sentence now appears as an official announcement. XSS is the digital version: the site repeats the visitor's words as if they were its own instructions.

There are three main types, as the researcher lists them:

  • Reflected XSS: the malicious script comes from the current HTTP request. You send it in the URL or a form, and the site immediately echoes it back in the page. The victim has to open a link the attacker prepared.
  • Stored XSS: the malicious script comes from the website's database. It is saved once, for example in a comment, and then served to every visitor who views that page.
  • DOM-based XSS: the vulnerability exists in client-side code rather than server-side code. The dangerous handling happens entirely inside the browser's JavaScript, without the server ever seeing the payload.

The case in this write-up is reflected XSS: the value travels in the URL and comes straight back in the response.

What is HTTP parameter pollution (HPP)?

A URL often carries extra pieces of information after a question mark. Each piece is a parameter: a name, an equals sign, and a value. In https://site.com/out?callback=https://subdomain.site.com, the parameter name is callback and its value is https://subdomain.site.com. The server reads that value and decides what to do with it.

HTTP parameter pollution, as the name suggests, means polluting the parameters of a web application in order to perform or achieve a specific malicious task or attack different from the intended behaviour of the web application. In practice the usual trick is to send the same parameter name more than once, for example ?callback=one&callback=two, and see how the application copes. Different servers and frameworks handle duplicates differently: some take the first value, some take the last, some join them together. If a security filter checks one copy while the application uses another, the filter can be bypassed.

A comparison: a club has a doorman who checks the first name on a guest list, while the person at the desk inside uses the last name on the list. If you can get two names onto the list, one clean and one not, the doorman waves you through and the desk lets in the wrong person.

From the original on infosecwriteups.com

Finding the redirect

After spending some days in the programs of HackerOne and Bugcrowd, the researcher had found vulnerabilities such as CSRF and business logic flaws, but all his reports were duplicates. He decided to hunt on VDP programs instead, and after two to three hours he found that one domain was using a callback parameter in the URL for redirecting users to another subdomain.

A subdomain is a section of a larger domain: in subdomain.site.com, site.com is the main domain and subdomain is the part in front. Companies often run many subdomains for different services.

The URL looked like this:

Text
https://site.com/out?callback=https://subdomain.site.com

Line by line:

  • https:// is the protocol, the set of rules the browser uses to talk to the site securely.
  • site.com is the site being visited.
  • /out is the path, the particular page on that site. The name suggests it is a page that sends you out somewhere.
  • ? marks the start of the parameters.
  • callback=https://subdomain.site.com is one parameter named callback whose value is another web address.

Opening that link redirected the browser to subdomain.site.com. So the page reads the callback value and uses it as the destination.

Testing whether the destination is checked

The first question was whether the site validates the destination at all. Validation here means checking that the value is allowed before acting on it. If redirects were restricted to subdomains of site.com, the endpoint would not be an open redirect. If there was no validation, it would be.

So he replaced the value with an external domain:

Text
https://site.com/out?callback=https://bing.com

Line by line:

  • The page and parameter name are unchanged: /out and callback.
  • The value is now https://bing.com, a completely different website, not a subdomain of site.com.

Opening this link redirected to bing.com. That confirmed no validation was taking place, and the endpoint was an open redirect: anyone can craft a link on the trusted site.com domain that sends visitors to any destination they choose.

Value of the callback parameter is reflecting in the response From the original on infosecwriteups.com

The image shows the value of the callback parameter reflecting in the response.

Noticing the reflection

While inspecting the response, the researcher saw that the callback value was also written back into the page. This is called reflection: the server copies the input into its reply. He was looking at the response in Burp Suite, a tool that sits between the browser and the website and lets you read and edit every request and response. You do not need it to understand the idea; your browser's built-in developer tools show responses too.

The important detail was where the reflection sat: inside a script tag, the HTML element that holds JavaScript, where the value was assigned to a variable named callbackUrl. A variable is a named storage slot in a program. If the page contains something like var callbackUrl = "...value...";, then the value is placed between quotation marks as text. If an attacker can supply a quotation mark of their own, they can end the text early and start writing code instead.

From the original on infosecwriteups.com

Because of that, he suspected the same parameter could also give reflected XSS.

Step 1: try to break the variable directly

To close the string assigned to callbackUrl, he put this payload in the callback parameter:

Text
anything%22;

What each part means:

  • anything is filler text, so the value looks like an ordinary word at first glance.
  • %22 is the URL-encoded form of the double quote character ". URLs cannot contain certain characters directly, so they are written as a percent sign followed by two hexadecimal digits. %22 is how a browser sends a double quote.
  • ; is a semicolon, which in JavaScript marks the end of a statement, a complete instruction.

The idea: the page has opened a string with a quote, so a quote in the input closes it. The semicolon then ends the assignment, leaving room to write new code after it.

The request was blocked with an error. The same error appeared for other values such as ' and ". In other words, the site had a filter: a check that rejects input containing characters it considers dangerous.

Error that blocks my request From the original on infosecwriteups.com

The image shows the error that blocked the request.

At this point there were two options:

  1. Report the issue as an open redirect and move on.
  2. Find a bypass for the filter and get XSS.

He remembered a Pwnfunction video on HTTP parameter pollution that he had watched some weeks earlier, and chose the second option.

Or watch on YouTube
From the original on infosecwriteups.com

Step 2: add a second parameter of the same name

He appended a second callback parameter to the URL:

Text
https://site.com/out?callback=anything&callback=random

Line by line:

  • The first parameter is callback=anything, a harmless word.
  • & separates one parameter from the next. It is the standard separator in a URL.
  • The second parameter is also named callback, with the value random.

Sending the same parameter name twice is unusual, and that is the point: it tests how the application handles duplicates.

Response of two callback parameters From the original on infosecwriteups.com

The response contained the values of both parameters, separated by a comma. That behaviour is the key observation: the application joins the duplicate parameters together rather than rejecting or ignoring one of them.

Step 3: break the variable through the second parameter

The blocked characters had been sent as the first, and only, callback value. This time the payload went into the second callback parameter, while the first held a harmless value:

Text
https://site.com/out?callback=anything&callback=%22;something%2f%2f

Line by line:

  • callback=anything is the first copy, clean and boring.
  • callback=%22;something%2f%2f is the second copy, carrying the payload.
  • %22 is the double quote, which closes the string in the script.
  • ; ends the statement.
  • something is placeholder text standing in for code.
  • %2f%2f is the URL-encoded form of //. In JavaScript, // starts a comment, which tells the browser to ignore the rest of the line. That matters because the original script continues after the value, and without a comment the leftover code would cause a syntax error.
Able to break the callbackUrl variable From the original on infosecwriteups.com

The variable was broken and the filter bypassed. This indicates that the validation was not applied to the second callback parameter.

Step 4: attempt an alert

With the breakout working, the next payload tried to execute script. alert() is a built-in JavaScript function that opens a small pop-up box with a message. It is the standard harmless way to prove that code ran: if the box appears, your code executed.

Text
https://site.com/out?callback=anything&callback=%22;alert%281%29;%2f%2f

Line by line:

  • The first parameter is still the harmless anything.
  • %22 closes the string.
  • ; ends the statement.
  • alert%281%29 is alert(1) with the brackets URL-encoded: %28 is ( and %29 is ). The 1 is simply the message to display.
  • ; ends the new statement.
  • %2f%2f is //, commenting out the remainder of the original line.
Again getting a block request From the original on infosecwriteups.com

The request was blocked again, this time because of the brackets. Replacing the brackets with their URL-encoded form, or with backticks, still produced an error. Some validation was still being applied to all the parameters.

Step 5: backticks, URL-encoded

Using backticks in URL-encoded form finally passed the filter. A backtick is the ` character, the small mark usually found at the top left of a keyboard. In JavaScript, backticks can wrap text in place of ordinary quotes, so alertXSS_POC_BY_SAAJAN_BHUJEL`` calls the same alert function with the same kind of text argument, without using brackets.

The final URL was:

Text
https://site.com/out?callback=anything&callback=%22;alert%60XSS_POC_BY_SAAJAN_BHUJEL%60;%2f%2f

Line by line:

  • callback=anything is the harmless first copy.
  • %22 closes the string.
  • ; ends the statement.
  • alert%60XSS_POC_BY_SAAJAN_BHUJEL%60 is alertXSS_POC_BY_SAAJAN_BHUJEL``, where %60 is the URL-encoded backtick. The text between the backticks is the message shown in the pop-up.
  • ; ends the statement.
  • %2f%2f comments out the rest of the original line.
Bypass the filter From the original on infosecwriteups.com
Getting an XSS alert

The report shows an alert image and states that XSS was performed through parameter pollution. In this case the bypass covered filters on values such as ' and " by moving the payload into a duplicate parameter.

Why it worked

Two weaknesses combine.

The redirect endpoint does not validate the destination, so any external URL is accepted. That is the open redirect.

Separately, the callback value is reflected into a script tag without adequate encoding, and the input filter that blocks quotes and brackets is applied in a way that a duplicate parameter slips past. The response shows both parameter values joined with a comma, so the second value reaches the script context even though the first was the one the filter expected to inspect. The exact server-side logic is not shown in the write-up; the concatenation behaviour is what the responses demonstrate.

What an attacker could do with it

The confirmed impact is XSS on the redirect endpoint, plus an open redirect. An attacker who can get a victim to open a crafted link can run script in the context of site.com, and can also send users to an arbitrary external site through the redirect.

The write-up does not describe session theft, credential access or any other post-exploitation step. A session is the period during which a site remembers who you are, usually by storing a cookie, a small piece of data your browser keeps and sends back with each request. Stealing a session cookie is a common goal of XSS, but nothing like that is shown here. The target is a VDP program, so no bounty is mentioned.

How to fix it

The write-up does not say what the program changed. Reasonable fixes would be:

  • Validate the callback destination against an allowlist of site.com subdomains. An allowlist is a list of values that are explicitly permitted; anything not on the list is refused.
  • Encode or reject the reflected value so it cannot break out of the callbackUrl string. Encoding means converting characters such as quotes into a safe form that the browser displays as text instead of treating as code.
  • Reject duplicate parameters of the same name, or handle them consistently.
  • Apply the input filter to every occurrence of a parameter rather than only the first.

Things to try yourself

These are the same ideas, written so you can test them on a site you are allowed to test. Never test on a site without permission; use your own practice applications or a program that explicitly invites reports.

  1. Duplicate parameter on any reflected endpoint. Send ?param=safe&param=payload and look for both values in the response, joined or repeated. A positive result is the payload appearing unencoded in a script or HTML context where the single-parameter request was blocked.
  2. Redirect endpoints with a URL parameter. Replace the destination with an external domain and check whether the redirect happens. A positive result is a 3xx to the external host. A 3xx is an HTTP status code, a number the server sends to say what happened; the 3xx family means "go somewhere else".
  3. Filter probing with quotes and brackets. Send ', ", (, ) and their URL-encoded forms one at a time and note which are blocked. A positive result is a value that is blocked alone but accepted when placed in a second parameter.
  4. Backtick substitution. Where brackets are filtered, try URL-encoded backticks around the alert argument. A positive result is script execution without brackets.
  5. Comment terminators. Append // or %2f%2f after the injected statement to neutralise the remainder of the line. A positive result is a clean breakout with no syntax error in the response.
From the original on infosecwriteups.com

Glossary

  • Allowlist: a list of values that are explicitly permitted; anything not on the list is refused.
  • Backtick: the ` character, which JavaScript can use in place of ordinary quotes around text.
  • Burp Suite: a tool that sits between the browser and a website so you can read and edit requests and responses.
  • Business logic flaw: a bug in the rules a site follows rather than in its code, for example letting a user apply a discount twice.
  • Callback parameter: here, a URL parameter named callback whose value the site uses as a redirect destination.
  • Cookie: a small piece of data a website stores in your browser and receives back with later requests, often used to remember who you are.
  • Cross-site scripting (XSS): a vulnerability that lets an attacker get their own code to run in a victim's browser as part of a trusted website.
  • CSRF: cross-site request forgery, a trick that makes a logged-in user's browser send a request the user did not intend.
  • DOM-based XSS: XSS where the dangerous handling happens entirely in the browser's JavaScript rather than on the server.
  • Duplicate report: a report for a bug that someone else has already reported.
  • Encoding (URL encoding): writing characters in a URL as a percent sign plus two hexadecimal digits, such as %22 for a double quote.
  • Filter: a check that inspects input and rejects or alters values it considers dangerous.
  • HackerOne / Bugcrowd: bug bounty platforms where companies offer rewards for valid security reports.
  • HTTP parameter pollution (HPP): sending the same parameter name more than once to exploit differences in how a filter and the application handle duplicates.
  • JavaScript: the programming language that runs in web pages and makes them interactive.
  • Open redirect: a redirect endpoint that accepts any destination, so a trusted domain can be used to send visitors to an attacker's site.
  • Parameter: a name and value pair in a URL after the question mark, such as callback=value.
  • Payload: the piece of input an attacker sends to trigger a vulnerability.
  • Reflected XSS: XSS where the malicious script comes from the current request and is echoed straight back in the response.
  • Reflection: when a server copies input from a request into its response.
  • Redirect: a response that tells the browser to load a different address.
  • Session: the period during which a site remembers who you are, usually tracked with a cookie.
  • Stored XSS: XSS where the malicious script is saved in the site's database and served to later visitors.
  • Subdomain: a section of a larger domain, such as subdomain in subdomain.site.com.
  • Validation: checking that input is allowed before acting on it.
  • Variable: a named storage slot in a program that holds a value.
  • VDP (vulnerability disclosure program): a scheme where an organisation invites people to report security problems, usually without a reward.

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.