From Open Redirect to Reflected XSS manually
A URL parameter used for redirection could be abused to redirect users to an external site, and by using a javascript: scheme, an attacker could execute arbitrary JavaScript in the victim's browser.
I had managed to bypass the character filter! And when I loaded the url, I was redirected to www.google.com, which means the “url” parameter was vulnerable to open redirect!
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.
From Open Redirect to Reflected XSS manually
Context
The target is a single web application, referred to throughout as redacted.com to protect the company. The write-up does not describe the product or the business behind it. What matters is a feature that takes a url parameter and uses it to send the browser somewhere else: the application reads the value of url and assigns it to window.location.href, so the parameter is meant to drive a redirect.
The researcher found two issues in that feature: an open redirect, and, once the redirect could be pointed at a javascript: URL, a reflected XSS. The write-up defines both concepts up front.
An open redirect happens when an application incorporates user-controllable data into the target of a redirection in an unsafe way. An attacker can build a URL on the application that redirects to an arbitrary external domain, which can be used to make phishing links against the application's users more convincing.
A reflected XSS happens when user input is returned immediately by the application, in an error message, a search result or any other response that includes some or all of the input from the request, without that data being made safe to render in the browser and without being stored permanently.
Setup
The write-up names no accounts, roles, versions or special tooling. The only tool described is the browser: the network tab of the dev tools was used to watch the requests the page makes. The testing was manual throughout, and the researcher describes the whole exercise as a manual hunt. A second researcher, ferreiraklet, was hunting in another part of the application at the same time and contributed the XSS step.
Finding it
- With the network tab of dev tools open, the researcher reloaded the page and noticed unusual .js files being requested by the application.
- Four JavaScript files were being called consecutively, one after the other. Their names were of the form
0.js,5.js,4.jsand so on. - Requesting
5.jsreturned a 404 status code. The others, including0.jsand4.js, returned 200 and could be read. - Reading
0.jsby hand, the researcher found a parameter that received anhrefvalue in the application, similar to this:
window.location.href("?url=");
The presence of a parameter called url was the signal: if the application takes that value and puts it into a redirect target, a request carrying an external URL in url should send the browser off-site. That is what the researcher tested next.
Exploitation
Step 1: try the obvious redirect
The parameter was appended after the root directory /, with an external URL as its value:
Nothing happened. The plain external URL in url did not produce a redirect.
Step 2: work around the character filter
The researcher recalled that, a few hours earlier while analysing the same subdomain, certain characters had made a difference when placed inside the value of parameters being tested. That suggested a character filter on the value. The bypass was found manually, and the payload that worked was:
?url=https://www.google.com/%3C--//#/
Loading that URL redirected the browser to www.google.com. The url parameter was therefore vulnerable to open redirect. The payload that worked appended %3C--//#/ after the external URL, and loading it redirected the browser to www.google.com.
Step 3: escalate to reflected XSS
Because a URL including the http protocol could be placed after the url parameter, the next question was whether other schemes would be accepted. ferreiraklet, hunting in another part of the application, found a way to get XSS by calling the javascript: scheme, which executes whatever follows the colon as JavaScript. The reflected XSS payload is:
?url=javascript:confirm(document.domain)%3C--//#/
This keeps the same filter bypass suffix, %3C--//#/, but replaces the http URL with javascript:confirm(document.domain). The payload calls javascript:confirm(document.domain), which would execute the JavaScript after the colon.
That is the full chain: a vulnerable parameter found by reading a JavaScript file, an open redirect, and an escalation to reflected XSS.
Root cause
The application takes user-controllable input from the url parameter and feeds it to window.location.href, with only a bypassable character filter in front. Two weaknesses follow from that.
First, the value is not constrained to the application's own domain, so any external URL is accepted and the browser is sent there. Second, the value is not constrained by scheme, so javascript: is accepted alongside http, and the browser executes it in the context of the application's origin.
A character filter existed, since the plain https://www.google.com/ value did nothing, but it was bypassable with a short suffix. The write-up does not describe how the filter was implemented, so the exact check it performed is not known; the bypass shows that whatever it matched could be satisfied while the browser still resolved the value to an external destination and, later, to a javascript: URL. A scheme and host allowlist on the url value would have stopped both issues.
Impact
An attacker can construct a link on the application's own domain that redirects the victim to an arbitrary external site. Because the link starts at the trusted application, it can be used to facilitate phishing against the application's users.
With the javascript: variant, the same link executes script in the application's origin. The demonstration payload only calls confirm(document.domain), but the write-up does not explore what else could be done from that position. Exploitation requires the victim to load the crafted URL.
Fix
Relying on a character filter is not enough, as the bypass in this report shows.
Variants to test
- Client-side redirect parameters. Look for parameters whose value ends up in
window.location,location.hreforlocation.assign. A positive result is a request carrying an external URL inurlthat lands on the external site. - Filter bypass suffixes. When the plain external URL is blocked, try appending encoded and structural characters, as with
%3C--//#/here. A positive result is a redirect that still reaches the external host. - Scheme switching. Once an
httpURL is accepted, tryjavascript:with a harmless proof such asconfirm(document.domain). A positive result is the dialog appearing on the application's page. - JavaScript files loaded by the page. Read the
.jsfiles the application requests and look for parameters passed to redirect or navigation APIs. A positive result is a parameter name you can then test in the URL. - Other schemes. Try
data:,vbscript:and protocol-relative values such as//www.google.com/against the same parameter. A positive result is navigation or execution that the application did not intend.
What happened, in plain words
A security researcher was looking at a website (called redacted.com here to protect the company) and found a feature that takes a value from the address bar and uses it to send your browser somewhere else. The feature reads a parameter called url and hands its value to a piece of browser machinery called window.location.href, which is the instruction a page uses to navigate. Because the site passed the url value into a redirect without a proper check, the researcher could make it send visitors to an external site. That is an open redirect.
Then the researcher, together with a second researcher called ferreiraklet, found that the same feature would also accept a javascript: value. A javascript: value is not a web address at all: it is a small program, and the browser runs it. So the same link that redirected you could instead run code on the site's own page. That is a reflected XSS.
Neither issue needed special software. The whole hunt was done by hand in a normal browser, mostly by watching which files the page loaded and reading one of them.
The two ideas you need first
Before the steps, two definitions, because the rest of the story is built on them.
Open redirect
An open redirect is when a website takes something the user controls (here, the url value in the address bar) and uses it, without checking it, as the place to send the browser next. The result is a link that starts on the trusted site but ends on any site the attacker chooses.
Why does that matter? Because people trust links that begin with a familiar domain. A phishing link that starts with the real company's address looks far more convincing than a link to a random domain. The redirect does the attacker's trust-laundering for them.
Reflected XSS
XSS stands for Cross-Site Scripting. A reflected XSS happens when a website takes input from a request and immediately puts it back into the page it returns (in an error message, a search result, or any other response that echoes the input), without making that input safe to display in a browser, and without storing it anywhere.
The word reflected is the key: the input bounces straight back in the same response. The word scripting is the danger: if the echoed input can contain code, the browser runs that code as if the website itself had written it.
Setting the scene
The write-up does not describe the product or the business behind redacted.com. What matters is one feature: it takes a url parameter and uses it to send the browser elsewhere. The application uses the value of url in a window.location.href call, so the parameter appears to drive a redirect.
No accounts, roles, software versions or special tools are named. The only tool described is the browser itself, specifically the network tab of the dev tools. Dev tools are the panel built into every modern browser (usually opened with F12) that lets you inspect what a page is doing. The network tab lists every request the page makes: every image, script, font and data call, with its address and its result. It is like a receipt for everything the page fetched.
The testing was manual throughout. A second researcher, ferreiraklet, was hunting in another part of the application at the same time and contributed the XSS step.
Finding it
- With the network tab of dev tools open, the researcher reloaded the page and noticed unusual .js files being requested by the application.
- Four JavaScript files were being called consecutively, one after the other. Their names were of the form
0.js,5.js,4.jsand so on. - Requesting
5.jsreturned a 404 status code. The others, including0.jsand4.js, returned 200 and could be read. - Reading
0.jsby hand, the researcher found a parameter that received anhrefvalue in the application, similar to this:
window.location.href("?url=");
What each part means:
windowis the browser's object for the current tab. It is the handle the page uses to talk to the browser itself.locationis the part ofwindowthat knows (and can change) which address the tab is showing.hrefis the actual address string.- Assigning to
window.location.hrefis the standard way a page says "go to this address now". It is the same as typing an address in the bar and pressing Enter. - The
"?url="string shows the page is building that address from a parameter namedurl.
A JavaScript file (.js) is a text file of instructions the browser downloads and runs. A 404 means the server could not find the file; a 200 means it was found and delivered. The 404 on 5.js meant the server could not find that file.
The presence of a parameter called url was the signal. If the application takes that value and puts it into a redirect target, then a request carrying an external URL in url should send the browser off-site. That is what the researcher tested next.
Exploitation
Step 1: try the obvious redirect
The parameter was appended after the root directory /, with an external URL as its value:
Line by line:
https://redacted.com/is the site being tested.?starts the query string, the part of a URL that carries parameters.url=names the parameter the researcher found in0.js.https://www.google.com/is the value being handed to it, an ordinary external site used as a harmless destination.
The reasoning: if the site blindly forwards whatever is in url, the browser should end up at Google.
Nothing happened. The plain external URL in url did not produce a redirect. Something was checking the value and refusing it.
Step 2: work around the character filter
The researcher recalled that, a few hours earlier while analysing the same subdomain, certain characters had made a difference when placed inside the value of parameters being tested. That suggested a character filter: a check that looks for particular characters or patterns in the input and blocks the request if it finds them. Think of it as a bouncer with a list of banned words, rather than a proper identity check.
The bypass was found manually, and the payload that worked was:
?url=https://www.google.com/%3C--//#/
What is in it:
?url=is the same parameter as before.https://www.google.com/is still the destination.%3Cis the URL-encoded form of the<character. URLs cannot contain raw<, so it is written in percent-encoding, the scheme where a character is replaced by%plus its code.--is two hyphens.//is a double slash.#starts the fragment, the part of a URL after the hash that browsers treat as a position within the page and do not send to the server./closes the value.
Loading that URL redirected the browser to www.google.com. The url parameter was therefore vulnerable to open redirect. The payload that worked appended %3C--//#/ after the external URL, and loading it redirected the browser to www.google.com.
Why would that work? The write-up does not describe how the filter was implemented, so the exact check it performed is not known. What the bypass shows is that whatever the filter matched could be satisfied while the browser still resolved the value to an external destination. The lesson for a beginner: a filter that looks for a pattern is not the same as a rule about where the browser may go.
Step 3: escalate to reflected XSS
Because a URL including the http protocol could be placed after the url parameter, the next question was whether other schemes would be accepted. A scheme is the part of a URL before the colon: http, https, ftp, mailto and so on. It tells the browser what kind of address follows and how to handle it.
ferreiraklet, hunting in another part of the application, found a way to get XSS by calling the javascript: scheme, which executes whatever follows the colon as JavaScript. The reflected XSS payload is:
?url=javascript:confirm(document.domain)%3C--//#/
Line by line:
?url=is the same parameter.javascript:is the scheme. It tells the browser that what follows is code, not an address.confirm(...)is a built-in browser function that shows a small dialog box with a message and an OK button. It is a harmless way to prove code ran.document.domainis the domain of the current page. Putting it insideconfirmmakes the dialog display which site the code is running on, which proves the code runs in the application's own context rather than somewhere unrelated.%3C--//#/is the same filter bypass suffix as before.
This keeps the same filter bypass suffix, %3C--//#/, but replaces the http URL with javascript:confirm(document.domain). The payload calls javascript:confirm(document.domain), which would execute the JavaScript after the colon.
Origin here means the combination of scheme, host and port that the browser uses to decide what a page is allowed to touch. Code running in the application's origin is treated as the application's own code. That is why an XSS is serious: the browser has no way to tell the difference between the site's script and an attacker's script once both are running from the same origin.
That is the full chain: a vulnerable parameter found by reading a JavaScript file, an open redirect, and an escalation to reflected XSS.
Root cause
The application takes user-controllable input from the url parameter and feeds it to window.location.href, with only a bypassable character filter in front. Two weaknesses follow from that.
First, the value is not constrained to the application's own domain, so any external URL is accepted and the browser is sent there. Second, the value is not constrained by scheme, so javascript: is accepted alongside http, and the browser executes it in the context of the application's origin.
A character filter existed, since the plain https://www.google.com/ value did nothing, but it was bypassable with a short suffix. A scheme and host allowlist on the url value would have stopped both issues.
An allowlist is the opposite of a blocklist: instead of naming what is forbidden, you name exactly what is permitted and reject everything else. It is the difference between "no known bad words" and "only these people may enter".
Impact
An attacker can construct a link on the application's own domain that redirects the victim to an arbitrary external site. Because the link starts at the trusted application, it can be used to facilitate phishing against the application's users.
With the javascript: variant, the same link executes script in the application's origin. The demonstration payload only calls confirm(document.domain), but the write-up does not explore what else could be done from that position. Exploitation requires the victim to load the crafted URL.
That last point is worth pausing on for a beginner: this is not a bug an attacker triggers remotely against the server. The attacker has to get a person to click or open the crafted link. The redirect and the script both happen in that person's browser.
Fix
Relying on a character filter is not enough, as the bypass in this report shows.
In plain terms: decide up front where the browser is allowed to go, and refuse everything else. Do not try to spot bad input after the fact.
Variants to test
If you want to look for the same kind of bug yourself, these are the angles the write-up suggests.
- Client-side redirect parameters. Look for parameters whose value ends up in
window.location,location.hreforlocation.assign. A positive result is a request carrying an external URL inurlthat lands on the external site. - Filter bypass suffixes. When the plain external URL is blocked, try appending encoded and structural characters, as with
%3C--//#/here. A positive result is a redirect that still reaches the external host. - Scheme switching. Once an
httpURL is accepted, tryjavascript:with a harmless proof such asconfirm(document.domain). A positive result is the dialog appearing on the application's page. - JavaScript files loaded by the page. Read the
.jsfiles the application requests and look for parameters passed to redirect or navigation APIs. A positive result is a parameter name you can then test in the URL. - Other schemes. Try
data:,vbscript:and protocol-relative values such as//www.google.com/against the same parameter. A positive result is navigation or execution that the application did not intend.
A protocol-relative value like //www.google.com/ is one that borrows the scheme from the page it sits on: on an https page it means https://www.google.com/. It is a common way to slip past checks that only look for the literal http.
Glossary
- Open redirect: a flaw where a site sends the browser to a destination taken from user input without checking it, so the link can point anywhere.
- Reflected XSS: a flaw where input from a request is echoed straight back into the response and the browser runs it as code, without the input being stored.
- XSS (Cross-Site Scripting): the general class of flaws where an attacker gets code to run in another user's browser as if it came from the site.
- Parameter: a named value in a URL's query string, such as
urlin?url=.... - Query string: the part of a URL after
?, carrying parameters. - Fragment: the part of a URL after
#, handled by the browser and not sent to the server. - Scheme: the part of a URL before the colon (
http,https,javascript), telling the browser how to handle the address. window.location.href: the browser property holding the current tab's address; assigning to it navigates the tab.- JavaScript file (
.js): a text file of instructions the browser downloads and runs. - Dev tools: the inspection panel built into browsers; its network tab lists every request a page makes.
- Network tab: the dev tools view showing each request, its address and its result.
- Status code 200: the server found the requested resource and returned it.
- Status code 404: the server could not find the requested resource.
- Character filter: a check that blocks input containing certain characters or patterns; it can often be bypassed.
- Percent-encoding: writing a character as
%plus its code, such as%3Cfor<, because URLs cannot contain some characters raw. javascript:scheme: a URL scheme whose content is run as code by the browser.confirm(): a built-in browser function that shows a dialog with a message and an OK button.document.domain: the domain of the current page, readable from script running on it.- Origin: the scheme, host and port combination the browser uses to decide what a page may access; code in the same origin is treated as the site's own.
- Allowlist: a rule naming exactly what is permitted and rejecting everything else, as opposed to a blocklist of forbidden items.
- Phishing: tricking someone into trusting a link or page so they hand over information or run something harmful.
- Protocol-relative URL: an address starting with
//that borrows the scheme of the page it appears on. - Subdomain: a named subdivision of a domain, such as
shop.example.comunderexample.com. - Root directory: the
/path of a site, the starting point before any parameter is added.