Skip to content
XSS Disclosed report Intermediate CVE-2018-5167

Old console and current debugger linkify javascript: URLs

Wladimir Palant Follow

Originally disclosed on Mozilla

  • Fixed in 7 days
  • Paid in 11 days
  • Disclosed after 7 days
Text
A response returning application/json will be displayed in the JSON Viewer and links in the data will be linkified. While this might be convenient, javascript: links will also be linkified. Web services don't expect that JSON output needs to be sanitized, so injecting a javascript: URL into the output is often trivial. See for example this Mozilla URL:

> https://token.services.mozilla.com/1.0/sync/javascript:alert(JSON.stringify(JSONView.headers.request%29%29

If the user somehow clicks value of the errors.0.name property an alert message will show up - JavaScript code executed successfully. And while the principal is set to the null principal so that the code cannot access document.cookies for example, it can access the JSONView object injected by the JSON Viewer. That object contains among other things all request headers - meaning also cookies and authorization tokens.

This JavaScript code can also trigger saving of arbitrary content, though that shouldn't be as critical:

> https://token.services.mozilla.com/1.0/sync/javascript:void(window.dispatchEvent(new%2520CustomEvent(%2527contentMessage%2527,%7Bdetail:%7Btype:%2527save%2527,value:%2527data:,foobar%2527%7D%7D%29%29%29

Clearly, JSON Viewer should only linkify HTTP and HTTPS URLs. For reference, the problematic code line is https://dxr.mozilla.org/mozilla-central/rev/6ff60a083701d08c52702daf50f28e8f46ae3a1c/devtools/client/shared/components/reps/reps.js#88. While this also allows data: and chrome: URLs, browser security mechanisms will no longer allow navigating to those.

The original report as published on Mozilla's Bugzilla, by Wladimir Palant. Images and videos are our own copies; raw HTML is shown as text. View it on Mozilla's Bugzilla.

The original is short, so this covers everything it reports, then explains this kind of bug in general: how it works, how to test for it and how it is fixed. The general sections are about the bug class, not this target. Written with AI and checked against the original; the original is the record. 4 min read.

What the report shows

The target is the Firefox DevTools JSON Viewer, the component that renders responses with an application/json content type. The researcher noticed that the viewer turns values inside the JSON into clickable links, and that this linkification is not limited to HTTP and HTTPS. A javascript: URL placed in the JSON output becomes a clickable link as well.

Because web services generally do not treat JSON output as something that needs sanitising, getting a javascript: URL into a JSON response is often easy. The researcher demonstrated this against a Mozilla endpoint, where a path segment is reflected into the JSON error output:

Text
https://token.services.mozilla.com/1.0/sync/javascript:alert(JSON.stringify(JSONView.headers.request%29%29

When the response is opened in the JSON Viewer, the value of the errors.0.name property is linkified. If the user clicks that link, an alert appears, which shows that JavaScript executed. The page runs under the null principal, so the code cannot read document.cookie, but it can reach the JSONView object that the viewer injects into the page. That object holds, among other things, all request headers, including cookies and authorization tokens.

The researcher also showed that the same mechanism can trigger saving of arbitrary content, although that was considered less critical:

Text
https://token.services.mozilla.com/1.0/sync/javascript:void(window.dispatchEvent(new%2520CustomEvent(%2527contentMessage%2527,%7Bdetail:%7Btype:%2527save%2527,value:%2527data:,foobar%2527%7D%7D%29%29%29

The report recommends that the JSON Viewer linkify only HTTP and HTTPS URLs. It points to the problematic line in reps.js at the given revision, and notes that data: and chrome: URLs are also accepted by the same code, though browser security mechanisms no longer allow navigating to those. The report does not record a bounty amount or a fix.

Root cause

The report does not describe the linkifier's implementation beyond naming the offending code line. The report names the offending code line in devtools/client/shared/components/reps/reps.js at revision [redacted]. The result is that attacker-influenced JSON content can produce a javascript: anchor inside a privileged browser UI, and a click on it executes script in the context of the viewer.

Impact

The executed script runs under the null principal, so it cannot read the page's cookies directly. It can, however, read the JSONView object, which exposes the request headers of the displayed response, including cookies and authorization tokens. That turns a reflected value in a JSON error response into a way to read credentials belonging to the request, provided the user clicks the linkified value. The same primitive can dispatch the viewer's save event to write arbitrary content, which the researcher rated as less serious. Exploitation depends on user interaction: the victim has to open the crafted URL in the JSON Viewer and click the link.

How this kind of bug works

Developer tools and other privileged interfaces often render untrusted data for convenience. When a renderer auto-detects URLs in text or structured data and turns them into links, it usually relies on a URL parser rather than on an explicit scheme allowlist. Parsers accept many schemes, and javascript: is a valid one. A click on such a link executes the URL body as script in the origin of the page that hosts the link, which here is the browser's own tooling context rather than the remote site.

The danger is amplified when the tooling injects its own objects into the rendered page, for example a global holding request metadata. Script running in that page can read those objects even when the principal is null, because the objects are reachable from the same window. The standard defence is to allowlist schemes (http and https only) before creating a link, and to avoid exposing sensitive request data to the rendered document.

How to test for it

  1. Identify features that render untrusted content as clickable links: JSON viewers, log viewers, network panels, markdown previews, diff views, and any developer tool that displays server responses.
  2. Find a way to get attacker-controlled text into that rendered output. Reflected path segments, query parameters, error messages and echoed headers are common sources.
  3. Place a harmless scheme probe such as a javascript: URL that calls an alert or writes to a global, and check whether the rendered value becomes a link and whether clicking it executes.
  4. If script executes, check what the surrounding page exposes: globals injected by the tool, request metadata, tokens, and any privileged APIs reachable from the window.
  5. A positive result is a clickable link with a non-HTTP scheme that runs script when activated. A common false positive is a value that looks like a link but is rendered as plain text, or a scheme that the browser refuses to navigate to.

How it is fixed

Restrict linkification to an explicit allowlist of safe schemes, typically http and https, and render everything else as plain text. Do not rely on the browser to block dangerous schemes. Where possible, avoid injecting sensitive request data such as headers and tokens into the document that displays untrusted content, and keep rendered content isolated from privileged globals.

Hunting notes

This class tends to hide in browser developer tools, internal dashboards, log and trace viewers, CI interfaces, and any product that pretty-prints JSON or XML from user-controlled sources. Recon signals include features that echo request data back into a rendered view, error pages that reflect input, and tools that expose request headers in the UI. To make a report land, show the full chain: the injection point, the rendered link, the executed script, and the sensitive data reachable from it, with a clear note that a click is required.

The original is short, so this covers everything it reports, then explains this kind of bug in general: how it works, how to test for it and how it is fixed. The general sections are about the bug class, not this target. Written with AI and checked against the original; the original is the record. 7 min read.

What happened, in plain words

Firefox ships with built-in developer tools, a set of panels for inspecting web pages and the traffic they make. One of these tools is the JSON Viewer. JSON is a plain text format that web services use to send structured data, for example a list of items or an error message. When a server answers with a response marked as application/json, Firefox shows it in the JSON Viewer, which formats the data so it is easier to read.

The researcher found that the JSON Viewer turns values inside the JSON into clickable links. That is handy when the data contains a normal web address. The problem is that the viewer does not check what kind of address it is. A javascript: address is also turned into a link. A javascript: address is not a place on the internet: it is a small piece of JavaScript code, the programming language of web pages, and a browser that follows such a link runs that code.

Web services usually do not treat their JSON output as something that needs cleaning, because JSON is just data, not a web page. So slipping a javascript: address into a JSON response is often easy. The researcher demonstrated this on a Mozilla service, where part of the requested address is copied into the JSON error output:

Text
https://token.services.mozilla.com/1.0/sync/javascript:alert(JSON.stringify(JSONView.headers.request%29%29

Reading this address from left to right: the first part is the normal service address. The last part, javascript:alert(...), is the code that ends up in the JSON output. The %29 at the end is an encoded closing bracket, so the code is alert(JSON.stringify(JSONView.headers.request)). alert shows a pop-up box, and JSON.stringify turns a data object into readable text. In short: show me the request headers as text in a pop-up.

When the response is opened in the JSON Viewer, the value of the errors.0.name property becomes a link. If the user clicks it, the pop-up appears, which proves the code ran. This matters because the code is not limited to showing a box. The page runs under the null principal, a deliberately powerless identity that stops the code from reading things like document.cookie, the browser's stored cookies for a site. A cookie is a small piece of data a site asks the browser to keep and send back with later requests, and it is often used to keep you logged in.

Even without cookies, the code can reach the JSONView object that the viewer itself puts into the page. That object holds, among other things, all request headers of the displayed response, including cookies and authorization tokens. A token is a secret string that proves who you are, much like a wristband at an event: show it and you are let in. So a click on a linkified value can hand those secrets to the injected code.

The researcher also showed that the same mechanism can trigger saving of arbitrary content, though that was considered less critical:

Text
https://token.services.mozilla.com/1.0/sync/javascript:void(window.dispatchEvent(new%2520CustomEvent(%2527contentMessage%2527,%7Bdetail:%7Btype:%2527save%2527,value:%2527data:,foobar%2527%7D%7D%29%29%29

Here the code does not show a box but dispatches the viewer's save event with the content foobar. The many %25 and %27 sequences are encoded characters (a percent sign and a quote), needed so the whole thing survives being placed inside a URL.

The report recommends that the JSON Viewer linkify only HTTP and HTTPS addresses, the two normal kinds of web address. It points to the problematic line in reps.js at the given revision, and notes that data: and chrome: addresses are also accepted by the same code, though browser security mechanisms no longer allow navigating to those. The report does not record a bounty amount or a fix.

In general, how this kind of bug works

Developer tools and other privileged interfaces often display untrusted data for convenience. When such a viewer spots something that looks like a web address and turns it into a link, it usually relies on a general URL parser rather than on an explicit list of allowed schemes. A scheme is the first part of an address, the https in https://.... Parsers accept many schemes, and javascript: is a valid one. A click on such a link runs the address body as code in the page that hosts the link, which here is the browser's own tooling rather than the remote site.

The danger grows when the tooling puts its own objects into the displayed page, for example a global holding request details. Code running in that page can read those objects even when the principal is null, because the objects sit in the same window. The standard defence is to allow only http and https before creating a link, and to avoid exposing sensitive request data to the displayed document.

How to test for it

  1. Look for features that render untrusted content as clickable links: JSON viewers, log viewers, network panels, markdown previews, diff views, and any developer tool that displays server responses.
  2. Find a way to get attacker-controlled text into that rendered output. Reflected path segments, query parameters, error messages and echoed headers are common sources.
  3. Place a harmless probe such as a javascript: address that calls an alert or writes to a global, and check whether the value becomes a link and whether clicking it runs code.
  4. If code runs, check what the surrounding page exposes: globals injected by the tool, request metadata, tokens, and any privileged interfaces reachable from the window.
  5. A positive result is a clickable link with a non-HTTP scheme that runs code when activated. A common false positive is a value that looks like a link but is shown as plain text, or a scheme the browser refuses to follow.

How it is fixed

Restrict linkification to an explicit list of safe schemes, typically http and https, and show everything else as plain text. Do not rely on the browser to block dangerous schemes. Where possible, avoid putting sensitive request data such as headers and tokens into the document that displays untrusted content, and keep displayed content isolated from privileged globals.

Hunting notes

This class tends to hide in browser developer tools, internal dashboards, log and trace viewers, build interfaces, and any product that pretty-prints JSON or XML from user-controlled sources. Signals worth watching are features that echo request data back into a rendered view, error pages that reflect input, and tools that show request headers in the interface. To make a report land, show the full chain: the injection point, the rendered link, the code that ran, and the sensitive data reachable from it, with a clear note that a click is required.

Glossary

  • JSON: a plain text format for structured data, widely used by web services.
  • JSON Viewer: the Firefox developer tool that formats and displays JSON responses.
  • DevTools: the set of developer tools built into Firefox.
  • Content type: a label on a response saying what kind of data it contains, such as application/json.
  • Linkify: to detect text that looks like a web address and turn it into a clickable link.
  • Scheme: the first part of an address, such as https or javascript, saying how to handle it.
  • javascript: URL: an address whose body is code that the browser runs when the link is followed.
  • JavaScript: the programming language that runs in web pages and in browser tooling.
  • Request: a message a browser sends to a server asking for something.
  • Response: the server's reply to a request.
  • Header: a labelled piece of metadata sent with a request or response.
  • Cookie: a small piece of data a site asks the browser to store and send back later, often used to keep you logged in.
  • Token: a secret string that proves identity or grants access.
  • Authorization token: a token sent with a request to prove the sender is allowed to make it.
  • Null principal: a deliberately powerless identity that blocks access to things like a page's cookies.
  • Principal: the identity a piece of code runs under, which decides what it may access.
  • Global / JSONView object: a named object placed in the page by the viewer, here holding request details.
  • Sanitise: to clean input so that it cannot do anything harmful when displayed.
  • Allowlist: an explicit list of things that are permitted, with everything else refused.
  • Reflected value: input that a server copies back into its output.
  • data: URL: an address that carries its content inline instead of pointing to a server.
  • chrome: URL: a Firefox-internal address scheme for its own interface.
  • Severity: a rating of how serious a bug is, here medium.
  • User interaction: the requirement that the victim performs an action, here a click, for the bug to work.

More by Wladimir Palant

View all

30 more disclosed reports, best first.

More from Mozilla

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.