Skip to content
XSS Advisory Advanced CVE-2024-3172

Insufficient data validation in DevTools (CVE-2024-3172)

A cross-site scripting flaw in the Chrome DevTools frontend allowed an attacker to execute JavaScript in a privileged origin by sending a crafted Log.EntryAdded event with a JavaScript URI containing control characters. This could lead to reading local files via the DevToolsAPI.

Matan Berson Follow

Originally disclosed on Chrome VRP

Bounty$6,000 High View original
  • Fix shipped in 2 months

VULNERABILITY DETAILS
I have identified an XSS vulnerability in the highly privileged Chrome DevTools Frontend origin (devtools://devtools). This vulnerability exists in any DevTools frontend page, in the filtering of JavaScript URIs when handling Log.EntryAdded events.
The vulnerability can be exploited by making the victim navigate to a particular URL, which makes the DevTools frontend connect to the attacker's WebSocket server (using the "ws" or "wss" query parameters). The attacker's WebSocket servers then sends a malicious Log.EntryAdded event in that connection, with a JavaScript URI in the "url" property. The handler for that event does try to block JavaScript URIs, but an attacker can bypass that by inserting either a \n, \r, or \t byte into the scheme of the URI (e.g "javascr\tipt:alert(origin)").
Then, a message will be printed to the console. prompting the user to click on a legitimate-looking link, which when clicked on, executes the attacker's JavaScript code. An example of this can be seen in the video PoC.
If you try to reproduce this vulnerability in the devtools://devtools/bundled/devtools_app.html endpoint, the XSS will get blocked by the CSP of the page, due to the removal of the "unsafe-inline" directive from the "script-src" in 2020. However, the vulnerability can still be exploited in the devtools://devtools/bundled/integration_test_runner.html endpoint, which was missed during the change.

The following URL can be used to exploit this XSS vulnerability: devtools://devtools/bundled/integration_test_runner.html?debugFrontend=true&inspected_test=https://example.com&ws=[URL of attacker WebSocket server, without the protocol].
This isn't the final exploit URL though, as an attacker can't simply redirect a victim to this URL, as it contains the "devtools" protocol.
I have however found a way to make a victim navigate to that devtools URL, by using a drag and drop interaction. An example of a malicious site which uses that interaction to open the exploit URL is included in the reproduction case.

After triggering the XSS, the exploit script gets a reference to the DevToolsAPI object using the following steps (I am not sure if this is meant to be possible):

  1. The script opens "devtools://devtools/bundled/devtools_app.html" in a new tab (window.opener.open is used in order to save a click from being necessary), and saves a reference to it in the "w" variable. At this stage, w.DevToolsAPI is undefined, as the window loaded with an opener property set
  2. The script sets w.opener to null
  3. The script reloads the window by calling w.location.reload()
  4. The script waits for the window to load again
  5. As the window was loaded without an opener property set, w.DevToolsAPI is now defined, and the exploit script can use it.

After getting access to the DevToolsAPI object, the script then uses it to read local files. I am fairly certain that a higher impact can be achieved using this API (as demonstrated in https://microsoftedge.github.io/edgevr/posts/attacking-the-devtools/), and I will continue to investigate this.
Finally, the opened window is closed, and the extracted information is parsed and displayed. As the CSP which the exploit script runs under is very permissive, exfiltrating this information would be trivial.

VERSION
Chrome Version: 119.0.6045.124 stable
Operating System: Windows 11 (also tested on Linux)

REPRODUCTION CASE
I have attached all of the files needed to run the HTTP and WebSocket attack servers. Please follow these steps to run them:

  1. Download all of the attached files (except the video PoC) into a single folder
  2. Navigate to that folder and run "npm install"
  3. Run the following command to start the servers: "npx supervisor node attack-servers.mjs". This will automatically restart the servers if they encounter an error.

Steps to Reproduce as the Victim:

  1. Navigate to http://localhost:9123/#devtools://devtools/bundled/integration_test_runner.html?ws=127.0.0.1:6123&panel=console&inspected_test=https://example.com&debugFrontend=true (the attacker's http server)
  2. Drag the installer icon into a new tab, as shown in the attached video PoC
  3. Notice that the potentially suspicious "javascript:" URI is trimmed in the "update chrome now" link, due to the many "\r" bytes preceding it, and click on the link
  4. Wait for the exploit to finish (should take about 0.5 seconds, as I was generous with the wait times), and notice the leaked file information.

CREDIT INFORMATION
Reporter credit: Matan Berson (https://twitter.com/MtnBer, https://matanber.com)

Cheers,
Matan.

The original report as published on the Chromium issue tracker, by Matan Berson (@MtnBer). Images and videos are our own copies; raw HTML is shown as text. View it on Chromium issue tracker.

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. 5 min read.

Context

Chrome DevTools is not just a set of panels bolted onto the browser: the frontend is a web application served from the privileged devtools://devtools origin. That origin is treated as highly trusted, so a cross-site scripting bug there is more serious than one in an ordinary page. This report describes an XSS in the DevTools frontend, in the code that filters JavaScript URIs when handling Log.EntryAdded events. The issue was tracked as CVE-2024-3172, rated high severity, and was disclosed on 23 January 2024 with a 6000 USD reward under the Chrome VRP. The reporter is Matan Berson (@MtnBer).

Setup

The researcher tested against Chrome 119.0.6045.124 stable on Windows 11, and also on Linux. The reproduction ships as a set of files that run an HTTP attack server and a WebSocket attack server. Node.js and npm are needed to run them.

Finding it

The DevTools frontend can be told to connect to a remote debugging endpoint through the ws or wss query parameters. When it does, it processes events coming over that WebSocket connection, including Log.EntryAdded. The handler for that event tries to block JavaScript URIs in the url property, but the check can be bypassed by inserting a \n, \r or \t byte into the scheme of the URI, for example:

Text
javascr\tipt:alert(origin)

The result is a console message containing a link that looks legitimate. When the user clicks it, the attacker's JavaScript runs in the DevTools frontend origin.

One limit matters here. If you try the same thing against devtools://devtools/bundled/devtools_app.html, the XSS is blocked by the page's CSP, because the unsafe-inline directive was removed from script-src in 2020. The devtools://devtools/bundled/integration_test_runner.html endpoint was missed during that change, so the payload still executes there.

Exploitation

Step 1: get the victim onto a devtools:// URL

The exploit URL is:

Text
devtools://devtools/bundled/integration_test_runner.html?debugFrontend=true&inspected_test=https://example.com&ws=[URL of attacker WebSocket server, without the protocol]

An attacker cannot simply redirect a victim to this URL, because it uses the devtools protocol. The researcher found a way around that with a drag and drop interaction: a malicious site presents something draggable, and the victim drags it into a new tab, which opens the devtools URL. The reproduction case includes an example of such a malicious site.

Step 2: serve the malicious event over WebSocket

Once the frontend connects to the attacker's WebSocket server, the server sends a Log.EntryAdded event whose url property holds the JavaScript URI with the injected control byte in the scheme. The frontend's filter does not recognise it as a JavaScript URI, and the console prints a message with a clickable link.

Step 3: get a reference to DevToolsAPI

After the XSS fires, the exploit script obtains a reference to the DevToolsAPI object. The researcher was not sure whether this is meant to be possible. The steps are:

  1. The script opens devtools://devtools/bundled/devtools_app.html in a new tab, using window.opener.open so that no click is needed, and saves a reference in the variable w. At this point w.DevToolsAPI is undefined, because the window was loaded with an opener property set.
  2. The script sets w.opener to null.
  3. The script reloads the window with w.location.reload().
  4. The script waits for the window to load again.
  5. Because the window is now loaded without an opener property set, w.DevToolsAPI is defined and the exploit script can use it.

Step 4: read local files and exfiltrate

With access to DevToolsAPI, the script reads local files. The researcher says they are fairly certain a higher impact can be achieved with this API, citing https://microsoftedge.github.io/edgevr/posts/attacking-the-devtools/, and that they would continue investigating. Finally the opened window is closed, and the extracted information is parsed and displayed. The CSP the exploit script runs under is very permissive, so exfiltrating the information would be trivial.

Step 5: run the reproduction

To run the attack servers, download all attached files except the video PoC into one folder, then:

Bash
npm install

and start the servers with:

Bash
npx supervisor node attack-servers.mjs

This restarts the servers automatically if they hit an error.

As the victim:

  1. Navigate to the attacker's HTTP server:
Text
http://localhost:9123/#devtools://devtools/bundled/integration_test_runner.html?ws=[redacted]:6123&panel=console&inspected_test=https://example.com&debugFrontend=true
  1. Drag the installer icon into a new tab.
  2. Notice that the suspicious javascript: URI is trimmed in the "update chrome now" link, because of the many \r bytes preceding it, and click the link.
  3. Wait for the exploit to finish, about 0.5 seconds because the wait times were generous, and notice the leaked file information.

Root cause

The Log.EntryAdded handler tries to block JavaScript URIs in the url property, but the check can be bypassed by inserting a \n, \r or \t byte into the scheme of the URI. The second half of the problem is the CSP gap: unsafe-inline was removed from script-src in 2020, which protects devtools_app.html, but integration_test_runner.html was missed, so inline script still runs there. The researcher was not sure whether obtaining the DevToolsAPI reference this way is meant to be possible.

Impact

An attacker who can get a victim to perform the drag and drop interaction can execute JavaScript in the privileged devtools://devtools origin. From there the script can reach DevToolsAPI and read local files, and the permissive CSP makes exfiltration trivial. The researcher expects that a higher impact is achievable through the same API but had not demonstrated it at the time of writing. The attack relies on a drag and drop interaction and a click on the crafted link.

Fix

The report does not describe the fix that was applied.

Variants to test

  1. Other DevTools frontend pages that accept ws or wss parameters: send a Log.EntryAdded event with control bytes in the scheme and see whether a clickable link is printed and executes.
  2. Other event handlers that render URLs from the debugging connection: try \n, \r and \t in the scheme and check whether the link is still treated as javascript:.
  3. Other bundled pages that may have been missed when unsafe-inline was removed: load each and check whether inline script executes under the page CSP.
  4. The opener-clearing and reload sequence against other privileged origins: open a page with an opener, null the opener, reload, and check whether privileged globals such as DevToolsAPI become defined.

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.

What happened, in plain words

Chrome DevTools is the panel you open inside Chrome (usually with F12) to inspect a web page: you can see the page's HTML, its network requests, and messages printed to the browser console. What many people do not realise is that this panel is itself a small web application, a set of HTML, JavaScript and CSS files, just like a normal website. The difference is where it is served from: a special internal address, devtools://devtools, instead of https://. Chrome treats that internal address as highly trusted, because code running there is part of the browser's own tooling. So a bug that lets an attacker run their own JavaScript on that address is more serious than the same bug on an ordinary website.

This report describes exactly such a bug: a cross-site scripting (XSS) flaw in the DevTools frontend. The flaw sits in the code that filters JavaScript links when DevTools receives a particular kind of log message, called Log.EntryAdded. The issue was tracked as CVE-2024-3172, rated high severity, disclosed on 23 January 2024, and paid a 6000 USD reward under the Chrome VRP (Chrome's Vulnerability Reward Program, the scheme that pays people for reporting security bugs). The reporter is Matan Berson (@MtnBer).

A few words you will meet throughout, explained once here:

  • XSS (cross-site scripting): a bug where an attacker manages to get their own JavaScript to run inside a page or origin that should not run it. Think of it as slipping a forged note into someone's in-tray so that the office treats it as an official instruction.
  • Origin: the combination of protocol, host and port that a browser uses to decide what a page is allowed to touch. devtools://devtools is one origin; https://example.com is another. Pages from different origins are kept apart on purpose.
  • JavaScript URI: a link that starts with javascript: and contains code. Clicking it runs the code instead of navigating somewhere. It is like a button labelled "open the door" that actually does something else when pressed.
  • WebSocket: a two-way, always-open connection between a browser and a server, unlike a normal web request that ends after one answer. Think of a phone call rather than a letter.
  • CSP (Content Security Policy): a rule set a page sends to the browser saying which scripts it is allowed to run. It is a bouncer at the door checking a guest list.
  • API (Application Programming Interface): a defined set of functions one piece of software offers to another. Here, DevToolsAPI is an object that gives JavaScript code access to DevTools features.

Setup

The researcher tested against Chrome 119.0.6045.124 stable on Windows 11, and also on Linux. The reproduction ships as a set of files that run two small servers: an HTTP attack server (which serves the malicious web page) and a WebSocket attack server (which talks to DevTools). Node.js and npm are needed to run them. Node.js is a program that lets JavaScript run outside a browser, and npm is its package manager, the tool that downloads the libraries a project needs.

Finding it

The DevTools frontend can be told to connect to a remote debugging endpoint through the ws or wss query parameters. A query parameter is the part of a URL after the ?, made of name and value pairs; ws here means "connect over WebSocket to this address". When DevTools does connect, it processes events coming over that WebSocket connection, including Log.EntryAdded. An event is simply a message with a name and some data; Log.EntryAdded means "a new line was added to the log".

The handler for that event tries to block JavaScript URIs in the url property, but the check can be bypassed by inserting a \n, \r or \t byte into the scheme of the URI, for example:

Text
javascr\tipt:alert(origin)

Line by line, in plain words:

  • javascript: is the scheme, the part before the colon that tells the browser what kind of link this is.
  • The payload splits the word with a tab character (\t), so the string reads javascr, then a tab, then ipt:alert(origin).
  • The filter in DevTools looks at the string and does not recognise it as a JavaScript URI, so it lets it through.
  • The filter in DevTools does not recognise the string as a JavaScript URI, so it lets it through, and clicking the link runs the attacker's code. alert shows a pop-up box, and origin is the address of the page, so the pop-up proves which origin the code is running in.

The result is a console message containing a link that looks legitimate. When the user clicks it, the attacker's JavaScript runs in the DevTools frontend origin.

One limit matters here. If you try the same thing against devtools://devtools/bundled/devtools_app.html, the XSS is blocked by the page's CSP, because the unsafe-inline directive was removed from script-src in 2020. script-src is the CSP instruction listing which scripts may run; unsafe-inline is the permission that allows scripts written directly inside the HTML page. Removing it means inline scripts no longer run. The devtools://devtools/bundled/integration_test_runner.html endpoint was missed during that change, so the payload still executes there.

Exploitation

Step 1: get the victim onto a devtools:// URL

The exploit URL is:

Text
devtools://devtools/bundled/integration_test_runner.html?debugFrontend=true&inspected_test=https://example.com&ws=[URL of attacker WebSocket server, without the protocol]

Reading it piece by piece:

  • devtools://devtools/bundled/integration_test_runner.html is the internal DevTools page that still allows inline scripts.
  • debugFrontend=true is a parameter that turns on debugging behaviour in the frontend.
  • inspected_test=https://example.com is a parameter the page expects; it names a test page.
  • ws=[URL of attacker WebSocket server, without the protocol] tells DevTools to open a WebSocket connection to the attacker's server. The protocol part (ws:// or wss://) is left out because the page adds it.

An attacker cannot simply redirect a victim to this URL, because it uses the devtools protocol. A normal web page cannot send the browser to an internal devtools:// address; the browser would refuse. The researcher found a way around that with a drag and drop interaction: a malicious site presents something draggable, and the victim drags it into a new tab, which opens the devtools URL. The reproduction case includes an example of such a malicious site.

Step 2: serve the malicious event over WebSocket

Once the frontend connects to the attacker's WebSocket server, the server sends a Log.EntryAdded event whose url property holds the JavaScript URI with the injected control byte in the scheme. The frontend's filter does not recognise it as a JavaScript URI, and the console prints a message with a clickable link. The attacker's server is doing the job of a legitimate debugging tool here: DevTools trusts what arrives over the connection, so a fake log line is enough to plant the link.

Step 3: get a reference to DevToolsAPI

After the XSS fires, the exploit script obtains a reference to the DevToolsAPI object. A reference simply means a variable in the script that points at that object, so the script can call its functions. The researcher was not sure whether this is meant to be possible. The steps are:

  1. The script opens devtools://devtools/bundled/devtools_app.html in a new tab, using window.opener.open so that no click is needed, and saves a reference in the variable w. At this point w.DevToolsAPI is undefined, because the window was loaded with an opener property set. window.opener is the link a pop-up or new tab keeps back to the page that opened it; undefined means the value does not exist.
  2. The script sets w.opener to null. This cuts that link.
  3. The script reloads the window with w.location.reload().
  4. The script waits for the window to load again.
  5. Because the window is now loaded without an opener property set, w.DevToolsAPI is defined and the exploit script can use it.

Step 4: read local files and exfiltrate

With access to DevToolsAPI, the script reads local files. The researcher says they are fairly certain a higher impact can be achieved with this API, citing https://microsoftedge.github.io/edgevr/posts/attacking-the-devtools/, and that they would continue investigating. Finally the opened window is closed, and the extracted information is parsed and displayed. The CSP the exploit script runs under is very permissive, so exfiltrating the information would be trivial. Exfiltrating means sending stolen data out to the attacker; a permissive CSP means few restrictions on where the script may send data.

Step 5: run the reproduction

To run the attack servers, download all attached files except the video PoC into one folder, then:

Bash
npm install

This command reads the project's list of dependencies and downloads them into the folder, so the attack servers have the libraries they need.

and start the servers with:

Bash
npx supervisor node attack-servers.mjs
  • npx runs a package without installing it globally.
  • supervisor is a small tool that watches a program and restarts it if it crashes.
  • node attack-servers.mjs runs the file attack-servers.mjs with Node.js; that file starts the HTTP and WebSocket attack servers.

This restarts the servers automatically if they hit an error.

As the victim:

  1. Navigate to the attacker's HTTP server:
Text
http://localhost:9123/#devtools://devtools/bundled/integration_test_runner.html?ws=[redacted]:6123&panel=console&inspected_test=https://example.com&debugFrontend=true

Here localhost means this computer, 9123 is the port of the attacker's HTTP server, and everything after # is a fragment. A fragment is normally not sent to the server; it stays in the browser, and the malicious page's script reads it and uses it to build the devtools:// URL. ws=[redacted]:6123 points DevTools at the WebSocket server on port 6123, and panel=console asks DevTools to show the console panel.

  1. Drag the installer icon into a new tab. This is the user interaction that gets the browser to open the devtools:// URL.
  2. Notice that the suspicious javascript: URI is trimmed in the "update chrome now" link, because of the many \r bytes preceding it, and click the link. The \r bytes are carriage returns, invisible control characters.
  3. Wait for the exploit to finish, about 0.5 seconds because the wait times were generous, and notice the leaked file information.

Root cause

The Log.EntryAdded handler validates the url property against JavaScript URIs, but the validation does not account for control bytes (\n, \r, \t) inside the scheme. Inserting one of them makes the string fail the check while the browser still treats it as a javascript: URI when the link is clicked. The second half of the problem is the CSP gap: unsafe-inline was removed from script-src in 2020, which protects devtools_app.html, but integration_test_runner.html was missed, so inline script still runs there. The DevToolsAPI exposure after clearing the opener and reloading is described by the researcher as possibly unintended, but the report does not confirm that.

Impact

An attacker who can get a victim to perform the drag and drop interaction can execute JavaScript in the privileged devtools://devtools origin. From there the script can reach DevToolsAPI and read local files, and the permissive CSP makes exfiltration trivial. The researcher expects that a higher impact is achievable through the same API but had not demonstrated it at the time of writing. The attack relies on a drag and drop interaction and a click on the crafted link.

Fix

The report does not describe the fix that was applied.

Variants to test

  1. Other DevTools frontend pages that accept ws or wss parameters: send a Log.EntryAdded event with control bytes in the scheme and see whether a clickable link is printed and executes.
  2. Other event handlers that render URLs from the debugging connection: try \n, \r and \t in the scheme and check whether the link is still treated as javascript:.
  3. Other bundled pages that may have been missed when unsafe-inline was removed: load each and check whether inline script executes under the page CSP.
  4. The opener-clearing and reload sequence against other privileged origins: open a page with an opener, null the opener, reload, and check whether privileged globals such as DevToolsAPI become defined.

Glossary

  • API (Application Programming Interface): a defined set of functions one program offers to another so they can work together.
  • Attack server: a server run by the attacker that serves the malicious page or talks to the victim's browser.
  • CSP (Content Security Policy): rules a page gives the browser about which scripts and resources it may load and run.
  • CVE: a public identifier for a known security vulnerability, here CVE-2024-3172.
  • Chrome VRP: Chrome's Vulnerability Reward Program, which pays researchers for reporting security bugs.
  • Control byte: an invisible character such as \n (newline), \r (carriage return) or \t (tab) that does not show on screen but affects how text is read.
  • Cross-site scripting (XSS): a bug that lets an attacker's JavaScript run inside a page or origin it should not run in.
  • DevTools: the inspection panel built into Chrome, opened with F12, showing a page's HTML, network traffic and console.
  • DevToolsAPI: the object that gives JavaScript access to DevTools features.
  • Directive: a single instruction inside a CSP, such as script-src.
  • Drag and drop interaction: the user action of dragging an item and dropping it somewhere, here into a new tab.
  • Event: a named message with data, such as Log.EntryAdded.
  • Exfiltration: sending stolen data out to the attacker.
  • Fragment: the part of a URL after #, kept in the browser and not sent to the server.
  • Handler: the piece of code that runs when a particular event arrives.
  • HTTP: the protocol browsers use to fetch web pages.
  • Inline script: JavaScript written directly inside an HTML page rather than in a separate file.
  • JavaScript URI: a link starting with javascript: that runs code when clicked.
  • localhost: the name a computer uses to refer to itself.
  • Node.js / npm: a program that runs JavaScript outside a browser, and its package manager that downloads libraries.
  • Opener: the link a new tab or pop-up keeps back to the page that opened it, available as window.opener.
  • Origin: the combination of protocol, host and port that decides what a page may access.
  • Parameter (query parameter): a name and value pair after ? in a URL.
  • Payload: the piece of attacker-controlled input that triggers the bug.
  • Port: a number that identifies a specific service on a computer.
  • Privileged origin: an origin the browser trusts more than ordinary websites, such as devtools://devtools.
  • Query string: the part of a URL after ? containing parameters.
  • Reference: a variable in a script that points at an object so its functions can be called.
  • Remote debugging endpoint: a server a browser or tool can connect to in order to inspect another browser.
  • Scheme: the part of a URL before the colon, such as https, devtools or javascript.
  • script-src: the CSP directive listing which scripts may run.
  • unsafe-inline: the CSP permission that allows inline scripts to run.
  • WebSocket: a two-way, always-open connection between a browser and a server.
  • ws / wss: the WebSocket URL schemes, the unencrypted and encrypted versions.
  • undefined / null: JavaScript values meaning "no value" and "deliberately empty".

More by Matan Berson

View all

1 more disclosed report, best first.

More from Google Chrome

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.