Skip to content
XSS Write-up Intermediate

Stealing User Information Via XSS Via Parameter Pollution

A client-side redirect function read a URL parameter and assigned it to window.location, allowing an attacker to inject a javascript: URL. By duplicating the parameter, the server's check on the first value was bypassed, and a tab character inside the scheme evaded a keyword filter, enabling script execution that could steal the logged-in user's information.

Hamza Avvan Follow

Published on levelup.gitconnected.com

Bounty$1,250 View original

Level Up Coding

Hamza Avvan, on levelup.gitconnected.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. 6 min read.

Context

This is a bug bounty write-up by Hamza Avvan (@hamzaavvan), published in Level Up Coding and disclosed on 12 January 2021. The target is a web application on Bugcrowd that the researcher had tested before. The report does not name the program or the application. The feature involved is a post-action redirect: after the user performs a certain action, the application sends the browser to a URL taken from the continue_url query parameter. The redirect is performed client-side, in JavaScript, rather than by the server.

The weakness recorded for the report is open redirect plus XSS, and the bounty was 1250.00 USD.

Setup

The researcher logged in to a Bugcrowd account and picked a target on which he had found bugs in the past, chosen to match his skills. No other tooling, accounts or versions are described. The attack needs a victim who opens a crafted link containing the continue_url parameter twice; reading the victim's user information additionally requires the victim to be logged in.

Finding it

The researcher started with source code review of the application's JavaScript files. In that review he found two endpoints that looked vulnerable to open redirect and XSS, because the developers let the application, rather than the server, decide where to redirect the user after an action. The redirect logic he found looks like this:

JavaScript
function get_param(param) {    var params = {};    var url = window.location.href;    var start = url.indexOf('?');    start = start < 0 ? url.length : start + 1;    var end = url.indexOf('#');    end = end < 0 ? url.length : end;    var parameters = url.slice(start,end).split('&');for ( var i = 0; i < parameters.length; i++) {        var parameter = parameters[i].split('=');        params[parameter[0]] = parameter[1];    }    return params[param];}// redirect from applicationwindow.location.href = get_param("continue_url");

The function takes the query string from window.location.href, splits it on &, splits each pair on =, and stores each value in a params object keyed by the parameter name. The result for continue_url is then assigned to window.location.href, which navigates the browser to it. Because the loop assigns params[parameter[0]] = parameter[1] for every pair, a repeated parameter name overwrites the earlier value, so the last occurrence wins in the browser.

Exploitation

Step 1: open redirect attempt

The first attempt was a plain open redirect through continue_url. The server responded with a 404 page whenever the parameter contained another domain or a payload, so the redirect was blocked at that stage.

Step 2: parameter pollution to bypass the server check

The researcher knew the server environment was Java, and Java is known for its handling of duplicate parameters. He sent the same parameter twice:

Text
?continue_url=redacted.com&continue_url=attacker.com

The server validated only the first continue_url value and ignored the second. The browser-side function, however, overwrote the first value with the second, so the application redirected to attacker.com. That bypassed the server's restriction.

The overwrite comes from this line of the function:

JavaScript
params[parameter[0]] = parameter[1];

With the supplied parameters, the object is built in two steps:

JavaScript
// setting value to continue_urlparams["continue_url"] = "redacted.com"; // overwriting continue_url using parameter pollutionparams["continue_url"] = "attacker.com";

The final value of continue_url in the params object is therefore the attacker-controlled second one.

Step 3: trying to escalate to XSS

With the server-side check bypassed, the next step was to put a JavaScript payload in the second parameter:

The server returned 400 Bad Request. Even after the 404 restriction was bypassed through parameter pollution, the server still checked the parameter for keywords related to javascript and rejected the request with a 400 error.

Step 4: probing the keyword filter

The researcher ran a set of test cases against the filter:

Text
xjavascript:alert(1)  // 400 Bad RequestjavaScriptx:alert(1)  // 400 Bad Requestxjavascriptx:alert(1) // 400 Bad Requestjavaxscript:alert(1)  // 200 OK (Breaking javascript)

From these results he concluded that the server was likely using a regular expression to extract and match the javascript keyword in the parameter string, in order to block the XSS. Inserting a character inside the keyword breaks that match while the browser still interprets the scheme.

Step 5: bypassing the filter with an encoded tab

The bypass is to place a URL-encoded tab character, %09, inside the payload. This breaks the server's validation, while JavaScript ignores the tab character, so the alert still fires. The final payload:

Text
javas%09cript:alert(1) // 200 OK

Step 6: stealing user information

While building the proof of concept, the researcher extended it to steal the details of the currently logged-in user. The script he wrote:

JavaScript
fetch("https://redacted.com/path/to/userinfo").then(a => a.json()).then(a => console.log(a.response)); // Instead of logging user info, an attacker may send it to his/her server

The full payload, with the script URL-encoded inside the second continue_url:

The fetch call requests the user information endpoint; the report does not state whether the response was readable. The result was logged to the browser console for demonstration; as the researcher notes, an attacker could instead send it to a server they control.

Root cause

Two mistakes combine. On the server, the validation of continue_url reads only the first occurrence of the parameter, while the Java environment accepts and processes duplicate parameters. On the client, get_param loops over every pair and assigns into the same object key, so a duplicate name silently overwrites the earlier value. The server therefore validates one value and the browser navigates to another. The researcher notes that the developers were either not fully aware of Java's behaviour with multiple parameters of the same name, or did not consider it when writing the function.

The keyword filter on javascript was the remaining defence. It appears to be a regular expression match on the parameter string, and it is defeated by inserting %09 inside the scheme, which the browser ignores when parsing the URL but which breaks the pattern match.

Impact

An attacker who can get a logged-in victim to open a crafted link can run JavaScript in the context of the application's origin. In the demonstrated case this reads the victim's user information from an authenticated endpoint and logs it; the same script could send it to an attacker-controlled server. The attack requires the victim to be logged in and to follow the link.

Fix

The changes implied by the findings are: validate every occurrence of a repeated parameter on the server rather than only the first, and make the client-side get_param reject or consistently handle duplicate parameter names instead of silently overwriting. The redirect target should also be restricted to an allowlist of expected destinations rather than filtered by keyword, since keyword matching on javascript was bypassed with an encoded tab.

Variants to test

  1. Send any redirect or return-URL parameter twice with different values and see whether the server checks the first while the client uses the last. A positive result is a redirect to the second value.
  2. Try the same duplicate-parameter trick on other parameters that feed client-side logic, such as next, redirect, url or return. A positive result is the client acting on a value the server did not validate.
  3. Probe keyword filters with characters the browser ignores in a scheme, such as an encoded tab (%09) or other encoded whitespace. A positive result is a 200 response where the plain keyword returned 400, with the script still executing.
  4. Test case variations of the blocked keyword (javaScript, xjavascript, javaxscript) to map what the filter matches. A positive result is any variant that passes validation and still executes.
  5. Chain the redirect into a same-origin fetch of an authenticated endpoint, as in the proof of concept, to confirm whether user data is readable. A positive result is the endpoint returning the victim's data to the injected script.

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

What happened, in plain words

A security researcher found a way to make a website send its logged-in users to a page of his choosing, and then to run his own code inside that website while the user was still logged in. The trick relied on two small mistakes that combined: the website's server checked only the first copy of a setting in the link, while the browser acted on the last copy. Once he could control where the browser went, he found a way around the website's filter that was meant to block dangerous links, and used it to read the logged-in user's account details.

He reported it through Bugcrowd, a platform where companies pay researchers for finding security problems. The report was published in Level Up Coding and disclosed on 12 January 2021, and the bounty was 1250.00 USD. The report does not name the program or the application.

Before going further, a few words on the pieces involved.

A web application is a program you use through your browser: you type a web address, the browser asks a server for a page, and the server sends back HTML, JavaScript and other files. The browser then runs the JavaScript, which can change the page, read things and send requests.

A URL (uniform resource locator) is the address of a page. It has parts. The origin is the scheme, host and port together, for example https://redacted.com. The path is what comes after the host, like /endpoint. The query string is the part after a ?, made of parameters: pairs of a name and a value joined by =, separated by &. In ?continue_url=redacted.com&continue_url=attacker.com there are two parameters, both named continue_url.

An endpoint is a specific address on a server that does a specific job, like returning a user's profile or accepting a form. Think of a large office building: the building is the website, and each endpoint is a different service window.

JavaScript is the programming language that runs inside your browser. It is what makes pages interactive. It can also read the address bar, change the page, and send requests to servers.

An open redirect is a weakness where a website takes a destination from the URL and sends the user there without checking it properly. It is like a receptionist who will walk you to any address written on a note you hand over, including a stranger's office.

XSS, short for cross-site scripting, is a weakness where an attacker gets their own JavaScript to run as part of a trusted website, inside a victim's browser. Because the code runs with the website's origin, it can do things the website itself could do for that user, such as read their data. It is like someone slipping a forged page into a company's internal binder: staff treat it as company material.

Parameter pollution is the trick of sending the same parameter name more than once with different values. Different parts of a system may disagree about which copy counts, and that disagreement is the weakness.

A session is how a website remembers that you are logged in. After you sign in, the server gives your browser a cookie or token, a short secret string that the browser sends with every request. The server sees it and knows the request is yours. If someone else's code runs in your browser on that website, it can make requests that carry your cookie, and the server will treat them as coming from you.

A bug bounty program is a company's offer to pay researchers who report security problems responsibly. Bugcrowd is one of the platforms that runs such programs. Triaged means the program's staff have looked at a report and confirmed it is real and worth handling.

Setup

The researcher logged in to his Bugcrowd account and picked a target on which he had found bugs in the past, chosen to match his skills. The report describes no other tools, accounts or software versions.

The attack needs a victim who opens a crafted link containing the continue_url parameter twice; reading the victim's user information additionally requires the victim to be logged in. The feature involved is a post-action redirect: after the user performs a certain action, the application sends the browser to a URL taken from the continue_url query parameter. The redirect happens in JavaScript in the browser, not on the server.

Finding it

The researcher started with source code review, which means reading the application's own JavaScript files, the code the browser downloads and runs, looking for logic that trusts input from the URL. In that review he found two endpoints that looked vulnerable to open redirect and XSS, because the developers let the application, rather than the server, decide where to redirect the user after an action. The redirect logic he found looks like this:

JavaScript
function get_param(param) {    var params = {};    var url = window.location.href;    var start = url.indexOf('?');    start = start < 0 ? url.length : start + 1;    var end = url.indexOf('#');    end = end < 0 ? url.length : end;    var parameters = url.slice(start,end).split('&');for ( var i = 0; i < parameters.length; i++) {        var parameter = parameters[i].split('=');        params[parameter[0]] = parameter[1];    }    return params[param];}// redirect from applicationwindow.location.href = get_param("continue_url");

Line by line:

  1. function get_param(param) { defines a function named get_param that takes one argument, the name of the parameter to look up.
  2. var params = {}; creates an empty object, a container that will hold name and value pairs.
  3. var url = window.location.href; reads the full address of the current page from the browser.
  4. var start = url.indexOf('?'); finds where the query string begins. indexOf returns the position of the character, or -1 if it is not there.
  5. start = start < 0 ? url.length : start + 1; handles the case where there is no ?: if so, start at the end of the URL; otherwise start just after the ?.
  6. var end = url.indexOf('#'); finds where the fragment begins, the part after a # that browsers do not send to the server.
  7. end = end < 0 ? url.length : end; if there is no #, use the end of the URL; otherwise stop at the #.
  8. var parameters = url.slice(start,end).split('&'); cuts out the query string and splits it on &, giving a list of name=value pieces.
  9. for ( var i = 0; i < parameters.length; i++) { loops over each piece.
  10. var parameter = parameters[i].split('='); splits the piece on =, so parameter[0] is the name and parameter[1] is the value.
  11. params[parameter[0]] = parameter[1]; stores the value in the object under the name. This is the important line: if the same name appears again, the new value replaces the old one.
  12. return params[param]; returns the value stored under the requested name.
  13. window.location.href = get_param("continue_url"); takes the value of continue_url and assigns it to the browser's address, which makes the browser navigate there.

Because the loop assigns params[parameter[0]] = parameter[1] for every pair, a repeated parameter name overwrites the earlier value, so the last occurrence wins in the browser.

Exploitation

Step 1: open redirect attempt

The first attempt was a plain open redirect through continue_url. The server responded with a 404 page whenever the parameter contained another domain or a payload, so the redirect was blocked at that stage. A 404 is the standard response meaning the requested page was not found; here the server used it as a refusal.

Step 2: parameter pollution to bypass the server check

The researcher knew the server environment was Java, and Java is known for its handling of duplicate parameters. He sent the same parameter twice:

Text
?continue_url=redacted.com&continue_url=attacker.com

This is a query string with two parameters of the same name. The first value is a harmless domain, the second is the attacker's domain. The server validated only the first continue_url value and ignored the second. The browser-side function, however, overwrote the first value with the second, so the application redirected to attacker.com. That bypassed the server's restriction.

The overwrite comes from this line of the function:

JavaScript
params[parameter[0]] = parameter[1];

This line takes the name of the current pair and stores the value under it. When the loop reaches the second continue_url, it stores the new value under the same name, replacing the first. With the supplied parameters, the object is built in two steps:

JavaScript
// setting value to continue_urlparams["continue_url"] = "redacted.com"; // overwriting continue_url using parameter pollutionparams["continue_url"] = "attacker.com";

The first line stores the harmless value. The second line stores the attacker's value under the same name, so the first is lost. The final value of continue_url in the params object is therefore the attacker-controlled second one.

Step 3: trying to escalate to XSS

With the server-side check bypassed, the next step was to put a JavaScript payload in the second parameter:

javascript: is a URL scheme, like http: or https:, that tells the browser to run the text after it as JavaScript instead of loading a page. alert(1) is a built-in function that shows a small pop-up with the number 1; researchers use it as a harmless signal that code ran. The server returned 400 Bad Request. A 400 is the standard response meaning the request was malformed or unacceptable. Even after the 404 restriction was bypassed through parameter pollution, the server still checked the parameter for keywords related to javascript and rejected the request with a 400 error.

Step 4: probing the keyword filter

The researcher ran a set of test cases against the filter:

Text
xjavascript:alert(1)  // 400 Bad RequestjavaScriptx:alert(1)  // 400 Bad Requestxjavascriptx:alert(1) // 400 Bad Requestjavaxscript:alert(1)  // 200 OK (Breaking javascript)

Each line is a variation of the blocked word. The first three add letters around or change the case of javascript and are still rejected with 400. The fourth inserts an x in the middle of the word, turning javascript into javaxscript, and the server answers 200, meaning the request was accepted. From these results he concluded that the server was likely using a regular expression, a pattern-matching tool, to extract and match the javascript keyword in the parameter string, in order to block the XSS. Inserting a character inside the keyword breaks that match while the browser still interprets the scheme.

Step 5: bypassing the filter with an encoded tab

The bypass is to place a URL-encoded tab character, %09, inside the payload. In a URL, characters that are not safe to type are written as a percent sign followed by two hexadecimal digits; %09 is the tab character. This breaks the server's validation, while JavaScript ignores the tab character, so the alert still fires. The final payload:

Text
javas%09cript:alert(1) // 200 OK

Read it as javas, then a tab, then cript:alert(1). The server's pattern no longer sees the word javascript and lets the request through with a 200. The browser, when it parses the scheme, ignores the tab and sees javascript:alert(1), so the code runs.

Step 6: stealing user information

While building the proof of concept, the researcher extended it to steal the details of the currently logged-in user. The script he wrote:

JavaScript
fetch("https://redacted.com/path/to/userinfo").then(a => a.json()).then(a => console.log(a.response)); // Instead of logging user info, an attacker may send it to his/her server

Line by line:

  1. fetch("https://redacted.com/path/to/userinfo") asks the browser to send a request to that address. The script sends a request to the user information endpoint; the report does not state whether the browser attached the victim's session cookie.
  2. .then(a => a.json()) waits for the response and reads its body as JSON, a common text format for structured data.
  3. .then(a => console.log(a.response)) takes the parsed data and prints it in the browser's developer console, a panel where developers see messages and errors.
  4. The comment notes that instead of logging the data, an attacker could send it to a server they control.

The full payload, with the script URL-encoded inside the second continue_url:

Here the second continue_url value is the whole script, with special characters percent-encoded so it survives the trip through the URL: %22 is a double quote, %3D is =, %3E is >. The // at the end starts a comment in JavaScript, so anything the browser might append is ignored. The result was logged to the browser console for demonstration; as the researcher notes, an attacker could instead send it to a server they control.

Root cause

Two mistakes combine. On the server, the validation of continue_url reads only the first occurrence of the parameter, while the Java environment accepts and processes duplicate parameters. On the client, get_param loops over every pair and assigns into the same object key, so a duplicate name silently overwrites the earlier value. The server therefore validates one value and the browser navigates to another. The researcher notes that the developers were either not fully aware of Java's behaviour with multiple parameters of the same name, or did not consider it when writing the function.

The keyword filter on javascript was the remaining defence. It appears to be a regular expression match on the parameter string, and it is defeated by inserting %09 inside the scheme, which the browser ignores when parsing the URL but which breaks the pattern match.

Impact

An attacker who can get a logged-in victim to open a crafted link can run JavaScript in the context of the application's origin. In the demonstrated case this reads the victim's user information from an authenticated endpoint and logs it; the same script could send it to an attacker-controlled server. The attack requires the victim to be logged in and to follow the link.

Fix

The changes implied by the findings are: validate every occurrence of a repeated parameter on the server rather than only the first, and make the client-side get_param reject or consistently handle duplicate parameter names instead of silently overwriting. The redirect target should also be restricted to an allowlist of expected destinations rather than filtered by keyword, since keyword matching on javascript was bypassed with an encoded tab.

Variants to test

  1. Send any redirect or return-URL parameter twice with different values and see whether the server checks the first while the client uses the last. A positive result is a redirect to the second value.
  2. Try the same duplicate-parameter trick on other parameters that feed client-side logic, such as next, redirect, url or return. A positive result is the client acting on a value the server did not validate.
  3. Probe keyword filters with characters the browser ignores in a scheme, such as an encoded tab (%09) or other encoded whitespace. A positive result is a 200 response where the plain keyword returned 400, with the script still executing.
  4. Test case variations of the blocked keyword (javaScript, xjavascript, javaxscript) to map what the filter matches. A positive result is any variant that passes validation and still executes.
  5. Chain the redirect into a same-origin fetch of an authenticated endpoint, as in the proof of concept, to confirm whether user data is readable. A positive result is the endpoint returning the victim's data to the injected script.

Glossary

  • Web application: a program you use through a browser, where a server sends pages and code that the browser runs.
  • URL: the address of a page, made of scheme, host, path and optional query string.
  • Origin: the combination of scheme, host and port that defines which website a page belongs to.
  • Query string: the part of a URL after ?, holding parameters.
  • Parameter: a name and value pair in a query string, written name=value and separated by &.
  • Endpoint: a specific address on a server that performs a specific job.
  • JavaScript: the programming language that runs in the browser and makes pages interactive.
  • Source code review: reading an application's code to look for security mistakes.
  • Open redirect: a weakness where a site sends users to a destination taken from the URL without proper checking.
  • XSS (cross-site scripting): a weakness where an attacker's JavaScript runs inside a trusted website in a victim's browser.
  • Parameter pollution: sending the same parameter name more than once so different parts of a system disagree about which value counts.
  • Session: how a site remembers that you are logged in.
  • Cookie: a small piece of data the browser stores for a site and sends with requests, often used to carry a session.
  • Token: a secret string used to prove identity or authorise a request.
  • Bug bounty program: a company's offer to pay researchers who report security problems.
  • Bugcrowd: a platform that runs bug bounty programs.
  • Triaged: reviewed and confirmed by the program's staff.
  • 404: the standard response meaning the requested page was not found.
  • 400 Bad Request: the standard response meaning the request was malformed or unacceptable.
  • 200 OK: the standard response meaning the request was accepted.
  • Regular expression: a pattern-matching tool used to find text that fits a rule.
  • URL encoding: writing unsafe characters as a percent sign plus two hexadecimal digits, such as %09 for a tab.
  • javascript: scheme: a URL scheme that tells the browser to run the text after it as JavaScript.
  • fetch: a browser function that sends a request to a server and returns the response.
  • JSON: a common text format for structured data.
  • Console: a panel in the browser's developer tools where messages and errors are shown.
  • Allowlist: a list of values that are explicitly permitted, with everything else refused.

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.