Story of URI based XSS with some simple google dorking
A redirect parameter accepted a javascript URI, leading to cross-site scripting when a logged-in user visited the crafted link. An attacker could execute script in the victim's browser to phish, steal cookies, or log keystrokes.
Published on medium.com
{{media:0}}
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
This is an account of an XSS bug found in a private HackerOne program. Because the program was private, the researcher refers to the site throughout as www.example.com. The program looked old but had a wide scope covering a number of domains. The vulnerable feature is a redirect endpoint on the social path, which takes a redirect parameter and sends the user to the location given in that parameter.

Setup
No special tooling is described beyond Google search and a browser. The researcher had an account on the site, since the payload only fired after logging in. The attack path described is that the victim is sent to the crafted URL and logs in, after which the payload fires.
Finding it
Rather than starting on the main domain, which the researcher expected many others had already tested, the work began on the other domains in scope. Initial testing on those turned up nothing useful. The next step was Google dorking, using the following query:
Site:*.example.com inurl:redirect
This was combined with various appended terms such as intext: ../index, admin, sql, url and redirect. Using redirect in the inurl parameter surfaced an interesting endpoint:
example.com/social?redirect=/somewhere
The endpoint takes a destination in the redirect parameter, which is what made it worth probing.
Exploitation
Step 1: confirm the redirect works
The first test was to point the parameter at an external site. Redirecting to google.com worked, confirming that the endpoint would send the browser to an arbitrary location supplied by the user.
Step 2: try a javascript URI
With an open redirect confirmed, the researcher considered that a JavaScript URI parser handling the value could lead to XSS, and supplied this payload in the redirect parameter:
example.com/social?redirect=javascript://alert(1)
At this point the site sent the browser to the login page, because the researcher was not logged in.
Step 3: log in and observe execution
After logging in, the alert popped up. After logging in, the alert popped up, showing the payload executed once the user was authenticated.
Step 4: the logout path
The researcher also notes that there was no protection on logout: a user could be logged out of their account and then sent again to the malicious URL. When the user enters their credentials, the XSS executes.
The same endpoint was present on some other domains belonging to the program, so those were vulnerable as well.
The program responded quickly and paid a reward.
Root cause
The redirect parameter accepts a javascript: value, which the browser then executes as script. A value beginning with javascript: is accepted and followed, so the browser executes it as script in the origin of the site rather than treating it as a plain URL. The redirect to google.com shows that arbitrary external destinations were already allowed, which is the same missing validation seen from another angle. The report does not describe the server-side code, so the exact parsing and validation logic is not known.
Impact
An attacker who can get a victim to follow a crafted social?redirect= link can run script in the victim's session on the site. The researcher lists phishing, cookie stealing and keylogging as possible uses. The attack works when the victim is logged in, or when the victim is logged out and then logs in after being sent to the malicious URL, since the payload fires after authentication. Because the same endpoint existed on other domains in the program, the issue affected more than one host.
Fix
The report does not state what change was made. The natural fix, given the behaviour described, is to validate the redirect value against an allowlist of permitted destinations and schemes, rejecting anything that is not a plain http or https URL to an expected host, so that values such as javascript://alert(1) are never followed.
Variants to test
- Run the same dork pattern against other scopes, for example
Site:*.example.com inurl:redirect, and also try the termsurl,next,redirect_to,pageandsiteininurl. A positive result is any endpoint that visibly takes a destination from the query string. - On each such endpoint, first try an external destination to confirm the redirect is open, then try a
javascript:URI in the same parameter. A positive result is script execution in the site's origin after authentication. - Check the logout flow: log out, then follow the crafted URL and log in. A positive result is the payload firing after the credentials are submitted.
- Test the same endpoint on every domain in scope, since the report found the endpoint replicated across several domains of the program.
- The researcher notes that these parameters can also lead to SSRF where sanitisation is missing, so watch for server-side fetches of the supplied destination as a further signal.
What happened, in plain words
A security researcher found a bug on a private bug bounty program on HackerOne. The bug let an attacker run their own JavaScript code in another user's browser on the site. This kind of bug is called cross-site scripting, or XSS. The researcher found it by using Google to search for certain patterns in URLs, a technique called Google dorking. The site is referred to as www.example.com because the program was private. The researcher reported it, the program responded quickly, and paid a reward.

The site and the feature
The program covered many domains, and the researcher chose to look at the less obvious ones first, thinking that the main domain had probably been tested by many others. The vulnerable feature was a redirect endpoint on the social path. A redirect endpoint is a page that takes a destination from the URL and sends your browser there. For example, after you log in, a site might send you back to the page you came from. The endpoint looked like this:
example.com/social?redirect=/somewhere
Here, redirect is a parameter: the part of the URL after the question mark that carries a value. The value /somewhere is where the site will send you. The researcher suspected that if the site did not check that value carefully, it could be abused.
Finding the endpoint with Google dorking
Google dorking means using special search operators to find pages that normal searches hide. For example, site: limits results to a domain, and inurl: looks for a word inside the URL. The researcher used this query:
Site:*.example.com inurl:redirect
This asks Google for any page on any subdomain of example.com whose URL contains the word redirect. The researcher also tried adding other words with intext: and plain terms such as admin, sql, url and redirect. The query with redirect in the URL turned up the social?redirect= endpoint. That endpoint was interesting because it clearly takes a destination from the user.
Testing the redirect
Step 1: does it redirect anywhere?
The first test was to put an external site in the redirect parameter. The researcher tried google.com, and the browser went there. That confirmed the endpoint would send users to any location supplied in the URL. This is called an open redirect: a redirect that does not check where it is sending people.
Step 2: try JavaScript in the parameter
An open redirect is not XSS by itself, but it is a clue. If the site takes the value and treats it as a URL, maybe it will also accept a special kind of URL that runs code. Browsers understand URLs that start with javascript:. When a browser follows such a URL, it runs the text after the colon as JavaScript instead of loading a page. The researcher tried this payload:
example.com/social?redirect=javascript://alert(1)
alert(1) is a built-in browser function that shows a small pop-up with the number 1. It is a harmless way to prove that code ran.
When the researcher opened that URL, the site sent the browser to the login page, because the researcher was not logged in. That is normal: many sites require you to log in before they will process a redirect.
Step 3: log in and see the pop-up
After logging in, the alert popped up. After logging in, the alert popped up, showing that code from the URL ran in the site's context. In other words, the code ran as if it were part of example.com. This is the XSS.
Step 4: the logout path
The researcher also noticed that there was no protection on logout. A user could be logged out, then sent to the malicious URL, and when they entered their credentials, the XSS would execute. The payload fires after login, so the attacker does not need the victim to be logged in at the moment they click the link; they only need the victim to log in afterwards.
The same endpoint existed on some other domains in the program, so those were vulnerable too.
Why it works
The redirect parameter decides where to send the browser, and a javascript: value was accepted and executed. A value starting with javascript: is accepted and followed, so the browser runs it as code in the site's origin. The fact that google.com also worked shows the endpoint would send users to an external site. The report does not describe the server-side code, so we do not know exactly how the value is parsed.
What an attacker could do
If an attacker can get a victim to open a crafted social?redirect= link, they can run their own script in the victim's session on the site. The researcher lists phishing, cookie stealing and keylogging as possible uses. Phishing means showing a fake login form to steal credentials. Cookie stealing means reading the browser's cookies, which often contain a session token that keeps you logged in. Keylogging means recording what the victim types. The attack works when the victim is logged in, or when they log in after being sent to the malicious URL.
How to fix it
The report does not say what change the site made. A sensible fix is to check the redirect value against a list of allowed destinations and schemes, and reject anything that is not a plain http or https URL to an expected host. That way, values such as javascript://alert(1) are never followed.
Variants to test
- Run the same dork pattern on other scopes, for example
Site:*.example.com inurl:redirect, and also try the termsurl,next,redirect_to,pageandsiteininurl. A positive result is any endpoint that visibly takes a destination from the query string. - On each such endpoint, first try an external destination to confirm the redirect is open, then try a
javascript:URI in the same parameter. A positive result is script execution in the site's origin after authentication. - Check the logout flow: log out, then follow the crafted URL and log in. A positive result is the payload firing after the credentials are submitted.
- Test the same endpoint on every domain in scope, since the report found the endpoint replicated across several domains of the program.
- The researcher notes that these parameters can also lead to SSRF where sanitisation is missing, so watch for server-side fetches of the supplied destination as a further signal. SSRF means server-side request forgery: the server itself makes a request to a destination chosen by the attacker.
Glossary
- XSS (cross-site scripting): a bug where an attacker can make a website run their own JavaScript in another user's browser.
- Redirect endpoint: a page that takes a destination from the URL and sends the browser there.
- Parameter: the part of a URL after the question mark that carries a value, such as
redirect=/somewhere. - Google dorking: using special search operators like
site:andinurl:to find pages that normal searches hide. - Open redirect: a redirect that does not check where it is sending people, so it can send them anywhere.
- JavaScript URI: a URL that starts with
javascript:; when followed, the browser runs the text after the colon as code. alert(1): a browser function that shows a pop-up with the value 1, often used to prove that code ran.- Session: the period during which a site remembers that you are logged in, usually via a cookie or token.
- Cookie: a small piece of data a site stores in your browser, often used to keep you logged in.
- Token: a value that proves who you are, often stored in a cookie.
- Phishing: tricking someone into entering their credentials on a fake page.
- Cookie stealing: reading a victim's cookies, often to take over their session.
- Keylogging: recording what a victim types.
- SSRF (server-side request forgery): a bug where the server itself makes a request to a destination chosen by the attacker.
- Sanitisation: checking and cleaning input so that dangerous values are rejected or made safe.
- Allowlist: a list of values that are explicitly permitted; anything not on the list is rejected.
- Scheme: the first part of a URL, such as
http,httpsorjavascript, that tells the browser how to handle it. - Origin: the combination of scheme, host and port that defines a site's security boundary; code running in an origin can access that origin's data.