Skip to content
XSS Disclosed report Beginner

XSS in GOCD Analytics Plugin

The analytics plugin reads the msg query parameter from the URL and inserts it into the page as HTML without sanitising it. An attacker could craft a link that runs script in the context of a server running the plugin, affecting the integrity and confidentiality of that server.

aviv_keller Follow

Originally disclosed on HackerOne

Medium 4.3 View original
  • Triaged in 7 hours
  • Fixed in 11 hours
  • Disclosed after 32 hours

Summary by the researcher

The gocd/gocd-analytics-plugin in info-message.js at line 28 contains a Cross-Site Scripting (XSS) vulnerability, which can be exploited via the ?msg= parameter. Attackers can inject malicious payloads, such as ?msg=%3Csvg%2Fonload%3Dalert%28%22XSS%22%29%20%3E, which inserts <svg/onload=alert("XSS") > into the webpage.

The report

gocd/gocd-analytics-plugin (info-message.js#L28) is vulnerable to XSS via the ?msg= parameter. By supplying an attack payload such as ?msg=%3Csvg%2Fonload%3Dalert%28%22XSS%22%29%20%3E, <svg/onload=alert("XSS") > will be injected into the webpage.

JavaScript
$(document).ready(function () {
  const msg = window.location.search.match(/[&?]msg=([^&]+)/);
  const msgText = msg ? decodeURIComponent(msg[1]) : "No data collected for this metric, cannot generate analytics.";

  $(document.body).html(Utils.infoMessage(msgText));
});

Utils.infoMessage basically just wraps msgText in a </p>

Impact

An attacker can run malicious code on servers running this plugin, comprising the integrity and confidentiality of such servers.

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

Context

GoCD is a continuous delivery server, and the analytics plugin (gocd/gocd-analytics-plugin) adds analytics views to it. One of the plugin's pages is an information message page, whose JavaScript lives in assets/js/pages/info-message.js. The page reads a message from the query string and renders it into the document body. That is the feature: a caller can pass text through the ?msg= parameter and have it displayed.

The vulnerability is a DOM-based cross-site scripting issue in that rendering path. The report rates it medium with a CVSS score of 4.3, and it was disclosed on 27 March 2024.

Setup

No accounts, roles, tools or version numbers are described in the report. The report describes no accounts, roles, tools or version numbers, and states no precondition beyond the vulnerable code itself.

Finding it

The researcher points at a specific line of the plugin source, info-message.js at line 28, and identifies the ?msg= parameter as the input that reaches it. The relevant code is:

JavaScript
$(document).ready(function () {
  const msg = window.location.search.match(/[&?]msg=([^&]+)/);
  const msgText = msg ? decodeURIComponent(msg[1]) : "No data collected for this metric, cannot generate analytics.";

  $(document.body).html(Utils.infoMessage(msgText));
});

Reading it top to bottom: the regular expression /[&?]msg=([^&]+)/ pulls the value of msg out of window.location.search, decodeURIComponent turns the percent-encoded value back into text, and then $(document.body).html(...) writes the result into the page as HTML. The report notes that Utils.infoMessage "basically just wraps msgText in a </p>", so the wrapper does not sanitise or escape anything; the decoded parameter value ends up in the HTML body.

Exploitation

Step 1: craft the payload in the query string

The researcher supplies an attack payload through the msg parameter:

Text
?msg=%3Csvg%2Fonload%3Dalert%28%22XSS%22%29%20%3E

Percent-decoding this value yields the markup below, which is what decodeURIComponent produces before the string is handed to .html():

HTML
<svg/onload=alert("XSS") >

Step 2: the payload is written into the DOM

Because the decoded value is passed to $(document.body).html(...), the <svg> element is parsed as HTML and inserted into the page. The onload handler on the element then fires, executing alert("XSS"). The report states plainly that <svg/onload=alert("XSS") > is injected into the webpage.

No HTTP request or response is shown in the report; the whole exchange happens in the browser between the URL and the DOM.

Root cause

The mistake is the use of .html() to insert a value that comes straight from the URL. The parameter is decoded and concatenated into the page as markup, with no encoding or sanitisation at any point: the regex only extracts the value, decodeURIComponent only reverses percent-encoding, and Utils.infoMessage only wraps the text in a </p>. None of these steps treats the input as untrusted text. The report does not describe any other defence, such as a Content Security Policy, that would have blocked the handler from running.

Impact

The report says an attacker can run malicious code on servers running this plugin, affecting the integrity and confidentiality of such servers. The report says an attacker can run malicious code on servers running this plugin, affecting their integrity and confidentiality. The report does not go further into what an attacker could reach from that position.

Fix

The report does not describe a fix or a change made in response.

Variants to test

  • Look for other places in the same plugin that read from window.location.search and pass the result to .html(), innerHTML, document.write or similar sinks. A positive result is a parameter value that appears as parsed markup in the DOM rather than as literal text.
  • Try other parameter names on the same page and on neighbouring pages of the plugin. A positive result is the same behaviour: the decoded value becomes an element and its event handler fires.
  • Check whether the wrapper function (Utils.infoMessage here) is reused elsewhere with untrusted input. A positive result is another call site where the wrapper's output reaches an HTML sink.
  • Test payloads that do not rely on onload, in case a filter blocks that specific attribute. A positive result is any injected element whose handler executes.

Hunting notes

This kind of bug hides in small client-side helpers that turn URL parameters into page content: message banners, error pages, info pages and anything that reads location.search or location.hash. During recon, JavaScript files that reference location.search, decodeURIComponent and .html( or innerHTML in the same function are the signal to follow. The researcher showed the payload and pointed to the vulnerable line.

Difficulty: beginner. The flaw is a short, readable DOM XSS in a single function, and the report demonstrates it with one encoded payload and the exact source line.

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

What happened, in plain words

GoCD is a server that helps software teams build and release their software automatically. It is a continuous delivery server: instead of a person copying files to a server by hand, GoCD runs the steps for them, again and again, in the same order. Teams can add extra features to GoCD through small add-on programs called plugins. The analytics plugin (gocd/gocd-analytics-plugin) is one of these add-ons: it adds pages that show statistics and charts about builds.

One of the plugin's pages is an information message page. Its job is simple: it shows a piece of text to the person looking at it. The text is not stored on the server; it is taken from the address bar of the browser. The page's JavaScript code lives in a file called assets/js/pages/info-message.js. When the page loads, that code reads a value called msg from the web address and puts it on the screen.

The problem is how it puts it on the screen. The page does not treat the value as plain text. It treats it as HTML, the language used to describe web pages. So if the value contains HTML tags, the browser does not show them as characters; it builds them into the page as real elements. An attacker can therefore put a small piece of code in the link, and the browser of anyone who opens that link will run it. This kind of bug is called cross-site scripting, or XSS. The specific type here is DOM-based XSS, because the dangerous step happens entirely inside the browser's page model (the DOM) and no server request is involved.

The report rates the issue as medium severity with a CVSS score of 4.3, and it was disclosed on 27 March 2024.

The product and the feature

GoCD is a continuous delivery server. Think of it as a robot that follows a recipe: fetch the code, build it, test it, put it on a server. The analytics plugin adds reporting pages on top of that, so a team can see how their builds have been going.

The information message page is a small helper page. Its feature is that a caller can pass text through the ?msg= parameter in the address and have that text displayed. A parameter is the part of a web address after a question mark, written as name=value. For example, in https://example.com/page?colour=blue, the parameter name is colour and its value is blue. The ?msg= parameter works the same way: whatever comes after msg= is the text the page should show.

That is a normal, useful design. The bug is not that the page accepts text from the address. The bug is that it inserts that text as HTML instead of as plain text.

Setup

The report does not describe any accounts, roles, tools or version numbers. The report describes no accounts, roles, tools or version numbers, and states no precondition beyond the vulnerable code itself. In other words: the plugin must be present on the GoCD instance, and a victim must open a crafted link to that page.

Finding it

The researcher points at a specific line of the plugin source, info-message.js at line 28, and identifies the ?msg= parameter as the input that reaches it. The relevant code is:

JavaScript
$(document).ready(function () {
  const msg = window.location.search.match(/[&?]msg=([^&]+)/);
  const msgText = msg ? decodeURIComponent(msg[1]) : "No data collected for this metric, cannot generate analytics.";

  $(document.body).html(Utils.infoMessage(msgText));
});

Line by line, in plain words:

  1. $(document).ready(function () { waits until the page has finished loading before running the code inside. This is a common pattern in JavaScript pages: do not touch the page until it exists.
  2. const msg = window.location.search.match(/[&?]msg=([^&]+)/); looks at the part of the address that starts with a question mark (window.location.search) and searches it for the pattern msg= followed by one or more characters that are not &. The result is stored in a variable called msg. A variable is just a named box that holds a value.
  3. const msgText = msg ? decodeURIComponent(msg[1]) : "No data collected for this metric, cannot generate analytics."; decides what text to show. If a msg value was found, it takes the captured part (msg[1]) and passes it through decodeURIComponent. If nothing was found, it uses a default sentence instead. decodeURIComponent is a built-in browser function that turns percent-encoded text back into normal characters. Web addresses cannot contain spaces and many symbols directly, so they are written in a code where, for example, %3C stands for <. Decoding reverses that.
  4. $(document.body).html(Utils.infoMessage(msgText)); takes the decoded text, passes it through a helper called Utils.infoMessage, and writes the result into the page body using .html(...). The .html(...) function tells the browser: treat this string as HTML markup and build it into the page.

The report notes that Utils.infoMessage "basically just wraps msgText in a </p>". So the helper adds a paragraph tag around the text and nothing else. It does not sanitise or escape anything. Sanitising means cleaning input so that dangerous parts are removed; escaping means turning characters like < into harmless text so the browser shows them instead of treating them as tags. Neither happens here, so the decoded parameter value ends up in the HTML body as markup.

Exploitation

Step 1: craft the payload in the query string

The researcher supplies an attack payload through the msg parameter:

Text
?msg=%3Csvg%2Fonload%3Dalert%28%22XSS%22%29%20%3E

This is the value as it appears in the address bar. It is percent-encoded, which is why it looks like a jumble of % signs and numbers. Percent-decoding this value yields the markup below, which is what decodeURIComponent produces before the string is handed to .html():

HTML
<svg/onload=alert("XSS") >

What this markup means: <svg> starts an SVG element, a format for drawing shapes that browsers understand. The / before onload is a shorthand way of writing the tag. onload is an event attribute: it tells the browser "when this element has finished loading, run the code that follows". The code that follows is alert("XSS"), a built-in browser function that shows a pop-up box with the text XSS. So the whole string says: create an SVG element, and when it loads, show a pop-up.

Step 2: the payload is written into the DOM

Because the decoded value is passed to $(document.body).html(...), the <svg> element is parsed as HTML and inserted into the page. The onload handler on the element then fires, executing alert("XSS"). The report states plainly that <svg/onload=alert("XSS") > is injected into the webpage.

The DOM is the browser's in-memory model of the page: a tree of elements that the browser builds from the HTML and that JavaScript can read and change. Writing to it with .html() is like handing the browser a fresh piece of page to build. The browser does not know or care that the string came from the address bar; it just builds it.

No HTTP request or response is shown in the report. The whole exchange happens in the browser, between the URL and the DOM. That is why this is called DOM-based XSS: the server is not involved in the dangerous step at all.

Root cause

The mistake is the use of .html() to insert a value that comes straight from the URL. The parameter is decoded and concatenated into the page as markup, with no encoding or sanitisation at any point. The regex only extracts the value, decodeURIComponent only reverses percent-encoding, and Utils.infoMessage only wraps the text in a </p>. None of these steps treats the input as untrusted text.

A useful comparison: imagine a receptionist who is told to read out whatever is written on a note left at the desk. If the note says "the meeting is at 3pm", that is fine. If the note says "shout fire and evacuate the building", the receptionist reads that out too, because nobody told them to check whether the note is a message or an instruction. Here, the page reads out whatever is in the address bar, and the browser follows any instructions it finds in it.

The report does not describe any other defence, such as a Content Security Policy, that would have blocked the handler from running. A Content Security Policy is a rule set a website can send to the browser saying which sources of code are allowed; it can stop inline handlers like onload from running. Nothing like that is mentioned here.

Impact

The report says an attacker can run malicious code on servers running this plugin, affecting the integrity and confidentiality of such servers. Integrity means the data has not been tampered with; confidentiality means it has not been seen by people who should not see it.

The report says an attacker can run malicious code on servers running this plugin. The origin is the combination of scheme, host and port that the browser uses to decide which site a page belongs to, for example https://gocd.example.com. Code running in that origin can act as that site towards the browser: it can read what the page can read and do what the page can do. The conditions are that the plugin is installed and a victim follows the link. The report does not go further into what an attacker could reach from that position.

Fix

For example, set the text content of the element instead of calling .html() on the decoded parameter, or escape the value before it is wrapped and inserted. Setting text content means the browser shows <svg> as the four characters <, s, v, g and the rest, instead of building an element from it.

Variants to test

  • Look for other places in the same plugin that read from window.location.search and pass the result to .html(), innerHTML, document.write or similar sinks. A sink is any function that turns a string into live page content. A positive result is a parameter value that appears as parsed markup in the DOM rather than as literal text.
  • Try other parameter names on the same page and on neighbouring pages of the plugin. A positive result is the same behaviour: the decoded value becomes an element and its event handler fires.
  • Check whether the wrapper function (Utils.infoMessage here) is reused elsewhere with untrusted input. A positive result is another call site where the wrapper's output reaches an HTML sink.
  • Test payloads that do not rely on onload, in case a filter blocks that specific attribute. A positive result is any injected element whose handler executes.

Hunting notes

This kind of bug hides in small client-side helpers that turn URL parameters into page content: message banners, error pages, info pages and anything that reads location.search or location.hash. location.hash is the part of the address after a # sign. During recon, JavaScript files that reference location.search, decodeURIComponent and .html( or innerHTML in the same function are the signal to follow. The researcher showed the payload and pointed to the vulnerable line.

Difficulty: beginner. The flaw is a short, readable DOM XSS in a single function, and the report demonstrates it with one encoded payload and the exact source line.

Glossary

  • DOM-based XSS: XSS where the dangerous step happens entirely in the browser's page model, without the server being involved.
  • DOM: the browser's in-memory tree of elements that makes up the current page; JavaScript reads and changes it.
  • GoCD: a continuous delivery server that automates building and releasing software.
  • Continuous delivery: the practice of automatically building, testing and releasing software in repeatable steps.
  • Plugin: an add-on program that extends a larger application with extra features.
  • Parameter: a name=value pair in a web address, after the ? sign.
  • Query string: the part of a web address from the ? onwards, holding parameters.
  • JavaScript: the programming language that runs in web browsers and makes pages interactive.
  • Variable: a named box in a program that holds a value.
  • Regex (regular expression): a pattern used to search text for a particular shape of characters.
  • Percent-encoding: a way of writing characters in a web address using % followed by codes, because many characters are not allowed directly.
  • decodeURIComponent: a built-in browser function that turns percent-encoded text back into normal characters.
  • HTML: the markup language that describes the structure of a web page using tags.
  • Tag / element: a piece of HTML such as <p> or <svg> that the browser turns into part of the page.
  • Attribute: a setting written inside an HTML tag, such as onload.
  • Event handler: code attached to an element that runs when something happens to it, such as loading.
  • .html(): a function that inserts a string into the page as HTML markup, so tags are built rather than shown.
  • Sink: any function or place that turns a string into live page content.
  • Sanitise: clean input so dangerous parts are removed.
  • Escape: turn special characters into harmless text so the browser shows them instead of acting on them.
  • Origin: the scheme, host and port of a site, which the browser uses to decide what a page is allowed to access.
  • Integrity: the property that data has not been tampered with.
  • Confidentiality: the property that data is only seen by people allowed to see it.
  • CVSS: a standard scoring system for rating the severity of security issues.
  • Content Security Policy: a rule set a site can send to the browser limiting which code may run.
  • Recon: the information-gathering phase of security testing, looking for clues about how a target works.

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.