Skip to content
Access control Write-up Advanced

Running code within the DevTools

Several flaws in Chromium and Edge DevTools let a malicious extension run code inside the privileged DevTools context, for example by passing an unvalidated remoteBase parameter or a javascript: devtools_page entry. From there the extension could read local files, script other extensions and ultimately escape the browser sandbox.

David Erceg Follow

Published on microsoftedge.github.io

Bounty$36,000 View original

Within Chromium and its derivatives, the DevTools is an interesting attack surface. That’s because the DevTools itself is fairly highly privileged, especially if it’s attached to a page as part of a debugging session.

David Erceg, on microsoftedge.github.io

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.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 12 min read.

Context

This is a guest post on the Microsoft Edge bug bounty blog by David Erceg, published on 21 July 2021. It describes a class of bugs in the Chromium DevTools, and specifically in Edge, that let a malicious browser extension run code inside the DevTools context and, from there, escape the browser sandbox.

The target is the DevTools frontend that ships with Chromium and its derivatives. The DevTools is a privileged surface: when it is attached to a page as part of a debugging session, it can script that page and it has access to the full Chrome DevTools Protocol. An extension normally has a much narrower set of capabilities. The post's premise is that an extension which can load DevTools URLs can take advantage of bugs in the DevTools to escalate its privileges.

The report covers three distinct issues that allowed an extension to run code in the DevTools context:

  1. An Edge issue in the remoteBase query parameter of inspector.html.
  2. A Chromium issue where the devtools_page manifest entry was not validated (issue 1059577).
  3. A Chromium issue where crafted channel messages from an extension's DevTools page could overwrite values in the DevTools (issue 1064519).

It then describes what the DevTools context grants (reading local files, scripting extensions and arbitrary sites, the Chrome DevTools Protocol) and two routes to sandbox escape.

Setup

The report does not describe a formal lab setup. The tools and preconditions it mentions are:

  • A Chromium or Edge browser with the ability to load an extension.
  • An extension that logs requests passed to chrome.webRequest.onBeforeRequest.
  • The ability to open and undock a DevTools window and then debug that DevTools instance with Ctrl + Shift + I.
  • For the sandbox escape via the Chrome DevTools Protocol, an extension with the debugger permission, which can dispatch input events including the browser shortcut to open the DevTools.

On Edge, the DevTools JavaScript is minified and the original source is not available at source.chromium.org, so the researcher debugged through the minified code. On Chrome, the original source can be consulted at source.chromium.org.

Finding it

The starting observation was a request that appeared when opening the DevTools while logging requests through the webRequest API:

Text
https://devtools.azureedge.net/serve_file/@[redacted]/third_party/webhint/worker_frame.html

The researcher notes a side technique here: logging all requests passed to chrome.webRequest.onBeforeRequest and then loading a privileged page can reveal cases where a privileged page loads an unprivileged page in a frame. Those requests can then be redirected to a page the attacker controls, and if message passing between the frame and its privileged parent is flawed, code may run in the parent's context.

The next step was to find how the DevTools constructed that URL. Debugging the undocked DevTools window led to the insight that the URL was built directly from the remoteBase query parameter without validation. A quick test confirmed it:

Text
devtools://devtools/bundled/inspector.html?remoteBase=javascript:console.log('Frame content set by query parameter')//

The javascript: portion ends in a comment because the DevTools appends third_party/webhint/worker_frame.html to the base URL. If remoteBase is used to add an iframe to inspector.html, the iframe points at a javascript: URL and is same-origin with its parent, so the injected code runs in the DevTools context.

The report notes that this general issue had affected Chromium before: a very similar problem was first reported in issue 571121, and the fix made there was shown to be insufficient in issue 619414.

A second finding concerned the devtools_page manifest entry. That entry refers to an extension page loaded in an iframe within the DevTools, with access to chrome.devtools.inspectedWindow, chrome.devtools.network and chrome.devtools.panels. In Chromium it used to be that the devtools_page entry was not validated either (issue 1059577), so setting it to a javascript: URL caused Chromium to load that URL in an iframe within the DevTools, and that frame could script the parent DevTools instance.

A third finding combined devtools_page with the debugger permission. The debugger permission lets an extension use the Chrome DevTools Protocol to debug a page, though not the full set of methods: Browser.setDownloadBehavior is restricted (issue 866426). An extension with the debugger permission can dispatch input events, including the browser shortcut to open the DevTools. The extension's DevTools page can then script the target page. Previously there were no restrictions (issues 1059577 and 795595) on when an extension page could script the target page, for example via chrome.devtools.inspectedWindow.eval. So if the DevTools was opened on a tab and the tab was navigated to a privileged page, any extension page loaded in the DevTools could script that privileged page. Since the extension can open the DevTools itself, it could run code on any privileged page, including a DevTools page, using a devtools_page entry.

Exploitation

Step 1: Run code in the DevTools via remoteBase

Load the crafted URL:

Text
devtools://devtools/bundled/inspector.html?remoteBase=javascript:console.log('Frame content set by query parameter')//

The DevTools builds the iframe source by appending third_party/webhint/worker_frame.html to the remoteBase value. The trailing // comments out that appended path, leaving a javascript: URL that is same-origin with the parent. The result is code execution in the DevTools context.

Step 2: Run code in the DevTools via a devtools_page entry

Set the devtools_page manifest entry to a javascript: URL. Chromium loads that URL in an iframe within the DevTools, and the frame can script the parent DevTools instance. The report does not give a manifest snippet for this step.

Step 3: Overwrite DevTools state with crafted channel messages

The chrome.devtools API is implemented with the channel messaging API between two JavaScript contexts, the extension page and the DevTools. This differs from other extension APIs, which are written in C++ and run in the browser process. If the DevTools does not validate messages from an extension page, the extension page may run arbitrary code in the DevTools. Issue 1064519 describes such a case.

The central problem is that a MessageChannel carries data, not code. Overwriting a value in a target context does not directly invoke code. The route found was chrome.devtools.panels.create: the panel is created within the DevTools and contains the extension's page in an iframe. The full path to the page is built by appending the page's path to the extension's origin, and the origin is stored in JavaScript by the DevTools. Because of how it was stored, a specially crafted channel message could overwrite it. Setting the origin to a javascript: URL caused the DevTools to create an iframe with that URL as its source, allowing the extension to script the DevTools.

Step 4: Read local files from the DevTools context

The DevTools can read local files. The method is documented in several Chromium issues (653134, 662859, 607939). The following code, run in the DevTools context, logs the contents of file:///c:/:

JavaScript
let data = "";
DevToolsAPI.streamWrite = function (id, chunk) {
    data += chunk;
};
DevToolsAPI.sendMessageToEmbedder("loadNetworkResource", ["file:///c:/", "", 0], function (result) {
    console.log(data);
}
);

streamWrite is replaced so that chunks written by the embedder are accumulated in data, and sendMessageToEmbedder invokes loadNetworkResource on the local path. The callback logs the accumulated content.

Step 5: Script extensions and arbitrary sites with registerExtensionsAPI

The DevTools has custom API methods, one of which is registerExtensionsAPI. It sets up extension pages (the devtools_page entries) within the DevTools. The DevTools injects a script into an extension frame on every navigation of that frame, and that script uses channel messaging behind the scenes. The call site is:

JavaScript
setInjectedScriptForOrigin(origin, script) {
    DevToolsAPI.sendMessageToEmbedder('registerExtensionsAPI', [origin, script], null);
}

It takes an origin and a script. For example, in a DevTools context:

JavaScript
InspectorFrontendHost.setInjectedScriptForOrigin("https://en.wikipedia.org", "console.log('Script run in ' + location.href)//");

The script argument ends in a comment because the injected code has ("...guid...") appended to it. Without the comment the result would be console.log(...)("...guid..."), which is not valid. Then load the iframe:

JavaScript
let iframe = document.createElement("iframe");
iframe.src = "https://en.wikipedia.org/wiki/Main_Page";
document.body.appendChild(iframe);

Once the frame has loaded, the console shows:

Text
Script run in https://en.wikipedia.org/wiki/Main_Page

So code in the DevTools context can script any site that can be loaded in an iframe, including any http/https site whose page is not blocked by the frame-ancestors content security policy directive. It also includes any extension page, even those not listed under web_accessible_resources, because the DevTools can load any extension resource. Without that exception, the page listed under devtools_page would have to be web accessible for the DevTools to load it. Scripting builtin extensions is useful because they typically have access to private APIs.

Step 6: Use the Chrome DevTools Protocol

When the DevTools is attached to a page, code in its context can script any page, however privileged. Unlike an extension using the debugger API, which is detached when the target page navigates to a privileged location, the DevTools can debug any page. It also has full access to the Chrome DevTools Protocol, including methods extensions cannot call, such as Browser.setDownloadBehavior.

There is a distinction between attached and unattached. Opening the DevTools in a tab with Ctrl + Shift + I or F12 attaches it to the page in that tab. Loading a DevTools URL directly in the browser leaves it unattached, so the Chrome DevTools Protocol is not usable.

Step 7: Escape the sandbox by targeting an extension

In Edge, the Edge Feedback App had access to a chrome.edgeFeedbackPrivate API with a method named saveBytesToFile. It did not validate the paths it received, so a file could be written to an arbitrary location, for example an executable into the user's startup folder, which would run on the next login. That issue is fixed, and App pages can no longer be loaded in regular tabs. chrome://extensions-internals lists all loaded extensions, including component (builtin) extensions that chrome://extensions does not show, which helps identify targets. Once an extension is chosen, load a page from it and check which APIs are available.

Step 8: Escape the sandbox via the Chrome DevTools Protocol

The protocol is only available when the DevTools is attached, so either the user opens the DevTools manually or the extension opens it, for example by sending the F12 key event with Input.dispatchKeyEvent, which requires the debugger permission. The steps are:

  1. Add a console pin in the DevTools:

    JavaScript
    let pin = "..."; // Contains the code to run
    localStorage.consolePins = JSON.stringify([pin]);
    

    This does not need an attached DevTools instance. In the DevTools UI a console pin is called a "live expression", though the localStorage key is consolePins.

  2. Open an attached DevTools instance by one of the two ways above.

  3. Navigate the debugged page to chrome://downloads. It is one of the few places where a local file can legitimately be opened. To open a file, call the OpenFileRequiringGesture mojo method available to that page. As the name suggests, a recent user gesture is required, specifically one received within the last five seconds. This can be done by sending a key event with Input.dispatchKeyEvent, which is needed anyway if the extension opens the DevTools with the debugger permission.

  4. The console pin is regularly re-evaluated on the target page, so its code runs in the context of chrome://downloads. The pin can then call OpenFileRequiringGesture to open a downloaded executable. This is an indirect use of the Chrome DevTools Protocol, since console pins internally use Runtime.evaluate to evaluate the code in the target page's context.

Root cause

The common root cause is missing validation of values that the DevTools trusts. In the Edge case, the remoteBase query parameter was used to construct an iframe source without validation, so a javascript: URL became same-origin with the DevTools. In the devtools_page case, the manifest entry was not validated, so a javascript: URL was loaded in an iframe inside the DevTools. In the channel messaging case, the extension origin was stored in JavaScript in a way that a crafted channel message could overwrite, and the DevTools then built a panel iframe source from it.

The design factor is that the chrome.devtools API is implemented in JavaScript over channel messaging rather than in C++ in the browser process, which gives an extension page a direct message channel into a privileged context. Existing defences did not stop these issues: the earlier Chromium fix for the remoteBase-style problem (issue 571121) was insufficient (issue 619414), and the restrictions on when an extension page could script the target page were absent (issues 1059577 and 795595).

Impact

An extension that can load DevTools URLs can, through these bugs, run code in the DevTools context. From there it can read local files, script any http/https site loadable in an iframe (subject to frame-ancestors), script any extension including builtin extensions with private APIs, and, when the DevTools is attached, use the full Chrome DevTools Protocol. The report describes two sandbox escape routes: attacking a higher-privileged extension such as the Edge Feedback App to write a file to an arbitrary location, and using console pins plus chrome://downloads and OpenFileRequiringGesture to open a downloaded executable. The report hedges that the protocol route requires either the user to open the DevTools manually or the extension to have the debugger permission, and that the frame-ancestors directive can block some sites.

On rewards: the Edge Feedback App issue was assessed as moderate severity and was not eligible for a reward, since at the time only higher severity issues were rewarded under the Microsoft Edge Bounty Program. The remoteBase issue was rewarded $30,000 USD, and with the other two Chromium issues (1059577 and 1064519) the total was $36,000 USD.

Fix

The report says the Edge Feedback App issue is fixed and that App pages can no longer be loaded in regular tabs. It mentions the Chromium issues by number (571121, 619414, 1059577, 1064519) without describing the code changes, and notes that the fix for 571121 was shown to be insufficient in 619414.

Variants to test

  • Log requests with chrome.webRequest.onBeforeRequest while loading privileged pages, and look for privileged pages framing unprivileged content. A positive result is a request you can redirect to a page you control where message passing with the parent is flawed.
  • Try remoteBase and similar base-URL parameters with javascript: values on DevTools URLs. A positive result is an iframe whose source is a javascript: URL same-origin with the DevTools.
  • Set devtools_page to a javascript: URL. A positive result is that URL loading in an iframe inside the DevTools and scripting the parent.
  • Send crafted channel messages to the DevTools to overwrite stored values such as the extension origin used by chrome.devtools.panels.create. A positive result is a panel iframe with a javascript: source.
  • Call registerExtensionsAPI with an origin and a script, then load a frame for that origin. A positive result is the script running in the frame, including for extension pages not listed in web_accessible_resources.
  • Check chrome://extensions-internals for builtin extensions and inspect their available APIs for methods that do not validate paths or inputs, such as file-writing methods. A positive result is writing a file to an arbitrary location.
  • Test console pins plus chrome://downloads and OpenFileRequiringGesture with a recent user gesture. A positive result is a downloaded executable being opened.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 21 min read.

What happened, in plain words

A security researcher named David Erceg wrote a guest post for Microsoft's Edge bug bounty blog, published on 21 July 2021. In it he explains a family of bugs in the DevTools, the built-in set of tools that ships with Chromium-based browsers such as Chrome and Edge, and how a malicious browser extension could abuse them.

To follow the story you only need to know a few everyday ideas. A browser extension is a small add-on program you install into your browser, for example an ad blocker or a password manager. Extensions are written in JavaScript and run inside the browser, but they are supposed to be kept in a box: they can do some things, not everything. A sandbox is that box. It is an operating system feature that stops a program from touching your files or other programs unless it is explicitly allowed to. The whole point of the sandbox is that if a website or an extension is malicious, the damage stays contained.

The DevTools is the debugging panel you open with F12 or Ctrl + Shift + I. It lets you inspect a web page, read its code, watch network requests and run snippets of JavaScript against the page. Because it is a tool for developers, it is deliberately powerful. When it is attached to a page, it can run code in that page and it can talk to a low-level interface called the Chrome DevTools Protocol, which is the same interface the browser itself uses internally to control pages. An ordinary extension has nothing like that power.

The researcher's premise is simple: if an extension can make the browser load a DevTools address, and the DevTools has bugs, the extension can use those bugs to climb from its small box into the DevTools' much bigger box. From there it may be able to read your local files, run code in other extensions, and eventually break out of the sandbox entirely.

The post describes three separate bugs that let an extension run code inside the DevTools:

  1. An Edge bug in a URL parameter called remoteBase on the DevTools page inspector.html.
  2. A Chromium bug where a setting in an extension's manifest file, the devtools_page entry, was not checked (Chromium issue 1059577).
  3. A Chromium bug where specially crafted messages sent over a browser messaging channel could overwrite values inside the DevTools (Chromium issue 1064519).

It then explains what running code in the DevTools actually buys an attacker, and describes two routes from there to a full sandbox escape.

The setup

The report does not describe a formal lab. It lists the tools and preconditions it uses:

  • A Chromium or Edge browser that can load an extension.
  • An extension that logs every request passed to chrome.webRequest.onBeforeRequest. In plain terms, chrome.webRequest is an extension interface that lets an extension watch network traffic, and onBeforeRequest is the moment just before a request leaves the browser.
  • The ability to open a DevTools window, undock it (pop it out into its own window), and then debug that DevTools window itself with Ctrl + Shift + I. Yes, you can open DevTools on DevTools.
  • For the second sandbox escape route, an extension with the debugger permission. A permission is a capability an extension declares in its manifest and the user approves at install time. The debugger permission lets the extension drive the Chrome DevTools Protocol against pages.

One practical wrinkle: on Edge the DevTools JavaScript is minified, meaning the code has been squashed and renamed to be small, and the original readable source is not published at source.chromium.org the way Chrome's is. So on Edge the researcher had to step through the minified code by hand. On Chrome the original source can simply be read at source.chromium.org.

Finding it

The starting point was a request that appeared when the DevTools was opened, captured by logging traffic through the webRequest API:

Text
https://devtools.azureedge.net/serve_file/@[redacted]/third_party/webhint/worker_frame.html

Line by line: this is a single URL. The host is devtools.azureedge.net, a content delivery network. The path includes a long hash-like folder name and then third_party/webhint/worker_frame.html, which is a small helper page belonging to a tool called webhint. The interesting part is not the file itself but the fact that the privileged DevTools was loading it at all.

The researcher notes a side technique here, and it is worth spelling out because it is a general trick. If you log every request passed to chrome.webRequest.onBeforeRequest and then load a privileged page, you may spot cases where a privileged page loads an unprivileged page inside a frame. A frame (an iframe) is a page embedded inside another page. If you can see that request, you can redirect it to a page you control. Then, if the message passing between the frame and its privileged parent is flawed, you may get code running in the parent's context. Think of it as noticing that a bank manager's office has a serving hatch to the street, and then standing at that hatch.

The next step was to work out exactly how the DevTools built that URL. Debugging the undocked DevTools window led to the insight that the URL was assembled directly from the remoteBase query parameter with no validation. A query parameter is the name=value part after the ? in a URL. A quick test confirmed it:

Text
devtools://devtools/bundled/inspector.html?remoteBase=javascript:console.log('Frame content set by query parameter')//

Line by line: devtools:// is a special internal address scheme, like https:// but for the browser's own DevTools pages. devtools/bundled/inspector.html is the DevTools page being loaded. ?remoteBase= starts the query string, and everything after it is the value the page will read. That value begins with javascript:, which is a URL scheme that means "run the code that follows as JavaScript". The code is console.log('Frame content set by query parameter'), which prints a message to the console. The trailing // starts a JavaScript comment, so anything appended after it is ignored.

Why the comment? Because the DevTools appends third_party/webhint/worker_frame.html to whatever base URL it is given. Without the //, the result would be javascript:console.log(...)third_party/webhint/worker_frame.html, which is not valid JavaScript. With the //, the appended path is commented out and the code stays valid.

If remoteBase is used to add an iframe to inspector.html, the iframe points at a javascript: URL and is same-origin with its parent. Same-origin means the browser treats the two as coming from the same place, so they are allowed to read and script each other freely. The result is that the injected code runs in the DevTools context.

The report notes this general issue had hit Chromium before: a very similar problem was first reported in issue 571121, and the fix made there was shown to be insufficient in issue 619414. In other words, the first patch did not close the hole.

A second finding concerned the devtools_page manifest entry. A manifest is the configuration file every extension must have; it declares the extension's name, permissions and entry points. The devtools_page entry names an extension page that the DevTools loads in an iframe, and that page gets access to three extension interfaces: chrome.devtools.inspectedWindow (inspect and script the page being debugged), chrome.devtools.network (read network activity) and chrome.devtools.panels (add custom panels to the DevTools UI). In Chromium it used to be that the devtools_page entry was not validated either (issue 1059577). So if you set it to a javascript: URL, Chromium loaded that URL in an iframe inside the DevTools, and that frame could script the parent DevTools instance.

A third finding combined devtools_page with the debugger permission. The debugger permission lets an extension use the Chrome DevTools Protocol to debug a page, though not the full set of methods: Browser.setDownloadBehavior is restricted (issue 866426). An extension with the debugger permission can dispatch input events, including the browser shortcut that opens the DevTools. Think of it as an extension being allowed to press F12 on your behalf. The extension's DevTools page can then script the target page. Previously there were no restrictions (issues 1059577 and 795595) on when an extension page could script the target page, for example via chrome.devtools.inspectedWindow.eval. So if the DevTools was opened on a tab and the tab was navigated to a privileged page, any extension page loaded in the DevTools could script that privileged page. Since the extension can open the DevTools itself, it could run code on any privileged page, including a DevTools page, using a devtools_page entry.

Exploitation

Step 1: Run code in the DevTools via remoteBase

Load the crafted URL:

Text
devtools://devtools/bundled/inspector.html?remoteBase=javascript:console.log('Frame content set by query parameter')//

Line by line: the browser opens the internal DevTools page inspector.html. The page reads remoteBase and builds an iframe source by appending third_party/webhint/worker_frame.html to it. The trailing // comments out that appended path, leaving a javascript: URL that is same-origin with the parent. The browser then runs the JavaScript in the DevTools context. The reason this step was taken is that it is the simplest possible proof: one URL, no extension code needed beyond the ability to make the browser load it.

Step 2: Run code in the DevTools via a devtools_page entry

Set the devtools_page manifest entry to a javascript: URL. Chromium loads that URL in an iframe within the DevTools, and the frame can script the parent DevTools instance. The report does not give a manifest snippet for this step, so there is nothing to copy here. The reason this matters is that it needs no special URL parameter at all: the extension simply declares a bad value in its own manifest and the browser trusts it.

Step 3: Overwrite DevTools state with crafted channel messages

The chrome.devtools API is implemented with the channel messaging API between two JavaScript contexts, the extension page and the DevTools. An API is simply a set of functions one program offers to another; here it is the set of functions the DevTools offers to extension pages. Channel messaging is a browser feature that lets two separate JavaScript contexts pass messages to each other, like two people with a private phone line. This differs from other extension APIs, which are written in C++ and run in the browser process. C++ code in the browser process is harder to reach from a web page; JavaScript talking to JavaScript is much easier to influence.

If the DevTools does not validate messages from an extension page, the extension page may run arbitrary code in the DevTools. Issue 1064519 describes such a case.

The central problem is that a MessageChannel carries data, not code. Overwriting a value in a target context does not directly invoke code. Think of it as being able to change a number on a form but not being allowed to write new instructions on the form. The route found was chrome.devtools.panels.create: the panel is created within the DevTools and contains the extension's page in an iframe. The full path to the page is built by appending the page's path to the extension's origin, and the origin is stored in JavaScript by the DevTools. An origin is the combination of scheme, host and port, for example https://example.com; it is the browser's basic unit of trust. Because of how it was stored, a specially crafted channel message could overwrite it. Setting the origin to a javascript: URL caused the DevTools to create an iframe with that URL as its source, allowing the extension to script the DevTools. The reason this step was taken is that it turns a data-only channel into code execution, which is the whole trick.

Step 4: Read local files from the DevTools context

The DevTools can read local files. The method is documented in several Chromium issues (653134, 662859, 607939). The following code, run in the DevTools context, logs the contents of file:///c:/:

JavaScript
let data = "";
DevToolsAPI.streamWrite = function (id, chunk) {
    data += chunk;
};
DevToolsAPI.sendMessageToEmbedder("loadNetworkResource", ["file:///c:/", "", 0], function (result) {
    console.log(data);
}
);

Line by line: let data = ""; creates an empty string to collect output. DevToolsAPI.streamWrite = function (id, chunk) { data += chunk; }; replaces the DevTools' own streaming function with one that appends each incoming chunk to data. This is needed because the file is delivered in pieces, not all at once. DevToolsAPI.sendMessageToEmbedder("loadNetworkResource", ["file:///c:/", "", 0], function (result) { ... }); asks the browser side of the DevTools to load a resource. The first argument names the operation, loadNetworkResource. The array holds the arguments: the path file:///c:/ (the root of the C: drive on Windows), an empty string, and 0. The final function is a callback that runs when the load finishes. console.log(data); prints everything collected. The reason this step was taken is to show that the DevTools context is not just a web page: it can reach the local disk.

Step 5: Script extensions and arbitrary sites with registerExtensionsAPI

The DevTools has custom API methods, one of which is registerExtensionsAPI. It sets up extension pages (the devtools_page entries) within the DevTools. The DevTools injects a script into an extension frame on every navigation of that frame, and that script uses channel messaging behind the scenes. The call site is:

JavaScript
setInjectedScriptForOrigin(origin, script) {
    DevToolsAPI.sendMessageToEmbedder('registerExtensionsAPI', [origin, script], null);
}

Line by line: this defines a function named setInjectedScriptForOrigin that takes two arguments, an origin and a script. Inside, it calls DevToolsAPI.sendMessageToEmbedder with the operation name 'registerExtensionsAPI', an array containing the origin and the script, and null as the last argument. In effect, it tells the browser: whenever a frame from this origin loads, inject this script into it.

It takes an origin and a script. For example, in a DevTools context:

JavaScript
InspectorFrontendHost.setInjectedScriptForOrigin("https://en.wikipedia.org", "console.log('Script run in ' + location.href)//");

Line by line: InspectorFrontendHost is the object the DevTools page uses to talk to the browser side. setInjectedScriptForOrigin is the function above. The first argument is the origin https://en.wikipedia.org. The second is the script to inject: console.log('Script run in ' + location.href)//. That script prints the text Script run in followed by the current page address, location.href. The trailing // is a comment again, and for the same reason: the injected code has ("...guid...") appended to it, where a guid is a long unique identifier string. Without the comment the result would be console.log(...)("...guid..."), which is not valid JavaScript. With the comment, the appended part is ignored.

Then load the iframe:

JavaScript
let iframe = document.createElement("iframe");
iframe.src = "https://en.wikipedia.org/wiki/Main_Page";
document.body.appendChild(iframe);

Line by line: let iframe = document.createElement("iframe"); creates a new iframe element in memory. iframe.src = "https://en.wikipedia.org/wiki/Main_Page"; sets its address to a Wikipedia page. document.body.appendChild(iframe); puts the iframe into the page, which makes the browser load it. The reason this step was taken is to prove that the injected script really runs inside the frame.

Once the frame has loaded, the console shows:

Text
Script run in https://en.wikipedia.org/wiki/Main_Page

So code in the DevTools context can script any site that can be loaded in an iframe, including any http/https site whose page is not blocked by the frame-ancestors content security policy directive. A content security policy is a set of rules a website sends to the browser saying what it is allowed to do; frame-ancestors specifically says which pages may embed it in a frame. It also includes any extension page, even those not listed under web_accessible_resources, because the DevTools can load any extension resource. web_accessible_resources is the manifest list of an extension's files that web pages are allowed to load; without the DevTools exception, the page listed under devtools_page would have to be on that list for the DevTools to load it. Scripting builtin extensions is useful because they typically have access to private APIs, which gives further options to escalate privileges.

Step 6: Use the Chrome DevTools Protocol

When the DevTools is attached to a page, code in its context can script any page, however privileged. Attached means the DevTools has an active debugging session with a particular tab. Unlike an extension using the debugger API, which is detached when the target page navigates to a privileged location, the DevTools can debug any page. It also has full access to the Chrome DevTools Protocol, including methods extensions cannot call, such as Browser.setDownloadBehavior.

There is a distinction between attached and unattached. Opening the DevTools in a tab with Ctrl + Shift + I or F12 attaches it to the page in that tab. Loading a DevTools URL directly in the browser leaves it unattached, so the Chrome DevTools Protocol is not usable. The reason this distinction matters is that the protocol is the powerful part, and it only works when there is a page to talk to.

Step 7: Escape the sandbox by targeting an extension

In Edge, the Edge Feedback App had access to a chrome.edgeFeedbackPrivate API with a method named saveBytesToFile. It did not validate the paths it received, so a file could be written to an arbitrary location, for example an executable into the user's startup folder, which would run on the next login. The startup folder is the place Windows looks at login to decide which programs to start automatically, so writing there is a classic way to get code to run. That issue is fixed, and App pages can no longer be loaded in regular tabs. chrome://extensions-internals lists all loaded extensions, including component (builtin) extensions that chrome://extensions does not show, which helps identify targets. Once an extension is chosen, load a page from it and check which APIs are available. The reason this step was taken is that a builtin extension with a private API is often a softer target than the browser itself.

Step 8: Escape the sandbox via the Chrome DevTools Protocol

The protocol is only available when the DevTools is attached, so either the user opens the DevTools manually or the extension opens it, for example by sending the F12 key event with Input.dispatchKeyEvent, which requires the debugger permission. The steps are:

  1. Add a console pin in the DevTools:

    JavaScript
    let pin = "..."; // Contains the code to run
    localStorage.consolePins = JSON.stringify([pin]);
    

    Line by line: let pin = "..."; creates a variable holding the code you want to run later; the ... is a placeholder for that code. localStorage.consolePins = JSON.stringify([pin]); stores it. localStorage is a small key-value store that a page can keep in the browser between visits. JSON.stringify([pin]) turns the code into a JSON text string wrapped in an array, because that is the format the DevTools expects. A console pin is a snippet the DevTools keeps re-running against the page being debugged. This does not need an attached DevTools instance. In the DevTools UI a console pin is called a "live expression", though the localStorage key is consolePins.

  2. Open an attached DevTools instance by one of the two ways above.

  3. Navigate the debugged page to chrome://downloads. It is one of the few places where a local file can legitimately be opened. To open a file, call the OpenFileRequiringGesture mojo method available to that page. Mojo is Chromium's internal messaging system between parts of the browser. As the name suggests, a recent user gesture is required, specifically one received within the last five seconds. A user gesture is a real action by the user, such as a click or key press, that the browser can verify. This can be done by sending a key event with Input.dispatchKeyEvent, which is needed anyway if the extension opens the DevTools with the debugger permission.

  4. The console pin is regularly re-evaluated on the target page, so its code runs in the context of chrome://downloads. The pin can then call OpenFileRequiringGesture to open a downloaded executable. This is an indirect use of the Chrome DevTools Protocol, since console pins internally use Runtime.evaluate to evaluate the code in the target page's context. The reason this step was taken is that it chains three ordinary features, a stored pin, a downloads page and a gesture check, into a way to launch a program.

Root cause

The common root cause is missing validation of values that the DevTools trusts. In the Edge case, the remoteBase query parameter was used to construct an iframe source without validation, so a javascript: URL became same-origin with the DevTools. In the devtools_page case, the manifest entry was not validated, so a javascript: URL was loaded in an iframe inside the DevTools. In the channel messaging case, the extension origin was stored in JavaScript in a way that a crafted channel message could overwrite, and the DevTools then built a panel iframe source from it.

The design factor is that the chrome.devtools API is implemented in JavaScript over channel messaging rather than in C++ in the browser process, which gives an extension page a direct message channel into a privileged context. Existing defences did not stop these issues: the earlier Chromium fix for the remoteBase-style problem (issue 571121) was insufficient (issue 619414), and the restrictions on when an extension page could script the target page were absent (issues 1059577 and 795595).

Impact

An extension that can load DevTools URLs can, through these bugs, run code in the DevTools context. From there it can read local files, script any http/https site loadable in an iframe (subject to frame-ancestors), script any extension including builtin extensions with private APIs, and, when the DevTools is attached, use the full Chrome DevTools Protocol. The report describes two sandbox escape routes: attacking a higher-privileged extension such as the Edge Feedback App to write a file to an arbitrary location, and using console pins plus chrome://downloads and OpenFileRequiringGesture to open a downloaded executable. The report hedges that the protocol route requires either the user to open the DevTools manually or the extension to have the debugger permission, and that the frame-ancestors directive can block some sites.

On rewards: the Edge Feedback App issue was assessed as moderate severity and was not eligible for a reward, since at the time only higher severity issues were rewarded under the Microsoft Edge Bounty Program. The remoteBase issue was rewarded $30,000 USD, and with the other two Chromium issues (1059577 and 1064519) the total was $36,000 USD.

Fix

The report says the Edge Feedback App issue is fixed and that App pages can no longer be loaded in regular tabs. It mentions the Chromium issues by number (571121, 619414, 1059577, 1064519) without describing the code changes, and notes that the fix for 571121 was shown to be insufficient in 619414.

Variants to test

  • Log requests with chrome.webRequest.onBeforeRequest while loading privileged pages, and look for privileged pages framing unprivileged content. A positive result is a request you can redirect to a page you control where message passing with the parent is flawed.
  • Try remoteBase and similar base-URL parameters with javascript: values on DevTools URLs. A positive result is an iframe whose source is a javascript: URL same-origin with the DevTools.
  • Set devtools_page to a javascript: URL. A positive result is that URL loading in an iframe inside the DevTools and scripting the parent.
  • Send crafted channel messages to the DevTools to overwrite stored values such as the extension origin used by chrome.devtools.panels.create. A positive result is a panel iframe with a javascript: source.
  • Call registerExtensionsAPI with an origin and a script, then load a frame for that origin. A positive result is the script running in the frame, including for extension pages not listed in web_accessible_resources.
  • Check chrome://extensions-internals for builtin extensions and inspect their available APIs for methods that do not validate paths or inputs, such as file-writing methods. A positive result is writing a file to an arbitrary location.
  • Test console pins plus chrome://downloads and OpenFileRequiringGesture with a recent user gesture. A positive result is a downloaded executable being opened.

Glossary

  • API: a set of functions one program offers to another so they can talk to each other.
  • Attached (DevTools): the state where the DevTools has an active debugging session with a particular tab.
  • Browser extension: a small add-on program installed into a browser, written in JavaScript, with declared permissions.
  • Callback: a function passed to another function, to be run when some work finishes.
  • Channel messaging: a browser feature that lets two separate JavaScript contexts pass messages to each other.
  • Chrome DevTools Protocol: the low-level interface the browser uses internally to control and inspect pages.
  • Console pin (live expression): a snippet of code the DevTools keeps re-running against the page being debugged.
  • Content security policy: rules a website sends to the browser saying what it is allowed to do.
  • C++: a compiled programming language used for the browser's own internal code.
  • DevTools: the built-in debugging panel in Chromium-based browsers, opened with F12 or Ctrl + Shift + I.
  • debugger permission: an extension permission that lets the extension drive the Chrome DevTools Protocol against pages.
  • devtools_page: a manifest entry naming an extension page that the DevTools loads in an iframe.
  • frame-ancestors: a content security policy directive saying which pages may embed a site in a frame.
  • Frame (iframe): a page embedded inside another page.
  • Guid: a long unique identifier string.
  • JavaScript: the programming language web pages and extensions run in the browser.
  • javascript: URL: a URL scheme that means "run the code that follows as JavaScript".
  • localStorage: a small key-value store a page can keep in the browser between visits.
  • Manifest: the configuration file every extension must have, declaring its name, permissions and entry points.
  • MessageChannel: the object used to send messages over channel messaging; it carries data, not code.
  • Minified: code that has been squashed and renamed to be small, making it hard to read.
  • Mojo: Chromium's internal messaging system between parts of the browser.
  • Origin: the combination of scheme, host and port, for example https://example.com; the browser's basic unit of trust.
  • Permission: a capability an extension declares in its manifest and the user approves at install time.
  • Query parameter: the name=value part after the ? in a URL.
  • Sandbox: an operating system feature that stops a program from touching files or other programs unless explicitly allowed.
  • Same-origin: two pages the browser treats as coming from the same place, so they may read and script each other.
  • Startup folder: the place Windows looks at login to decide which programs to start automatically.
  • User gesture: a real action by the user, such as a click or key press, that the browser can verify.
  • web_accessible_resources: the manifest list of an extension's files that web pages are allowed to load.
  • webRequest: an extension interface that lets an extension watch network traffic.

More by David Erceg

View all

1 more disclosed report, best first.

More from Microsoft

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.