Closed Bug 1880374 (CVE-2024-6612) Opened 2 years ago Closed 2 years ago

Developer tools leak CSP violations through DNS prefetching (links in devtools should have DNS prefetching disabled)

Categories

(DevTools :: General, defect, P2)

Desktop
All
defect

Tracking

(firefox-esr115 wontfix, firefox126 wontfix, firefox127 wontfix, firefox128 fixed)

RESOLVED FIXED
128 Branch
Tracking Status
firefox-esr115 --- wontfix
firefox126 --- wontfix
firefox127 --- wontfix
firefox128 --- fixed

People

(Reporter: ymarchand, Assigned: jdescottes)

References

(Regressed 1 open bug)

Details

(4 keywords, Whiteboard: [reporter-external] [client-bounty-form] [verif?][adv-main128+])

Attachments

(3 files)

Attached file poc.html

User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:122.0) Gecko/20100101 Firefox/122.0

Steps to reproduce:

  • Set up a DNS name server
  • In the attached HTML file, update "example.org" to point to your DNS server
  • Visit the attached HTML file

Actual result:

  • A DNS request is sent out when the CSP violation is generated, leaking the violation

Expected result:

  • No DNS prefetching in developer tools

Summary:
By default, <a> tags are prefetched upon loading into the DOM, this includes the developer tools. Upon a CSP violation a link is generated in the console tab of the developer tools, pointing to the violating resource. This causes a DNS prefetch, leaking that a CSP violation has happened. This can be used to bypass the "default-src none" directive in case of a CSS injection, as can be seen in the attached POC. It should be noted that we were only able to exploit this in a browser where the developer tools were open.

In addition to the user agent above, we also confirmed this vulnerability on a Windows machine.

Flags: sec-bounty?

This issue was found during DiceCTF by Aidan Stephenson & Yannik Marchand.

Thanks for the report. I haven't tried to repro (not a devtools expert, can't easily set up a DNS server, and it's 10pm here), but the report makes sense to me, so just going to try to pass this to the right people to investigate further.

Moving to devtools, but Valentin, who from networking would be good to chat to here? I guess devtools could update all their individual markup but that's pretty error-prone. A browsingcontext/docshell level change would be a more systemic solution. Do we already have a flag of that sort?

Component: Security → Console
Flags: needinfo?(valentin.gosu)
OS: Unspecified → All
Product: Firefox → DevTools
Hardware: Unspecified → Desktop
Summary: Developer tools leak CSP violations through DNS prefetching → Developer tools leak CSP violations through DNS prefetching (links in devtools should have DNS prefetching disabled)

Maybe it would be worth disabling DNS prefetching for the developer tools entirely? Given that only a small percentage of users will be interacting with these tools (and those that do will likely be developing their own website, meaning its likely already in the DNS cache) it seems worth the possible performance hit.

(In reply to aidands from comment #3)

Maybe it would be worth disabling DNS prefetching for the developer tools entirely? Given that only a small percentage of users will be interacting with these tools (and those that do will likely be developing their own website, meaning its likely already in the DNS cache) it seems worth the possible performance hit.

Right, that is effectively what I asked in comment 2. I'm not sure if we have primitives for this at the moment (we may do, I just don't know off-hand). There's an HTTP header (X-DNS-Prefetch-Control) but the devtools' own html pages are not using HTTP channels. If one doesn't exist we can create one, but that may require people other than the devtools team to help. :-)

Tom, Freddy: interesting CSP edge case. Does a page's CSP apply to DevTools?

Status: UNCONFIRMED → NEW
Ever confirmed: true

HTMLDocument chrome://devtools/content/webconsole/index.html
temp3.csp.policyCount // 0

We could either try setting Document::mAllowDNSPrefetch to false for the devtools document, or better yet change the following code to return false if the document's nodePrincipal is the SystemPrincipal. I think this would be good to do anyway.

https://searchfox.org/mozilla-central/rev/9e5b13e92b50c61e60a42bdc2cb2e5966ae28795/dom/html/HTMLDNSPrefetch.cpp#182-185

bool HTMLDNSPrefetch::IsAllowed(Document* aDocument) {
  // There is no need to do prefetch on non UI scenarios such as XMLHttpRequest.
  return aDocument->IsDNSPrefetchAllowed() && aDocument->GetWindow();
}
Flags: needinfo?(valentin.gosu)

CSP is supposed to have a mechanism for blocking preconnect/preload/prefetch called "resource hints". I have been on-and-off working on this a bit when I have some time in bug 1457204. However currently the specification for this is broken: https://github.com/w3c/webappsec-csp/issues/633.

Component: Console → General
Severity: -- → S3
Flags: needinfo?(jdescottes)
Priority: -- → P2
Assignee: nobody → jdescottes
Status: NEW → ASSIGNED

Thanks for the suggestion and review Valentin!

Daniel: are we okay with landing the current patch as is, since it's sec-low?

Flags: needinfo?(jdescottes) → needinfo?(dveditz)

We are :)

Flags: needinfo?(dveditz)
Pushed by jdescottes@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/7dec3dd641fd Disable DNS prefetching if document nodePrincipal is systemPrincipal r=valentin
Group: firefox-core-security → core-security-release
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 128 Branch

The patch landed in nightly and beta is affected.
:jdescottes, is this bug important enough to require an uplift?

  • If yes, please nominate the patch for beta approval.
  • If no, please set status-firefox127 to wontfix.

For more information, please visit BugBot documentation.

Flags: needinfo?(jdescottes)

Considering that we could not write a test for it, I think it's safer to let this ride the trains.

Flags: needinfo?(jdescottes)
Flags: sec-bounty? → sec-bounty+
QA Whiteboard: [post-critsmash-triage]
Flags: qe-verify-
Whiteboard: [reporter-external] [client-bounty-form] [verif?] → [reporter-external] [client-bounty-form] [verif?][adv-main128+]
Alias: CVE-2024-6612
Group: core-security-release
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: