Skip to content
XSS Disclosed report Beginner CVE-2024-28866

XSS in new.loading.page.html

aviv_keller Follow

Originally disclosed on HackerOne

  • Triaged in 5 hours
  • Fixed in 15 hours
  • Disclosed after 16 hours

Summary by the researcher

Exploiting a vulnerability rooted in inadequate handling of query parameters within the new.loading.page.html file, attackers can manipulate the URL query to insert javascript: URIs. By triggering the redirectToLanding function with a crafted URL parameter like ?redirect_to=javascript:alert("XSS"), the vulnerable code executes the injected script, leading to Cross-Site Scripting (XSS) exploitation.

The report

Overview

The vulnerability arises from inadequate handling of query parameters, enabling attackers to insert javascript: URIs as redirectors within the new.loading.page.html file.

JavaScript
var redirectToLanding = function() {
  var locationData = window.location.search.match(/(\?|&)redirect_to=([^&]+)(&|$)/);
  if (locationData === null) {
    window.location.reload(true);
  } else {
    window.location = decodeURIComponent(locationData[2]);
  }
}

View Permalink

When the URL's query is ?redirect_to=javascript:alert("XSS"), locationData[2] equals 'javascript:alert("XSS")'. Subsequently, triggering redirectToLanding leads to XSS exploitation.

Impact

Attackers can inject javascript: URIs to execute unauthorized scripts, potentially stealing sensitive information such as session cookies or performing actions on behalf of the user.

The original report as published on HackerOne, by aviv_keller. 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

GoCD is a continuous delivery server, and one of the files it ships is new.loading.page.html. One of these files is new.loading.page.html. The code in that file reads a redirect_to query parameter and assigns it to window.location; if the parameter is missing, it reloads the page.

The report describes a reflected cross-site scripting issue in that redirect logic.

Setup

No accounts, roles, tools or version numbers are described in the report. The only precondition is that a victim opens a crafted URL pointing at new.loading.page.html with a redirect_to query parameter, which is enough to reach the vulnerable function.

Finding it

The value of redirect_to is taken from the URL and assigned directly to window.location. There is no check on the scheme of the value, so a javascript: URI is accepted just like an ordinary path or URL. The relevant code is:

JavaScript
var redirectToLanding = function() {
  var locationData = window.location.search.match(/(\?|&)redirect_to=([^&]+)(&|$)/);
  if (locationData === null) {
    window.location.reload(true);
  } else {
    window.location = decodeURIComponent(locationData[2]);
  }
}

The function matches redirect_to= in the query string, either at the start of the query or after an ampersand, and captures everything up to the next ampersand or the end of the string. If there is no match, the page reloads. If there is a match, the captured value is URL-decoded and assigned to window.location. Because the assignment happens without any validation of the destination, the browser will follow whatever scheme the value uses.

Exploitation

Step 1: craft the URL

The attacker builds a URL for new.loading.page.html whose redirect_to parameter contains a javascript: URI:

Text
?redirect_to=javascript:alert("XSS")

Step 2: the parameter is parsed

When the page loads with that query string, the regular expression matches and locationData[2] holds the captured value, which equals 'javascript:alert("XSS")'. The value is passed through decodeURIComponent, which leaves it unchanged here.

Step 3: the redirect runs the script

When redirectToLanding is triggered, the decoded value is assigned to window.location. The browser treats the javascript: scheme as executable code rather than a navigation target, so the injected script runs. The report uses alert("XSS") as the demonstration payload; the same mechanism would run any script the attacker supplies.

Root cause

The mistake is that a user-controlled query parameter is used as a navigation target without validating its scheme. The regular expression only extracts the value; it does not restrict it to http, https or a relative path. decodeURIComponent is applied to the captured value, but decoding is not a security control and does nothing to stop a javascript: URI.

Impact

An attacker who gets a victim to open the crafted URL can execute arbitrary script in the context of the loading page. According to the report, this could be used to steal sensitive information such as session cookies or to perform actions on behalf of the user. The impact depends on the victim following the link and on what the script does once it runs; the report does not go beyond these general consequences.

Fix

The report does not describe a fix or a code change.

Variants to test

  1. Try other executable schemes in the same parameter, such as data: URIs, and see whether the browser navigates to them. A positive result is script execution in the page's origin.
  2. Try scheme variations that may bypass a naive allowlist, for example mixed case or leading whitespace before javascript:. A positive result is the same execution.
  3. Look for the same pattern in other loading pages or redirect helpers that read a query parameter and assign it to window.location. A positive result is any parameter whose value reaches a navigation sink without scheme validation.
  4. Check whether the parameter can be supplied through a fragment or a second parameter that the page later reads. A positive result is execution triggered by a URL the victim would plausibly click.

Hunting notes

This kind of bug tends to hide in small static helper pages: loading screens, error pages, logout pages and anything with a redirect_to, return, next or url parameter. During recon, grep the shipped JavaScript and HTML for assignments to window.location, location.href and location.replace where the right-hand side comes from location.search or a similar source. A match on a query parameter with no scheme check is the signal. The report uses a minimal alert payload reached through a single crafted URL.

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

What happened, in plain words

GoCD is a continuous delivery server: a piece of software that teams use to build and ship their own software automatically. One of the files it ships is a page called new.loading.page.html. One of those pages is a file called new.loading.page.html.

The code in that file reads a redirect_to value from the address bar and assigns it to window.location. If there is no such value, it reloads the page.

The researcher found that the page takes the redirect_to value straight from the address bar and hands it to the browser as a destination, without checking what kind of destination it is. Normally a destination is a web address starting with http or https. But browsers also understand a special kind of address starting with javascript:, which means "run the code that follows". Because the page does not check, an attacker can put code in that spot, and the browser will run it.

This class of bug is called reflected cross-site scripting, or reflected XSS. "Scripting" means running small programs (JavaScript) inside a web page. "Cross-site" means the code comes from an attacker rather than from the site itself. "Reflected" means the malicious value is not stored on the server; it travels in the link the victim clicks and is echoed straight back into the page. The report describes it as reflected XSS. CVSS is a standard scoring system for how serious a security flaw is; 3.1 out of 10 is on the low end.

Context

To follow this, you need a few everyday ideas.

  • A query parameter is the part of a web address after a question mark. In shop.example/item?colour=red, the parameter is colour and its value is red. Websites use these to pass small pieces of information from the address bar into the page.
  • JavaScript is the programming language that runs inside your browser and makes pages interactive. When a page "runs a script", it is executing JavaScript.
  • window.location is the browser's built-in way of knowing and changing which page you are on. If a script assigns a new address to window.location, the browser navigates there. Think of it as the steering wheel of the browser tab.
  • A URI scheme is the first part of an address, before the colon. https:// is the scheme for secure web pages, mailto: opens an email program, and javascript: tells the browser to run the text that follows as code.
  • A regular expression is a pattern used to search text. It is like a very precise find-and-replace rule: "find this shape of text and pull out part of it".

The problem lives in the browser, in the redirect logic of new.loading.page.html. The report describes a reflected XSS issue in the redirect logic of new.loading.page.html.

Setup

The report describes no accounts, roles, tools or version numbers. The only thing needed is a victim who opens a crafted link pointing at new.loading.page.html with a redirect_to query parameter. That is enough to reach the vulnerable function. In other words, the attacker does not need to log in anywhere or break into the server; they only need the victim to click.

Finding it

The value of redirect_to is taken from the address bar and assigned directly to window.location. Nothing checks the scheme of the value, so a javascript: address is accepted exactly like an ordinary path or web address. The relevant code is:

JavaScript
var redirectToLanding = function() {
  var locationData = window.location.search.match(/(\?|&)redirect_to=([^&]+)(&|$)/);
  if (locationData === null) {
    window.location.reload(true);
  } else {
    window.location = decodeURIComponent(locationData[2]);
  }
}

Line by line, in plain words:

  1. var redirectToLanding = function() { defines a function named redirectToLanding. A function is a named block of instructions that can be run later, whenever something calls it.
  2. var locationData = window.location.search.match(/(\?|&)redirect_to=([^&]+)(&|$)/); looks at the query string of the current address (window.location.search, the part starting with ?) and searches it with a regular expression. The pattern means: find either a ? or an &, then the literal text redirect_to=, then capture one or more characters that are not & (that is the ([^&]+) part), then either an & or the end of the string. The result is stored in locationData. If the pattern is found, locationData is a list where the third item, locationData[2], is the captured value.
  3. if (locationData === null) { asks: did the search find nothing? If so, there is no redirect_to in the address.
  4. window.location.reload(true); then reloads the current page. This is the "no destination given, just refresh" behaviour.
  5. } else { covers the case where a redirect_to value was found.
  6. window.location = decodeURIComponent(locationData[2]); takes the captured value, runs it through decodeURIComponent, and assigns it to window.location. decodeURIComponent turns encoded characters back into normal ones; for example, %20 becomes a space. It is a formatting step, not a safety check.
  7. The closing braces end the else block and the function.

The key point is line 6: whatever text was captured is handed to the browser as a destination, with no check on what kind of address it is. Because of that, the browser will follow whatever scheme the value uses, including javascript:.

Exploitation

Step 1: craft the URL

The attacker builds a link to new.loading.page.html whose redirect_to parameter contains a javascript: address:

Text
?redirect_to=javascript:alert("XSS")

alert("XSS") is a built-in browser function that pops up a small dialog box showing the text XSS. It is the classic harmless demonstration payload: it proves that code ran, without doing any damage. The attacker's goal at this stage is simply to get that text into the address bar in a place the page will read.

Step 2: the parameter is parsed

When the page loads with that query string, the regular expression matches, and locationData[2] holds the captured value, which equals 'javascript:alert("XSS")'. The value is passed through decodeURIComponent, which leaves it unchanged here because there is nothing encoded in it. This step matters because it shows the page really does pick the value out of the address bar and prepare it for use, exactly as designed; the design is what is flawed.

Step 3: the redirect runs the script

When redirectToLanding is triggered, the decoded value is assigned to window.location. The browser sees the javascript: scheme and treats what follows as code to execute rather than as an address to visit. The injected script therefore runs. "Origin" here means the combination of scheme, host and port that the browser uses to decide which page is allowed to touch which data; code running in the page's origin is treated as if it came from that site. The report uses alert("XSS") as the demonstration payload; the same mechanism would run any script the attacker supplies.

Root cause

The mistake is that a value controlled by whoever writes the link is used as a navigation target without checking its scheme. The regular expression only extracts the value; it does not restrict it to http, https or a relative path. decodeURIComponent is applied to the captured value, but decoding is not a security control and does nothing to stop a javascript: address. A Content Security Policy is a set of rules a site can send to the browser saying which scripts are allowed to run; a strict one can stop injected code even when it reaches the page.

Impact

An attacker who gets a victim to open the crafted link can run arbitrary script in the context of the loading page. According to the report, this could be used to steal sensitive information such as session cookies, or to perform actions on behalf of the user. A session cookie is a small piece of data the browser stores after you log in, and it is what tells the site "this is still the same logged-in person". If someone else gets hold of it, they can often act as you without knowing your password. The impact depends on the victim following the link and on what the script does once it runs; the report does not go beyond these general consequences.

Fix

The report does not describe a fix or a code change. In everyday terms: before turning the steering wheel, check that the destination is a real road and not a trapdoor.

Variants to test

These are follow-up ideas for someone hunting similar bugs. Each one asks: does the same unchecked hand-off happen somewhere else?

  1. Try other executable schemes in the same parameter, such as data: addresses, and see whether the browser navigates to them. A data: address carries its content inline, and some browsers will run script from it. A positive result is script execution in the page's origin.
  2. Try scheme variations that may bypass a naive allowlist, for example mixed case or leading whitespace before javascript:. An allowlist is a list of things that are permitted; a naive one might compare text exactly and miss a disguised version. A positive result is the same execution.
  3. Look for the same pattern in other loading pages or redirect helpers that read a query parameter and assign it to window.location. A positive result is any parameter whose value reaches a navigation sink without scheme validation. A "sink" is the place where data finally gets used in a way that matters, here the assignment that makes the browser navigate.
  4. Check whether the parameter can be supplied through a fragment or a second parameter that the page later reads. The fragment is the part of an address after #, which is normally not sent to the server but is readable by scripts in the page. A positive result is execution triggered by a link the victim would plausibly click.

Hunting notes

This kind of bug tends to hide in small static helper pages: loading screens, error pages, logout pages and anything with a redirect_to, return, next or url parameter. These pages are easy to overlook because they look trivial, yet they often take a value from the address bar and act on it.

During recon, search the shipped JavaScript and HTML for assignments to window.location, location.href and location.replace where the right-hand side comes from location.search or a similar source. Recon means the early information-gathering stage of a security review. A match on a query parameter with no scheme check is the signal. The report uses a minimal alert payload reached through a single crafted link.

Glossary

  • GoCD: a continuous delivery server, software that automates building and releasing other software.
  • Continuous delivery: a way of working where software changes are automatically tested and prepared for release.
  • Static page: a plain HTML and JavaScript file served as-is, with no server-side logic generating it.
  • Query parameter: the name=value pairs after the ? in a web address.
  • JavaScript: the programming language that runs inside web browsers.
  • window.location: the browser object that represents the current address and lets scripts navigate to another one.
  • URI scheme: the part of an address before the colon, such as https:, mailto: or javascript:, which tells the browser how to handle it.
  • javascript: URI: an address whose scheme tells the browser to run the text that follows as code.
  • data: URI: an address that carries its content inline rather than pointing to a server.
  • Regular expression: a pattern used to find and extract text.
  • decodeURIComponent: a JavaScript function that turns percent-encoded characters back into normal ones; it is formatting, not a security check.
  • Reflected XSS: cross-site scripting where the malicious value travels in the link the victim clicks and is echoed straight back into the page.
  • Cross-site scripting (XSS): a flaw that lets an attacker run their own script inside a page of a site they do not control.
  • Origin: the combination of scheme, host and port that the browser uses to decide which page may access which data.
  • Payload: the piece of input an attacker supplies to trigger a bug; here, the javascript: address.
  • alert(): a browser function that shows a small dialog box, commonly used to prove that script ran.
  • Session cookie: a small piece of data stored by the browser after login that identifies the logged-in user.
  • CVSS: a standard scoring system for the severity of security flaws, from 0 to 10.
  • Severity: a rough rating of how serious a flaw is, here low.
  • Content Security Policy: rules a site can send to the browser saying which scripts are allowed to run.
  • Allowlist: a list of values that are explicitly permitted.
  • Sink: the place in code where data is finally used in a way that can cause harm, such as a navigation assignment.
  • Recon: the information-gathering stage of a security review.
  • Fragment: the part of a web address after #, readable by scripts in the page but normally not sent to the server.

More by aviv_keller

View all

3 more disclosed reports, best first.

More from GoCD

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.