A pair of plotly bugs stored XSS abd AWS metadata
The Plotly platform had a server-side request forgery (SSRF) vulnerability in its external URL import feature, allowing an authenticated user to make the server request internal AWS metadata endpoints. Separately, a stored cross-site scripting (XSS) flaw existed in presentation text links, where a javascript: URL could be saved and executed when clicked.
Published on ysx.me.uk
Plotly is a powerful data analytics and visualisation platform. Founded in 2012, the firm offer a range of products, including a collaborative web interface, API libraries, the Plotly.js library, on-premises services and various software utlities.
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
Plotly is a data analytics and visualisation platform founded in 2012. Its products include a collaborative web interface, API libraries, the Plotly.js library, on-premises services and various software utilities. The company runs a public bug bounty program alongside a private HackerOne program that researchers with a positive Signal metric can request an invitation to.
This write-up covers two reports from early May 2017: a server-side request forgery (SSRF) in the external URL import endpoint that reached the AWS EC2 instance metadata service, and a stored cross-site scripting (XSS) issue in Plotly Presentations via the Spectacle Editor.
Setup
The SSRF was reproducible by an authenticated user. The report does not describe any special role or privilege beyond being logged in. The XSS was found while exploring Plotly Presentations and the Spectacle Editor tool, which is described as:
an Electron based app for creating, editing, saving, and publishing Spectacle presentations [...] a joint effort between Formidable and Plotly.
No specific tooling or versions are given beyond the browser and the Spectacle Editor itself.
Finding it
The SSRF idea came from Brett Buerhaus' blogpost about a server-side request forgery vulnerability on the ESEA eSports platform, which the researcher had read in April the previous year. After exploiting a URL filter bypass for reflected XSS there, Brett learned of an EC2 instance metadata disclosure technique from @NahamSec.
Live instances on Amazon's Elastic Compute Cloud can retrieve information by querying the link-local metadata address [redacted]. The starting point is the following URL, which discloses the endpoints available for inspection:
http://[redacted]/latest/meta-data/
The EC2 documentation for the topic contains a Metadata Categories table with details on formatting and data types. The researcher also noted that the metadata address can disclose AWS API credentials if the instance is connected to a specific IAM role:
If there is an IAM role associated with the instance, role-name is the name of the role, and role-name contains the temporary security credentials associated with the role [...]
For the XSS, the researcher came across Plotly Presentations during wider reconnaissance of the firm's properties and started to explore the Spectacle Editor tool. Links can be added to text elements in a Spectacle presentation, and the platform accepted them.
Exploitation
Step 1: Reaching the metadata service through the external URL import
The external endpoint processes a valid url parameter and opens the Graph Maker with the retrieved data. Because http://[redacted] URLs were accepted, the well-formatted metadata appeared in the Graph Maker. The following URLs reproduced the issue for an authenticated user:
- https://plot.ly/external/?url=http://[redacted]/latest/meta-data
- https://plot.ly/external/?url=http://[redacted]/latest/meta-data/public-hostname
- https://plot.ly/external/?url=http://[redacted]/latest/dynamic/instance-identity/document
The report lists these three URLs as reproducing the issue. In this case it was not possible to obtain API credentials, so the impact was limited to the metadata that the instance exposed.
Step 2: Stored XSS through a presentation text link
The researcher pasted the following payload into the Link field of a text element:
javascript:prompt(document.domain)
After uploading the presentation to Plotly and selecting the test hyperlink, the JavaScript executed. The report describes this as straightforward stored XSS via a trusted URL element. After submitting the initial HackerOne report, the researcher later exported and attached the Spectacle JSON file to assist the Plotly team with their investigation and fix.
Root cause
The external endpoint processed the url parameter and opened the Graph Maker with the retrieved data; http://[redacted] URLs were accepted. The report does not describe the filtering logic, so the exact reason the address was accepted is not stated.
For the XSS, the Spectacle Editor accepted javascript: URLs in the Link field of text elements, and the payload executed when the link was selected. When the test hyperlink was selected, the JavaScript executed.
Impact
For the SSRF, an authenticated user could make Plotly's servers query the EC2 metadata service and read the responses in the Graph Maker. The metadata available included the endpoint listing, the public hostname and the instance identity document. AWS API credentials would have been exposed if the instance had been associated with an IAM role, but in this case it was not possible to obtain them.
For the stored XSS, a javascript: link stored in a presentation executed when the link was selected.
Fix
It records that both issues were resolved: the SSRF on 2017-05-17 and the stored XSS on 2017-05-25. The researcher commends Jody from Engineering for the swift handling of reports and the Development team for the quick resolution response.
Variants to test
- Other internal addresses through URL import features. Submit
urlvalues pointing at[redacted], RFC 1918 ranges and other link-local addresses to any endpoint that fetches a user-supplied URL. A positive result is the fetched content appearing in the application's response or UI. - Redirect-based bypasses. Host a URL that redirects to
http://[redacted]/latest/meta-data/and pass it to the import feature. A positive result is the metadata listing being returned after the redirect. - Alternate encodings of the metadata address. Try decimal, octal or IPv6 representations of
[redacted]. A positive result is the same metadata content appearing despite a filter on the literal address. - Other URL schemes in link fields. In any editor that accepts links on text elements, try
javascript:,data:andvbscript:payloads. A positive result is script execution when the link is selected. - Presentation export and re-import. Export a presentation containing a
javascript:link and re-import it, or share it with another account. A positive result is the payload surviving the round trip and executing for the second user.
What happened, in plain words
In May 2017, a security researcher named Yasin Soliman found two separate security problems in Plotly, a website for making charts and presentations. Both problems were reported through Plotly's bug bounty programme, a scheme where companies pay people for telling them about security holes before criminals find them.
The first problem let a logged-in user make Plotly's own computers fetch a special web address that only machines inside Plotly's network can normally reach. That address belongs to Amazon Web Services (AWS), the cloud provider Plotly used to run its servers, and it hands out information about the server. This kind of trick is called server-side request forgery, or SSRF: the attacker does not connect to the secret address themselves, they trick the server into doing it for them.
The second problem was in Plotly Presentations, a tool for building slide decks in the browser. A presentation can contain text with a clickable link. The researcher found that the link could be set to a special kind of address starting with javascript:, which makes the browser run code instead of opening a page. Plotly saved that link, and the code ran when the link was selected. This is called stored cross-site scripting, or stored XSS: the malicious content is stored on the site and later runs in other people's browsers.
Both issues were fixed. The SSRF was resolved on 17 May 2017 and the stored XSS on 25 May 2017. The researcher praised the Plotly team for handling the reports quickly.
Background: what Plotly is
Plotly is a data analytics and visualisation platform founded in 2012. In everyday terms, it helps people turn spreadsheets of numbers into charts and graphs they can share. Its products include a collaborative web interface (a website where several people can work on the same charts), API libraries (code that other programs use to talk to Plotly), the Plotly.js library (the chart-drawing code that runs in a browser), on-premises services (versions a company can run on its own computers) and various software utilities.
Plotly runs a public bug bounty programme alongside a private HackerOne programme. HackerOne is a website where security researchers report bugs to companies. The private programme is invitation-only: researchers with a positive Signal metric can ask to be invited. Signal is HackerOne's reputation score, which goes up when a researcher's reports turn out to be valid and down when they are not. A good Signal therefore acts like a reference, showing the company that the researcher is worth listening to.
The researcher reached out to the team and started searching for bugs in early May 2017. This article walks through the two reports, starting with the SSRF.
The idea behind the SSRF: AWS metadata
Before looking at Plotly itself, it helps to understand where the idea came from. Brett Buerhaus wrote a blogpost about a server-side request forgery vulnerability on the ESEA eSports platform, and the researcher had read it in April the previous year. In that post, Brett first exploited a URL filter bypass for reflected XSS, and then learned an interesting SSRF technique from @NahamSec: reading EC2 instance metadata.
Let us unpack those terms.
- Server-side request forgery (SSRF): a bug where an attacker can make a server send a request to an address of the attacker's choosing. The attacker cannot reach that address directly, but the server can, because the server sits inside the company's network. The everyday comparison is asking a colleague who works in the building to go and read a notice on an internal board for you: you cannot get past reception, but they can.
- EC2: Amazon Elastic Compute Cloud, the part of AWS that rents out virtual computers (called instances) by the hour.
- Instance metadata: a small information service that every EC2 instance can query about itself. It tells the instance its own hostname, its network details, and sometimes temporary login credentials for other AWS services.
Live instances on Amazon's Elastic Compute Cloud can retrieve information by querying the link-local metadata address [redacted]. A link-local address is a special address that only works on the local network segment; it is not routed across the internet. The everyday comparison is an extension number inside an office: it works from a desk phone in the building, but not from outside. That is exactly why SSRF matters: the attacker is outside, but the server is inside, so the server can dial the extension.
As a starting point, the following URL discloses the endpoints available for inspection:
http://[redacted]/latest/meta-data/
Line by line, in plain words:
http://is the ordinary web protocol, the same one used for normal websites.[redacted]is the fixed link-local address of the metadata service on every EC2 instance./latest/meta-data/is the path that lists what categories of information the instance is willing to hand out.
So the whole line means: ask the local metadata service for its table of contents. The answer is a plain list of names, such as the hostname or the instance identity, each of which can then be fetched by adding it to the end of the path.
The EC2 documentation for this topic contains a highly useful Metadata Categories table along with details on formatting and data types. The researcher also noted something more serious: the metadata address can disclose AWS API credentials if the instance is connected to a specific IAM role. The documentation quoted in the report says:
If there is an IAM role associated with the instance, role-name is the name of the role, and role-name contains the temporary security credentials associated with the role [...]
Two more terms to explain:
- API: an application programming interface, a way for one program to ask another program to do something. The everyday comparison is a restaurant menu: you do not walk into the kitchen, you order from the menu and the kitchen does the work. AWS APIs let programs create servers, read files and so on.
- IAM role: Identity and Access Management role, a set of permissions that an AWS instance can be given. If an instance has a role, the metadata service will hand out temporary credentials for that role, so that programs on the instance can call other AWS services without a password being written on disk.
That last point is why SSRF to the metadata address is taken seriously: if the instance has a role, an attacker who can read the metadata can read those temporary credentials and then act as the instance inside AWS. In this case it was not possible to obtain API credentials, so the impact was limited to the metadata the instance did expose.
Finding the SSRF in Plotly
The Plotly bug could be reproduced by an authenticated user, that is, someone with a normal Plotly account who is logged in. The report does not describe any special role or privilege beyond being logged in.
The feature involved is the external endpoint. In a URL, an endpoint is the part of the site that handles a particular job, and a parameter is a named value passed to it. Plotly's external endpoint takes a url parameter, fetches whatever address is given there, and opens the Graph Maker with the retrieved data. The Graph Maker is Plotly's chart-building screen.
The everyday comparison is a helpful assistant who will go and fetch any web page you name and put it on your desk. That is convenient for public pages. It becomes a problem when the assistant will also walk into the stationery cupboard that visitors are not supposed to enter.
Because http://[redacted] URLs were accepted, the well-formatted metadata appeared in the Graph Maker. The following URLs reproduced the issue for an authenticated user:
- https://plot.ly/external/?url=http://[redacted]/latest/meta-data
- https://plot.ly/external/?url=http://[redacted]/latest/meta-data/public-hostname
- https://plot.ly/external/?url=http://[redacted]/latest/dynamic/instance-identity/document
Taking the first URL apart:
https://plot.ly/external/is Plotly's own import feature, reached over the encrypted web protocol.?starts the list of parameters.url=names the parameter and gives its value.http://[redacted]/latest/meta-datais the address the researcher wants Plotly's server to fetch.
The second URL adds /public-hostname to the path, and the third adds /latest/dynamic/instance-identity/document.
The external endpoint fetched the URL and opened the Graph Maker with the retrieved data, and the well-formatted metadata appeared there.
In this case it was not possible to obtain API credentials, so the impact was limited to the metadata that the instance exposed.
Finding the stored XSS in Plotly Presentations
The researcher came across Plotly Presentations during wider reconnaissance of the firm's properties. Reconnaissance simply means looking around a company's websites and features to see what exists, the way a burglar might walk past a building noting which windows are open. Plotly Presentations is a tool for building slide decks online, and the researcher started to explore its Spectacle Editor.
Spectacle Editor is described in the report as:
an Electron based app for creating, editing, saving, and publishing Spectacle presentations [...] a joint effort between Formidable and Plotly.
A few explanations:
- Electron: a framework for building desktop applications using web technology. The everyday comparison is a browser window with the menus stripped off and the app's own buttons put in their place. Many chat and editor apps are built this way.
- Spectacle: an open-source library for making presentation slides with web code. Spectacle Editor is the desktop app built around it, made jointly by Formidable Labs and Plotly.
Links can be added to text elements in a Spectacle presentation, and the platform accepted them. A text element is simply a block of text on a slide, and a link is the clickable part that normally takes you to another page.
Exploiting the stored XSS
The researcher pasted the following payload into the Link field of a text element:
javascript:prompt(document.domain)
Line by line, in plain words:
javascript:is a URL scheme, the part before the colon that tells the browser what kind of address this is. You have seenhttp:andhttps:;javascript:tells the browser that what follows is code to run, not a page to open.prompt(...)is a built-in browser function that shows a small pop-up box asking the user to type something. It is a harmless way to prove that code ran.document.domainis the browser's name for the current website's address, for exampleplot.ly. Putting it inside the pop-up shows which site the code is running on.
So the whole line means: when someone clicks this link, run a pop-up that displays the address of the site we are on. The report describes this as straightforward stored XSS via a trusted URL element.
After pasting the payload, the researcher uploaded the presentation to Plotly and selected the test hyperlink. The JavaScript executed.
Two terms to pin down:
- Cross-site scripting (XSS): a bug where an attacker gets their own code to run in another user's browser as if it came from the trusted website. The everyday comparison is slipping a forged page into a company's internal binder: everyone who opens the binder trusts what they read.
- Stored XSS: the malicious content is saved on the server, so it runs for every viewer, not just the person who created it. The alternative, reflected XSS, only bounces the payload back to the person who sent it.
Why does running code in Plotly's context matter? A browser gives code on a site access to that site's cookies and tokens. A cookie is a small piece of data the browser stores for a site, often used to remember that you are logged in. A token is a similar secret, often used by APIs to prove who is calling. If an attacker's code runs on plot.ly, it can read what the browser will hand over for plot.ly and send it to the attacker, who can then act as the victim. The report does not describe which users could view such a presentation or what data the script could reach, so we should not assume more than the pop-up proof.
After submitting the initial HackerOne report, the researcher later exported and attached the Spectacle JSON file to assist the Plotly team with their investigation and fix. JSON is a plain-text format for structured data, and a Spectacle presentation is stored as one, so attaching it gave the developers the exact file that triggered the bug.
Why the bugs worked
For the SSRF, the external endpoint processed the url parameter and opened the Graph Maker with the retrieved data; http://[redacted] URLs were accepted.
For the XSS, the Spectacle Editor accepted javascript: URLs in the Link field of text elements, and the payload executed when the link was selected. Sanitising means cleaning input so that dangerous parts are removed or neutralised. When the test hyperlink was selected, the JavaScript executed. The origin is the combination of scheme, host and port that the browser uses to decide which site a piece of code belongs to.
What the impact was
For the SSRF, an authenticated user could make Plotly's servers query the EC2 metadata service and read the responses in the Graph Maker. The metadata available included the endpoint listing, the public hostname and the instance identity document. AWS API credentials would have been exposed if the instance had been associated with an IAM role, but in this case it was not possible to obtain them.
For the stored XSS, a javascript: link stored in a presentation executed when the link was selected.
How it was fixed
It records that both issues were resolved: the SSRF on 2017-05-17 and the stored XSS on 2017-05-25. The researcher commends Jody from Engineering for the swift handling of reports and the Development team for the quick resolution response.
Timeline
The following timestamps are provided in GMT, which is the time zone used as a common reference across the world.
SSRF via External URL Import leading to AWS Metadata Disclosure
- 2017-05-09 09:19: issue reported
- 2017-05-10 17:41: triaged and bounty issued
- 2017-05-17 22:25: issue resolved
Stored XSS via Presentation Text Link
- 2017-05-02 16:49: issue reported
- 2017-05-03 19:33: triaged and bounty issued
- 2017-05-25 21:30: issue resolved
Triaged means the company confirmed the report was valid and passed it to the right people. A bounty is the payment made for a valid report. The report notes that Plotly also pay on triage for valid reports, which the researcher calls a highly encouraged move from programme operators: it means the researcher is paid as soon as the report is confirmed, rather than waiting for the fix.
Variants worth testing
These are the same ideas applied in slightly different ways, useful for anyone learning how these bugs are found. Each one lists what a positive result looks like, so you know when you have found something.
- Other internal addresses through URL import features. Submit
urlvalues pointing at[redacted], RFC 1918 ranges and other link-local addresses to any endpoint that fetches a user-supplied URL.[redacted]is the loopback address, meaning the machine itself; RFC 1918 ranges are the private address blocks used inside home and office networks. A positive result is the fetched content appearing in the application's response or UI. - Redirect-based bypasses. Host a URL that redirects to
http://[redacted]/latest/meta-data/and pass it to the import feature. A redirect is a server telling the browser to go somewhere else; if the import feature follows redirects, a filter that only checks the first address can be sidestepped. A positive result is the metadata listing being returned after the redirect. - Alternate encodings of the metadata address. Try decimal, octal or IPv6 representations of
[redacted]. The same address can be written in several ways, and a filter that only blocks the literal text may miss the others. A positive result is the same metadata content appearing despite a filter on the literal address. - Other URL schemes in link fields. In any editor that accepts links on text elements, try
javascript:,data:andvbscript:payloads.data:embeds content directly in the URL, andvbscript:is an older scheme some browsers understand. A positive result is script execution when the link is selected. - Presentation export and re-import. Export a presentation containing a
javascript:link and re-import it, or share it with another account. A positive result is the payload surviving the round trip and executing for the second user.
Glossary
- API: an application programming interface, a way for one program to ask another program to do something, like ordering from a menu rather than entering the kitchen.
- AWS: Amazon Web Services, Amazon's cloud platform that rents out computers and services over the internet.
- Bounty: a payment made to a researcher for reporting a valid security bug.
- Cookie: a small piece of data a website asks the browser to store, often used to remember that you are logged in.
- Cross-site scripting (XSS): a bug where an attacker's code runs in another user's browser as if it came from the trusted website.
- EC2: Amazon Elastic Compute Cloud, the AWS service that provides virtual computers called instances.
- Electron: a framework for building desktop applications with web technology.
- Endpoint: the part of a website that handles a particular job, such as importing a URL.
- Graph Maker: Plotly's chart-building screen, where imported data is displayed.
- HackerOne: a platform where security researchers report bugs to companies and companies pay bounties.
- IAM role: an AWS identity with a set of permissions that an instance can be given, so programs on it can call AWS services.
- Instance: a single virtual computer running in the cloud.
- Instance identity document: a small file from the metadata service describing the instance, such as its region and account.
- JSON: a plain-text format for structured data, used to store and exchange information.
- Link-local address: an address that only works on the local network segment and is not routed across the internet, such as 169.254.169.254.
- Metadata service: a small service on an EC2 instance that answers questions about the instance itself at 169.254.169.254.
- On-premises: software a company runs on its own computers rather than on someone else's cloud.
- Origin: the combination of scheme, host and port that the browser uses to decide which site a piece of code belongs to.
- Parameter: a named value passed to an endpoint in a URL, such as
url=in?url=.... - Payload: the piece of input an attacker uses to trigger a bug, such as a
javascript:link. - Reconnaissance: looking around a company's websites and features to see what exists and where bugs might be.
- Redirect: a server telling the browser or client to go to a different address instead.
- Reflected XSS: XSS where the payload bounces straight back to the person who sent it, rather than being stored.
- RFC 1918: the standard that defines the private address ranges used inside home and office networks.
- Sanitising: cleaning input so dangerous parts are removed or neutralised before it is stored or displayed.
- Server-side request forgery (SSRF): a bug where an attacker makes a server send a request to an address of the attacker's choosing, often an internal one the attacker cannot reach.
- Signal: HackerOne's reputation score for a researcher, based on how many of their reports turned out to be valid.
- Spectacle: an open-source library for making presentation slides with web code; Spectacle Editor is the desktop app built around it.
- Stored XSS: XSS where the malicious content is saved on the server and runs for every viewer.
- Token: a secret string used to prove identity, often for APIs, similar in purpose to a cookie.
- Triaged: confirmed as valid by the company and passed to the right people to fix.
- URL scheme: the part before the colon in a URL, such as
http:,https:orjavascript:, which tells the browser what kind of address it is.