Reflected cross-site scripting (XSS) on api.tiles.mapbox.com
A reflected cross-site scripting flaw existed in the map embed page of Mapbox's v4 map API, where the access_token query parameter was inserted into HTML without escaping. An attacker could craft a link that, when opened in Firefox, executed arbitrary JavaScript in the context of the Mapbox page.
Originally disclosed on HackerOne
- Triaged in 4 hours
- Fixed in 4 days
- Paid in 4 days
- Disclosed after 34 days
Summary by the program
On April 28th, 2016 @dawgyg reported a reflected cross-site scripting issue in the map embed page of our v4 map API that affected Firefox users only. An attacker could manipulate the access_token query string parameter on api.mapbox.com or api.tiles.mapbox.com to inject arbitrary JavaScript that would then execute in the context of the page.
The attack exploited an interpolated underscore template (<%=) that did not HTML-escape the value. In addition, Firefox does not encodeURIComponent() the single quote character (%27 or ') in the address bar. Both of these factors allowed an attacker to add a single quote character to break out of several meta HTML elements on our map embed page and add arbitrary script elements for Firefox users.
To resolve this issue we switched to HTML-escaped underscore templates (<%-). We deployed the fix to our servers and resolved the issue on April 29th, 2016.
This report only affected infrastructure running on api.mapbox.com and api.tiles.mapbox.com - it did not affect any of Mapbox's open source libraries such as mapbox.js or Mapbox GL JS. In addition, this issue also only affected Firefox users - Chrome, Safari, and Internet Explorer users were not affected.
The report
There is a reflective XSS vulnerability in the access_token param found in the page.html at api.tiles.mapbox.com
Attachments

Context
Mapbox's v4 map API serves map tiles and an embeddable map page. The page in question is page.html, reachable under the /v4/<account>.<mapid>/ path on both api.mapbox.com and api.tiles.mapbox.com. It takes an access_token query string parameter, which is the public token used to authorise access to a map. The page renders that token into HTML, and that rendering is where the bug lived.
The issue was a reflected cross-site scripting flaw that only affected Firefox users. Chrome, Safari and Internet Explorer were not affected. The report also states that Mapbox's open source libraries, mapbox.js and Mapbox GL JS, were not affected; only the infrastructure running on api.mapbox.com and api.tiles.mapbox.com was.
Setup
No account, role or special tooling is described. The only precondition that matters is the browser: the payload depends on Firefox behaviour in the address bar, so the attack works when a Firefox user opens the crafted link. The proof of concept uses a public token belonging to the map ctswebrequest.m4ga59jd.
Finding it
The researcher identified a reflected XSS vulnerability in the access_token parameter of page.html at api.tiles.mapbox.com. The value of the parameter is reflected into the page without being safely encoded, so a crafted token value can break out of the surrounding markup and introduce a script.
Exploitation
Step 1: craft the link
The researcher supplied a proof of concept URL:
http://api.tiles.mapbox.com/v4/ctswebrequest.m4ga59jd/page.html?access_token=pk.[redacted].aspx%27%3E%3Cscript%3Ealert%28document.domain%29%3C/script%3E#11/39.9168/-75.1595
The path selects the map ctswebrequest.m4ga59jd and the embed page page.html. The access_token value starts with a normal-looking public token and then appends .htaccess.aspx, followed by percent-encoded characters. Decoded, the tail is a single quote, a closing angle bracket, a script element that calls alert(document.domain), and a closing script tag. The URL ends with the fragment #11/39.9168/-75.1595.
Step 2: the single quote breaks out of the markup
The page interpolates the token into several meta HTML elements using an underscore template with the <%= form. That form inserts the value without HTML-escaping it. The injected single quote closes the attribute the token sits in, and the > closes the meta element, so the following <script> becomes a real element in the document rather than text.
Step 3: Firefox keeps the quote intact
Firefox does not run encodeURIComponent() on the single quote character (%27 or ') in the address bar. The quote therefore survives in the URL as typed, reaches the server, and is reflected back into the page. In browsers that encode or otherwise neutralise the quote, the breakout does not happen, which is why the issue was Firefox-only.
Step 4: the script runs
When a Firefox user opens the link, the injected script element executes in the context of the page and calls alert(document.domain), demonstrating that JavaScript runs with the origin of api.tiles.mapbox.com.

The attachment is included with the report.
Root cause
The map embed page rendered the access_token value through an interpolated underscore template written as <%=, which does not HTML-escape its output. Because the token was placed inside several meta HTML elements, an unescaped single quote was enough to close the attribute and the element, and the rest of the value was parsed as markup. The second half of the cause is browser behaviour: Firefox does not encodeURIComponent() the single quote in the address bar, so the character reached the server unchanged. Both factors together allowed an attacker to add arbitrary script elements for Firefox users.
Impact
An attacker could manipulate the access_token query string parameter on api.mapbox.com or api.tiles.mapbox.com to inject arbitrary JavaScript that would execute in the context of the page. The victim has to be a Firefox user who opens the crafted link. Chrome, Safari and Internet Explorer users were not affected, and the open source libraries mapbox.js and Mapbox GL JS were not affected.
Fix
Mapbox switched from the unescaped underscore template form <%= to the HTML-escaped form <%-. The fix was deployed to the servers and the issue was resolved on April 29th, 2016, one day after the report on April 28th, 2016.
Variants to test
- Other parameters reflected into
metaelements or attributes: send a single quote and a closing angle bracket, then a harmless marker such as ascriptelement, and check whether the marker appears as markup rather than text. - The same embed page on both hostnames: test
api.mapbox.comandapi.tiles.mapbox.com, since the report names both as affected. - Browser-specific encoding: repeat the request from different browsers and compare what reaches the server. A positive result is a quote that survives in the URL in one browser but is encoded in another.
- Template syntax in other pages: look for values rendered through
<%=rather than<%-, and check whether the output is escaped.
Hunting notes
This kind of bug hides in server-rendered embed and preview pages that interpolate user-controlled query parameters into HTML attributes, especially meta tags. During recon, look for pages that echo a token, key or identifier back into the response, and check whether the echoed value is HTML-escaped. The signal is a parameter whose value appears verbatim in the HTML source. The researcher supplied a proof of concept link containing alert(document.domain). The report earned a 1000.00 USD bounty.
What happened, in plain words
Mapbox is a company that provides maps for websites and apps. One of its services is an API, which is a way for one computer program to ask another computer program for data over the internet. In this case the API hands out map images (called tiles) and a ready-made web page that shows a map inside another site.
That ready-made page is called page.html. It lives on Mapbox's servers under a web address that includes an account name and a map identifier, and it accepts a value called access_token in the address. A token is a short string of characters that acts like a key: it proves you are allowed to use a particular map. Mapbox puts that token into the HTML of the page so the page can work.
The problem was that the page copied the token into its HTML without cleaning it first. If someone put special characters into the token part of the address, those characters were treated as part of the page's structure rather than as harmless text. That let an attacker slip a small program (JavaScript) into the page. When another person opened the crafted link in Firefox, that program ran as if Mapbox itself had written it. This class of bug is called cross-site scripting, or XSS: a way to make a trusted website deliver code that the site's owners never intended.
The researcher who found it was dawgyg, and the report was made on 28 April 2016. Mapbox fixed it the next day, on 29 April 2016, and paid a bounty of 1000.00 USD. A bounty is a reward a company pays to someone who reports a security problem responsibly instead of abusing it.
Context
Mapbox's v4 map API serves map tiles and an embeddable map page. "Embeddable" means the page is designed to be placed inside another website, the way a video player can be dropped into a blog post. The page in question is page.html, reachable under the /v4/<account>.<mapid>/ path on both api.mapbox.com and api.tiles.mapbox.com. The angle brackets are placeholders: in a real address, <account> is the account name and <mapid> is the identifier of one particular map.
The page takes an access_token query string parameter. A query string is the part of a web address after the ? sign; it carries small pieces of information to the server, each written as name=value. Here the name is access_token and the value is the public token used to authorise access to a map. "Public" means the token is not a secret password; it is meant to be visible in the page so the map can load. "Authorise" means the server checks the token and decides whether to serve the map.
The page renders that token into HTML. "Renders" means it builds the final web page text, including the token, and sends it to the browser. That rendering is where the bug lived.
The issue was a reflected cross-site scripting flaw. "Reflected" means the dangerous value is not stored on the server; it travels in the request and is echoed straight back in the response. It only affected Firefox users. Chrome, Safari and Internet Explorer were not affected. The report also states that Mapbox's open source libraries, mapbox.js and Mapbox GL JS, were not affected; only the infrastructure running on api.mapbox.com and api.tiles.mapbox.com was. "Open source" means the code is published for anyone to read and reuse, and those libraries are separate software from the servers that host the API.
Setup
No account, role or special tooling is described. The only precondition that matters is the browser: the payload depends on Firefox behaviour in the address bar, so the attack works when a Firefox user opens the crafted link. The proof of concept uses a public token belonging to the map ctswebrequest.m4ga59jd.
Finding it
The researcher identified a reflected XSS vulnerability in the access_token parameter of page.html at api.tiles.mapbox.com. The value of the parameter is reflected into the page without being safely encoded, so a crafted token value can break out of the surrounding markup and introduce a script.
"Encoded" here means converting characters that have a special meaning in HTML into a safe written form, so the browser shows them as text instead of acting on them. "Markup" is the HTML itself: the tags such as <meta> and <script> that tell the browser how to build the page. "Break out" means getting past the place where your text was supposed to stay and into the surrounding structure, where the browser starts treating your characters as instructions.
Exploitation
Step 1: craft the link
The researcher supplied a proof of concept URL:
http://api.tiles.mapbox.com/v4/ctswebrequest.m4ga59jd/page.html?access_token=pk.[redacted].aspx%27%3E%3Cscript%3Ealert%28document.domain%29%3C/script%3E#11/39.9168/-75.1595
Line by line, in plain words:
http://api.tiles.mapbox.comis the server being contacted.httpis the protocol, the set of rules browsers and servers use to exchange pages./v4/ctswebrequest.m4ga59jd/page.htmlis the path. It selects the mapctswebrequest.m4ga59jdand the embed pagepage.html.?access_token=starts the query string and names the parameter whose value the page will use.pk.[redacted].aspxis the start of the value. It looks like a normal public token, and then.htaccess.aspxis appended to it. That suffix is appended to the token value.%27is the percent-encoded form of a single quote character. Percent-encoding is a way of writing characters in a web address using a%sign and two hexadecimal digits, because addresses are only allowed to contain a limited set of characters.%27decodes to'.%3Edecodes to>, the character that closes an HTML tag.%3Cscript%3Edecodes to<script>, the opening tag of a script element.alert%28document.domain%29decodes toalert(document.domain).alertis a browser function that pops up a message box.document.domainis the address of the site the page belongs to. So this asks the browser to show the site's own address in a pop-up, which proves the code is running as part of that site.%3C/script%3Edecodes to</script>, the closing tag of the script element.#11/39.9168/-75.1595is the fragment, the part after the#. It is the fragment, the part after the#. A fragment is handled by the browser and is not normally sent to the server.
Decoded, the tail of the token value is a single quote, a closing angle bracket, a script element that calls alert(document.domain), and a closing script tag.
Step 2: the single quote breaks out of the markup
The page interpolates the token into several meta HTML elements using an underscore template with the <%= form. A template is a piece of text with blanks that get filled in with values when the page is built; underscore is a JavaScript library that provides this filling-in feature. The <%= form inserts the value without HTML-escaping it, meaning it copies the characters exactly as they arrived.
A meta element is a small tag in the head of an HTML page that carries information about the page, such as its description. Its values are written inside attributes, which are name="value" pairs inside the tag, and attributes are wrapped in quotes. The injected single quote closes the attribute the token sits in, and the > closes the meta element, so the following <script> becomes a real element in the document rather than text. In everyday terms: imagine a form where your name is supposed to go inside a box marked "name". If the form does not check what you write, you can write a closing quote and then extra instructions of your own, and the person reading the form treats those instructions as part of the form.
Step 3: Firefox keeps the quote intact
Firefox does not run encodeURIComponent() on the single quote character (%27 or ') in the address bar. encodeURIComponent() is a JavaScript function that converts characters into their percent-encoded form, so a quote would become %27 and lose its special meaning. The quote therefore survives in the URL as typed, reaches the server, and is reflected back into the page. In browsers that encode or otherwise neutralise the quote, the breakout does not happen, which is why the issue was Firefox-only.
Step 4: the script runs
When a Firefox user opens the link, the injected script element executes in the context of the page and calls alert(document.domain), demonstrating that JavaScript runs with the origin of api.tiles.mapbox.com. "Context" and "origin" here mean the security boundary of the site: the browser groups pages by site, and code running inside that boundary can read and act on things that belong to that site. That is why running even a harmless-looking alert matters: it proves an attacker could run any code they liked there.

The attachment is included with the report.
Root cause
The map embed page rendered the access_token value through an interpolated underscore template written as <%=, which does not HTML-escape its output. Because the token was placed inside several meta HTML elements, an unescaped single quote was enough to close the attribute and the element, and the rest of the value was parsed as markup. The second half of the cause is browser behaviour: Firefox does not encodeURIComponent() the single quote in the address bar, so the character reached the server unchanged. Both factors together allowed an attacker to add arbitrary script elements for Firefox users.
Impact
An attacker could manipulate the access_token query string parameter on api.mapbox.com or api.tiles.mapbox.com to inject arbitrary JavaScript that would execute in the context of the page. The victim has to be a Firefox user who opens the crafted link. Chrome, Safari and Internet Explorer users were not affected, and the open source libraries mapbox.js and Mapbox GL JS were not affected.
Fix
Mapbox switched from the unescaped underscore template form <%= to the HTML-escaped form <%-. The difference is one character, but it changes the behaviour: the escaped form turns special characters into safe text so they cannot become part of the page's structure. The fix was deployed to the servers and the issue was resolved on 29 April 2016, one day after the report on 28 April 2016.
Variants to test
- Other parameters reflected into
metaelements or attributes: send a single quote and a closing angle bracket, then a harmless marker such as ascriptelement, and check whether the marker appears as markup rather than text. - The same embed page on both hostnames: test
api.mapbox.comandapi.tiles.mapbox.com, since the report names both as affected. - Browser-specific encoding: repeat the request from different browsers and compare what reaches the server. A positive result is a quote that survives in the URL in one browser but is encoded in another.
- Template syntax in other pages: look for values rendered through
<%=rather than<%-, and check whether the output is escaped.
Hunting notes
This kind of bug hides in server-rendered embed and preview pages that interpolate user-controlled query parameters into HTML attributes, especially meta tags. During recon, look for pages that echo a token, key or identifier back into the response, and check whether the echoed value is HTML-escaped. The signal is a parameter whose value appears verbatim in the HTML source. The researcher supplied a proof of concept link containing alert(document.domain). The report earned a 1000.00 USD bounty.
Glossary
- API: a way for one program to request data or actions from another program over the internet.
- Access token: a string of characters that acts like a key, proving the holder is allowed to use a particular resource.
- Attribute: a
name="value"pair inside an HTML tag that gives the tag extra information. - Bounty: a reward a company pays to someone who reports a security problem responsibly.
- Browser: the program you use to view web pages, such as Firefox or Chrome.
- Context (of a page): the security boundary a piece of code runs inside, tied to the site it belongs to.
- Cross-site scripting (XSS): a bug where a website delivers code an attacker supplied, so it runs as if the site wrote it.
- Document domain: the address of the site a page belongs to, readable from JavaScript running on that page.
- Embeddable page: a page designed to be placed inside another website.
- Encode / escape: converting characters with special meaning into a safe written form so they are treated as text.
- Fragment: the part of a web address after the
#, handled by the browser and not normally sent to the server. - HTML: the language used to describe the structure of a web page, made of tags such as
<meta>and<script>. - HTTP: the set of rules browsers and servers use to exchange pages and data.
- JavaScript: the programming language browsers run to make pages interactive.
- Markup: the HTML tags and structure of a page.
- Meta element: a tag in the head of a page that carries information about the page.
- Open source: software whose code is published for anyone to read and reuse.
- Origin: the combination of scheme, host and port that defines a site's security boundary.
- Parameter: a
name=valuepair in a query string that passes information to a server. - Path: the part of a web address that identifies a resource on the server, such as
/v4/.../page.html. - Payload: the crafted value an attacker sends to trigger a bug.
- Percent-encoding: writing characters in a web address as a
%sign plus two hexadecimal digits. - Proof of concept: a working example that demonstrates a bug is real.
- Query string: the part of a web address after the
?, carrying parameters. - Reflected XSS: XSS where the dangerous value is echoed straight back from the request rather than stored.
- Render: to build the final page text and send it to the browser.
- Script element: an HTML tag that tells the browser to run the JavaScript inside it.
- Template: text with blanks that get filled in with values when a page is built.
- Underscore: a JavaScript library that provides template features.
- URL: a web address.
encodeURIComponent(): a JavaScript function that percent-encodes characters so they lose special meaning.