Skip to content
XSS Disclosed report Beginner

Regression on dest parameter sanitization doesn't check scheme/websafe destinations

mrzheev Follow

Originally disclosed on HackerOne

Bounty$500 Medium 5.6 View original
  • Triaged in 11 hours
  • Fixed in 15 hours
  • Paid in 13 hours
  • Disclosed after 38 days

Hi team, I get Xss via javascript:alert() url on login page parameter dest=

###Payload Url Xss :

javascript:alert(document.domain);

##XSS Javascript URL ###Steps and reproduction :

##Proof of Concept (PoC) : https://www.reddit.com/login/?dest=javascript:alert(document.domain);

bandicam_2023-04-27_03-15-21-520.mp4 From the original on HackerOne

Reference : https://brightsec.com/blog/open-redirect-vulnerabilities/ https://hackerone.com/reports/1930763

Impact

When an attacker manages to perform a redirect in JavaScript, many dangerous vulnerabilities may occur. As Open Redirects are mostly used in phishing scams, people are not aware of the fact that Open Redirects can also be part of more complex attack chains where multiple vulnerabilities are exploited. And JavaScript-based Open Redirect is a key part of that chain. For example, redirecting the user to javascript: something() ends up being a dangerous Cross-Site Scripting injection. and the attacker can steal the victim's cookies

The original report as published on HackerOne, by mrzheev. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

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

Context

Reddit's login page accepts a dest parameter, which is meant to hold the destination the user should be sent to after a successful login. The parameter is visible in the URL as https://www.reddit.com/login/?dest=https%3A%2F%2Fwww.reddit.com%2F, where the value is a URL-encoded absolute URL. The report is a reflected XSS on www.reddit.com, rated medium with a CVSS score of 5.6, disclosed on 3 June 2023, with a bounty of 500 USD.

Setup

No special accounts, roles or tooling are described. The researcher used a browser; the proof-of-concept video is named bandicam_2023-04-27_03-15-21-520.mp4. The only precondition is that a victim logs in after opening a crafted login URL.

Finding it

The researcher noticed that the dest parameter on the login page could be set to a javascript: URL. The title of the report frames this as a regression: the sanitisation on dest does not check the scheme of the destination, so non-web ("websafe") destinations such as javascript: are accepted. The payload used is:

JavaScript
javascript:alert(document.domain);

Exploitation

Step 1: Open the login page with a normal destination

Using a browser, navigate to:

Text
https://www.reddit.com/login/?dest=https%3A%2F%2Fwww.reddit.com%2F

This is the legitimate form of the URL: dest holds a URL-encoded https://www.reddit.com/, the page the user would normally be redirected to after logging in.

Step 2: Replace the destination with a javascript: URL

Copy and modify the dest parameter so that the URL redirects to dest=javascript:alert(document.domain);. The full proof-of-concept URL is:

Text
https://www.reddit.com/login/?dest=javascript:alert(document.domain);

Step 3: Send the URL and log in

Send this URL in a new browser window. After login, the browser executes the javascript: destination and a pop-up appears, confirming the XSS is triggered.

bandicam_2023-04-27_03-15-21-520.mp4 From the original on HackerOne

Root cause

The dest parameter is used as a redirect target after login, but its scheme is not checked, so javascript: is accepted. Because javascript: is accepted as a destination, the redirect becomes script execution in the origin of www.reddit.com. The report's title calls this a regression. The report does not describe the server-side or client-side code involved, so the exact location of the missing check is not stated.

Impact

When an attacker can perform a redirect in JavaScript, the report argues, more dangerous vulnerabilities can follow. Open redirects are mostly used in phishing, but they can also be part of more complex attack chains, and a JavaScript-based open redirect is a key part of such a chain: redirecting the user to javascript: something() ends up being a dangerous cross-site scripting injection. In this case the attacker can steal the victim's cookies. The attack requires the victim to open the crafted login URL and complete a login, and the report does not discuss cookie flags or other mitigations that might limit cookie theft.

Fix

The report does not describe a fix or a change made by the program.

  1. Other schemes: try data:, vbscript: and mixed-case variants such as JaVaScRiPt: in the same parameter. A positive result is the browser executing the value after login.
  2. Encoding tricks: double-encode or partially encode the scheme (%6aavascript:, javascript%3A) and see whether the value is decoded before the redirect. A positive result is execution after decoding.
  3. Other redirect parameters: look for parameters with names like next, return, redirect, continue or url on login, logout and OAuth pages, and test the same javascript: payload. A positive result is an alert on the target origin.
  4. Client-side redirects: check whether the destination is applied through location.href or location.assign in JavaScript rather than through a server-side 302. A positive result is execution even when the server rejects the value.

This kind of bug tends to hide in post-login redirect parameters, which are often added for usability and validated less strictly than other inputs. During recon, look for login, logout and OAuth URLs that carry a destination parameter, and check whether the value is reflected into a redirect. The researcher demonstrated impact with a minimal proof of concept: a single URL that, after login, produces an alert on document.domain, recorded on video. That is enough to show script execution in the target origin without further escalation.

References

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

Reddit's login page has a feature that makes life easier for users. The login page carries a dest parameter (short for destination) in the address bar. That "where to go next" value is carried in the address bar as a parameter called dest (short for destination).

A security researcher found that this dest value was not checked carefully enough. The researcher discovered that it also accepted a special kind of address that starts with javascript:. When a browser is told to go to a javascript: address, it does not open a page: it runs the text after the colon as a small program. So by putting a small program into the dest value, the researcher could make the browser run that program on Reddit's own login page after the victim logged in. The program used was a pop-up showing the site's domain name, and the report says an attacker can steal the victim's cookies.

This kind of bug is called reflected cross-site scripting, or XSS. The report was rated medium severity with a CVSS score of 5.6, disclosed on 3 June 2023, and earned a bounty of 500 USD. The report's title calls it a regression.

The pieces you need to know

Before walking through the steps, here are the few ideas the report relies on.

  • URL parameter: the part of a web address after a question mark, made of name and value pairs. In ?dest=something, dest is the name and something is the value. Think of it like the "to" field on an envelope: the page reads it and acts on it.
  • URL encoding: some characters are not allowed raw in a web address, so they are written as a percent sign plus two characters. For example %3A means a colon : and %2F means a slash /. It is like spelling out a word letter by letter when the other person cannot hear you clearly.
  • Scheme: the first part of a web address, before the colon. https is a scheme, and so is javascript. The scheme tells the browser what kind of thing the address is: a web page to fetch, or a small program to run.
  • Redirect: when a site sends your browser somewhere else automatically. Like a receptionist pointing you to the right office instead of letting you wander.
  • Open redirect: a redirect where the destination is taken from user input without proper checking, so an attacker can choose where victims are sent.
  • XSS (cross-site scripting): a bug where an attacker manages to get their own code running inside a trusted website, in the browser of a victim. The browser cannot tell the difference between the site's own code and the injected code, so it trusts it.
  • Cookie: a small piece of data a website stores in your browser to remember who you are. The login session cookie is effectively a temporary key to your account, which is why stealing it matters.
  • document.domain: a way for a script running in a page to refer to the site it is running on. Showing it in a pop-up is a simple way to prove which site the code is executing on.

The finding

The researcher noticed that the dest parameter on the login page could be set to a javascript: address. The report frames this as a regression: the sanitisation on dest does not check the scheme of the destination, so non-web ("websafe") destinations such as javascript: are accepted. The payload used is:

JavaScript
javascript:alert(document.domain);

Line by line:

  • javascript: tells the browser that what follows is not a web page but a small program to run.
  • alert(...) is a built-in browser function that shows a pop-up box with a message.
  • document.domain is the site the page belongs to, so the pop-up proves the code is running as part of Reddit's own page rather than somewhere unrelated.
  • The trailing ; simply ends the statement, the way a full stop ends a sentence.

Reproducing it, step by step

Step 1: Open the login page with a normal destination

Using a browser, navigate to:

Text
https://www.reddit.com/login/?dest=https%3A%2F%2Fwww.reddit.com%2F

This is the legitimate form of the URL. Reading it piece by piece:

  • https://www.reddit.com/login/ is the login page itself.
  • ? starts the list of parameters.
  • dest= is the parameter name that holds the destination.
  • https%3A%2F%2Fwww.reddit.com%2F is the URL-encoded form of https://www.reddit.com/, the page the user would normally be sent to after logging in.

This step matters because it shows the feature working as intended. You first see the normal behaviour, so that when you change one thing you know exactly what caused the difference.

Step 2: Replace the destination with a javascript: URL

Copy and modify the dest parameter so that the URL redirects to dest=javascript:alert(document.domain);. The full proof-of-concept URL is:

Text
https://www.reddit.com/login/?dest=javascript:alert(document.domain);

Here the only change is the value of dest. Instead of a web address, it now holds the javascript: payload from above. The reason for trying this is simple: if the site blindly trusts whatever is in dest and later sends the browser there, then a javascript: value turns a redirect into code execution. The researcher is testing whether the site checks the scheme before using the value.

Step 3: Send the URL and log in

Send this URL in a new browser window. After login, the browser executes the javascript: destination and a pop-up appears, confirming the XSS is triggered.

bandicam_2023-04-27_03-15-21-520.mp4 From the original on HackerOne

The recording is named bandicam_2023-04-27_03-15-21-520.mp4.

Why it works

The dest parameter is used as a redirect target after login, but its scheme is not checked, so javascript: is accepted. An allowlist is a list of things that are permitted, and everything else is refused; here the list should contain only web schemes such as https. Because javascript: is accepted as a destination, the redirect becomes script execution in the origin of www.reddit.com. Origin means the combination of scheme, host and port that a browser uses to decide which page is allowed to touch which data, so code running in Reddit's origin is treated as Reddit's own code.

The report's title calls this a regression. The report does not describe the server-side or client-side code involved, so the exact location of the missing check is not stated.

What an attacker could do with it

When an attacker can perform a redirect in JavaScript, the report argues, more dangerous vulnerabilities can follow. Open redirects are mostly used in phishing, where a victim is sent to a lookalike page, but they can also be part of more complex attack chains, and a JavaScript-based open redirect is a key part of such a chain: redirecting the user to javascript: something() ends up being a dangerous cross-site scripting injection. In this case the attacker can steal the victim's cookies.

Stealing the session cookie is serious because that cookie is what tells Reddit "this browser is already logged in as this user". Anyone holding it can act as that user without knowing the password. The attack requires the victim to open the crafted login URL and complete a login, and the report does not discuss cookie flags or other mitigations that might limit cookie theft.

How it should be fixed

The report does not describe a fix or a change made by the program.

These are variations on the same idea, useful for checking whether a fix is complete or whether similar pages have the same weakness.

  1. Other schemes: try data:, vbscript: and mixed-case variants such as JaVaScRiPt: in the same parameter. A positive result is the browser executing the value after login. Mixed case matters because a naive check might compare text exactly and miss a differently capitalised version.
  2. Encoding tricks: double-encode or partially encode the scheme (%6aavascript:, javascript%3A) and see whether the value is decoded before the redirect. A positive result is execution after decoding. The idea is that a filter may inspect the encoded text, while the browser later decodes it and runs it.
  3. Other redirect parameters: look for parameters with names like next, return, redirect, continue or url on login, logout and OAuth pages, and test the same javascript: payload. A positive result is an alert on the target origin. The same feature is often copied across several pages.
  4. Client-side redirects: check whether the destination is applied through location.href or location.assign in JavaScript rather than through a server-side 302. A positive result is execution even when the server rejects the value. A 302 is the standard server response that means "go to this other address"; if the redirect happens in the browser's own JavaScript instead, the server's checks may never see the dangerous value.

This kind of bug tends to hide in post-login redirect parameters, which are often added for usability and validated less strictly than other inputs. During recon, look for login, logout and OAuth URLs that carry a destination parameter, and check whether the value is reflected into a redirect. The researcher demonstrated impact with a minimal proof of concept: a single URL that, after login, produces an alert on document.domain, recorded on video. That is enough to show script execution in the target origin without further escalation.

References

Glossary

  • URL parameter: a name and value pair in a web address after the question mark, used to pass information to a page.
  • URL encoding: writing special characters as a percent sign plus two characters, such as %3A for a colon, so they can travel safely inside a web address.
  • Scheme: the first part of a web address before the colon, such as https or javascript, which tells the browser what kind of address it is.
  • Redirect: an automatic instruction that sends the browser from one address to another.
  • Open redirect: a redirect whose destination comes from user input without proper checking, letting an attacker choose where victims go.
  • XSS (cross-site scripting): a bug where an attacker's code runs inside a trusted website in a victim's browser.
  • Reflected XSS: an XSS where the malicious value is sent in a request and immediately echoed back into the page, rather than being stored on the server.
  • Payload: the piece of text or code an attacker supplies to trigger a bug.
  • javascript: URL: an address whose scheme is javascript, causing the browser to run the text after the colon as a program instead of loading a page.
  • alert(): a browser function that shows a pop-up message, often used to prove that code ran.
  • document.domain: a way for a script to refer to the site the page belongs to.
  • Origin: the combination of scheme, host and port that the browser uses to decide which page may access which data.
  • Cookie: a small piece of data a site stores in the browser, often used to remember a logged-in session.
  • Session cookie: the cookie that identifies a logged-in user, effectively a temporary key to the account.
  • Sanitisation: cleaning or checking input so that dangerous values are removed or refused.
  • Allowlist: a list of permitted values, with everything not on the list rejected.
  • Regression: a bug that reappears because a fix or check that once existed has been lost or weakened.
  • CVSS score: a standard numeric rating of how severe a vulnerability is.
  • Bounty: a reward paid by a company to a researcher who reports a valid vulnerability.
  • 302: a standard server response meaning the browser should go to a different address.
  • location.href / location.assign: browser JavaScript ways of sending the page to another address.
  • OAuth: a common way for websites to let you log in or grant access through another service, often using redirects.
  • Recon: the research phase where you map out a site's pages and features before testing them.

More by mrzheev

View all

2 more disclosed reports, best first.

More from Reddit

View all

The newest disclosed reports for this program.

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.