Stored XSS | api.mapbox.com | IE 11 | Styles name
A stored cross-site scripting injection could be saved in a Styles name on api.mapbox.com, and because JSON responses lacked the X-Content-Type-Options: nosniff header, Internet Explorer 11 would render the response as HTML and execute the script. An attacker could therefore run script in the context of a victim using IE11 who viewed the affected resource.
- Triaged in 15 days
- Fixed in 20 days
- Paid in 15 days
- Disclosed after 29 days
Summary by the program
On December 24, 2019, user @renekroka reported a stored XSS injection vulnerability on api.mapbox.com that affected users in Internet Explorer 11. An attacker could store XSS injections on Mapbox servers, and then exploit them in IE11 due to JSON responses not including the X-Content-Type-Options: nosniff header.
Using the information provided by the researcher, we deployed a patch to Mapbox servers on January 8, 2020. This patch added the X-Content-Type-Options: nosniff and X-Frame-Options: deny to Styles API JSON responses.
What the report shows
On 24 December 2019, a researcher reported a stored cross-site scripting vulnerability on api.mapbox.com. The flaw affected users of Internet Explorer 11. The program's summary states that an attacker could store XSS injections on Mapbox servers and then exploit them in IE11, because JSON responses did not include the X-Content-Type-Options: nosniff header.
The affected feature is the Styles API, which returns JSON. The report does not include the individual requests, payloads or the exact field where the injection was stored; the program summary only names the asset and the browser.
The researcher's information was sufficient for the program to act. On 8 January 2020, Mapbox deployed a patch that added two headers to Styles API JSON responses:
X-Content-Type-Options: nosniff
X-Frame-Options: deny
The report was rated medium severity and disclosed on 21 January 2020. The summary does not state a bounty amount.
Root cause
The root cause is likely a combination of two things. First, a user-controlled value was stored and later returned inside a JSON response without being neutralised for the context in which a browser might interpret it. Second, the JSON response lacked X-Content-Type-Options: nosniff, so a browser was free to ignore the declared content type and sniff the body as something else.
Internet Explorer 11 is the browser where this mattered. When a response is served without nosniff, IE can treat a JSON body as HTML if the content looks like markup. A stored string that contains HTML or script syntax can therefore be rendered and executed in the origin of api.mapbox.com, rather than being treated as inert data.
Impact
According to the program, an attacker could store XSS injections on Mapbox servers and exploit them in IE11. That means script execution in the context of the affected origin for users of that browser who viewed the crafted content. The report does not describe which data or sessions were reachable from that origin, so the practical blast radius beyond script execution in the api.mapbox.com origin is not stated.
How this kind of bug works
Content sniffing is the mechanism at the centre of this bug class. A server declares a content type, for example application/json, but some browsers, historically IE, may inspect the body and decide it looks like HTML. If the body contains attacker-controlled markup, the browser renders it as a document in the server's origin. Any script in that markup runs with that origin's privileges.
The X-Content-Type-Options: nosniff header tells the browser not to second-guess the declared type. With it present, a JSON response stays JSON and markup inside string values is not rendered. Without it, every stored value that ends up in a JSON body is a potential HTML injection point for sniffing browsers.
Stored XSS differs from reflected XSS in that the payload persists server-side and is served to whoever requests the affected resource. The defence has two layers: encode or reject dangerous characters at storage and output time, and send nosniff so that even a missed encoding step cannot turn a data response into an HTML document.
How to test for it
- Identify features where user-supplied names or labels are stored and later returned by an API, especially JSON endpoints. Style names, project names, saved search names and similar fields are typical.
- Create an object with a name containing HTML markup, for example a tag with an event handler or a script tag, and save it.
- Request the endpoint that returns the stored object and inspect the response headers. Note whether
Content-Typeis JSON and whetherX-Content-Type-Options: nosniffis present. - If
nosniffis absent, open the response URL directly in a browser known to sniff content, such as IE11, and observe whether the markup is rendered and the script executes. - Confirm that the execution happens in the target origin, not in a sandboxed or separate context.
A positive result is script execution when the JSON response is loaded as a document. Common false positives include payloads that are reflected but HTML-encoded, responses that already carry nosniff, execution that only occurs in a context with no access to the target origin, and browsers that do not sniff JSON as HTML. A payload that renders as text inside a JSON viewer is not a finding.
How it is fixed
The standard fix is to send X-Content-Type-Options: nosniff on all API responses, particularly JSON. The program deployed X-Content-Type-Options: nosniff together with X-Frame-Options: deny. In addition, stored values should be encoded for the output context, and input validation can reject or escape markup characters in names. Defence in depth means the header protects against sniffing even if an encoding gap remains.
Hunting notes
This bug class tends to hide in APIs that return user-controlled strings as JSON, especially older endpoints and ones serving multiple client types. Recon signals include JSON responses without nosniff, endpoints that echo stored names, and features that support legacy browsers. When reporting, show the stored value, the response headers, and a demonstration of execution in the affected browser, and state clearly which origin the script runs in so the program can judge impact.
What happened, in plain words
Mapbox is a company that provides maps and location services that other companies build into their own websites and apps. One of its products is the Styles API, which is a service that returns map styling information as data. Think of it as a waiter who hands you a printed menu: you ask for a menu, and you get back a sheet of paper with the details written on it, not a cooked meal.
On 24 December 2019, a researcher reported a stored cross-site scripting vulnerability on api.mapbox.com, the address where Mapbox's API lives. The flaw affected people using Internet Explorer 11, an older Microsoft browser. According to the program's summary, an attacker could store XSS injections on Mapbox servers and then exploit them in IE11, because JSON responses did not include the X-Content-Type-Options: nosniff header.
The affected feature is the Styles API, which returns JSON. JSON is a plain text format for data, a way of writing information as labelled values so a program can read it. The report does not include the individual requests, payloads or the exact field where the injection was stored; the program summary only names the asset and the browser.
The researcher's information was sufficient for the program to act. On 8 January 2020, Mapbox deployed a patch that added two headers to Styles API JSON responses:
X-Content-Type-Options: nosniff
X-Frame-Options: deny
A header is a small line of extra information that a web server sends alongside a response, like a label on a parcel telling the recipient how to handle the contents. The first line tells the browser not to guess what kind of content it is receiving. The second tells the browser not to display the response inside a frame, a small window embedded in another page.
The report was rated medium severity and disclosed on 21 January 2020. The summary does not state a bounty amount.
Root cause
The root cause is likely a combination of two things. First, a user-controlled value was stored and later returned inside a JSON response without being neutralised for the context in which a browser might interpret it. Second, the JSON response lacked X-Content-Type-Options: nosniff, so a browser was free to ignore the declared content type and sniff the body as something else.
Content sniffing is the habit some browsers have of looking at the body of a response and deciding for themselves what it is, rather than trusting the label the server attached. It is like a postal worker opening a parcel labelled "documents" and, because the contents look like a birthday cake, treating it as food.
Internet Explorer 11 is the browser where this mattered. When a response is served without nosniff, IE can treat a JSON body as HTML if the content looks like markup. HTML is the language web pages are written in, and markup means the tags that tell a browser how to display things. A stored string that contains HTML or script syntax can therefore be rendered and executed in the origin of api.mapbox.com, rather than being treated as inert data. An origin is the combination of scheme, host and port that a browser uses to decide which pages may talk to each other; script running in the api.mapbox.com origin is treated as belonging to Mapbox's API.
Impact
According to the program, an attacker could store XSS injections on Mapbox servers and exploit them in IE11. That means script execution in the context of the affected origin for users of that browser who viewed the crafted content. The report does not describe which data or sessions were reachable from that origin, so the practical blast radius beyond script execution in the api.mapbox.com origin is not stated.
How this kind of bug works
In general, content sniffing is the mechanism at the centre of this bug class. A server declares a content type, for example application/json, but some browsers, historically IE, may inspect the body and decide it looks like HTML. If the body contains attacker-controlled markup, the browser renders it as a document in the server's origin. Any script in that markup runs with that origin's privileges.
The X-Content-Type-Options: nosniff header tells the browser not to second-guess the declared type. With it present, a JSON response stays JSON and markup inside string values is not rendered. Without it, every stored value that ends up in a JSON body is a potential HTML injection point for sniffing browsers.
Stored XSS differs from reflected XSS in that the payload persists server-side and is served to whoever requests the affected resource. A payload is the piece of content an attacker plants; stored means it is saved on the server and handed out later, while reflected means it bounces straight back in the same response. The defence has two layers: encode or reject dangerous characters at storage and output time, and send nosniff so that even a missed encoding step cannot turn a data response into an HTML document.
How to test for it
In general, you can look for this bug class with a few simple steps:
- Identify features where user-supplied names or labels are stored and later returned by an API, especially JSON endpoints. Style names, project names, saved search names and similar fields are typical.
- Create an object with a name containing HTML markup, for example a tag with an event handler or a script tag, and save it.
- Request the endpoint that returns the stored object and inspect the response headers. Note whether
Content-Typeis JSON and whetherX-Content-Type-Options: nosniffis present. - If
nosniffis absent, open the response URL directly in a browser known to sniff content, such as IE11, and observe whether the markup is rendered and the script executes. - Confirm that the execution happens in the target origin, not in a sandboxed or separate context.
A positive result is script execution when the JSON response is loaded as a document. Common false positives include payloads that are reflected but HTML-encoded, responses that already carry nosniff, execution that only occurs in a context with no access to the target origin, and browsers that do not sniff JSON as HTML. A payload that renders as text inside a JSON viewer is not a finding.
How it is fixed
In general, the standard fix is to send X-Content-Type-Options: nosniff on all API responses, particularly JSON. The program deployed X-Content-Type-Options: nosniff together with X-Frame-Options: deny. In addition, stored values should be encoded for the output context, and input validation can reject or escape markup characters in names. Defence in depth means the header protects against sniffing even if an encoding gap remains.
Hunting notes
In general, this bug class tends to hide in APIs that return user-controlled strings as JSON, especially older endpoints and ones serving multiple client types. Recon signals include JSON responses without nosniff, endpoints that echo stored names, and features that support legacy browsers. When reporting, show the stored value, the response headers, and a demonstration of execution in the affected browser, and state clearly which origin the script runs in so the program can judge impact.
Glossary
- API: a service that lets one program ask another for data or actions, like a counter where you place an order and receive what you asked for.
- Content type: the label a server puts on a response saying what kind of data it is, such as JSON or HTML.
- Content sniffing: a browser's habit of inspecting a response body and guessing its type instead of trusting the declared label.
- Cross-site scripting (XSS): a bug where an attacker gets their own script to run inside another site's pages, so the browser treats it as part of that site.
- Header: a short line of extra information a server sends with a response, telling the browser how to handle it.
- HTML: the language used to write web pages, made of tags that describe structure and content.
- Internet Explorer 11 (IE11): an older Microsoft browser that is known to sniff content types.
- JSON: a plain text format for data, written as labelled values that programs can read.
- Markup: the tags and syntax in HTML that tell a browser how to display content.
- nosniff: the value of the
X-Content-Type-Optionsheader that tells a browser to trust the declared content type and not guess. - Origin: the combination of scheme, host and port that a browser uses to decide which pages may interact with each other.
- Payload: the piece of content an attacker plants to trigger a bug.
- Reflected XSS: XSS where the payload bounces straight back in the same response instead of being stored.
- Stored XSS: XSS where the payload is saved on the server and served later to anyone who requests the affected resource.
- Styles API: the Mapbox service that returns map styling information as JSON.
- X-Frame-Options: a header that tells the browser whether a response may be displayed inside a frame on another page.