Closed Bug 1920348 Opened 1 year ago Closed 9 months ago

CSP bypass in DevTools Network Tab Response Preview because `content-security-policy:` headers ignored

Categories

(DevTools :: Netmonitor, defect, P2)

defect

Tracking

(firefox-esr115 wontfix, firefox-esr128 wontfix, firefox137 wontfix, firefox138 wontfix, firefox139 fixed)

RESOLVED FIXED
139 Branch
Tracking Status
firefox-esr115 --- wontfix
firefox-esr128 --- wontfix
firefox137 --- wontfix
firefox138 --- wontfix
firefox139 --- fixed

People

(Reporter: t.satoki111, Assigned: tschuster)

References

Details

(Keywords: csectype-mitigation-bypass, reporter-external, sec-low, Whiteboard: [client-bounty-form] [adv-main139+])

Attachments

(7 files)

Attached file poc.py β€”

CSP (Content Security Policy) is a crucial security feature set by web administrators to prevent information leakage from users. When clicking on a network request in the DevTools Network tab and viewing the response preview, it becomes evident that CSP is not enforced. This behavior does not occur with the <meta> tag.

I have attached poc.py. Upon inspecting the site, you can see that the CSP is set to default-src 'none';, and elements such as base, img, and iframe are prohibited. However, what happens when a user opens the response preview in the Network tab? CSP is immediately disabled, and a request for the content within the base tag is triggered.

This illustrates a case of HTML injection, where CSP fails to protect if sensitive information (such as UUIDs) is included in the URL path. In other words, the path gets leaked. Additionally, it demonstrates that content may be rendered incorrectly as well.

Flags: sec-bounty?
Attached image test.png β€”

A weird preview

Summary: "Information Leakage and Content Spoofing Due to Disabled CSP in DevTools Network Tab Response Preview" → Information Leakage and Content Spoofing Due to Disabled CSP in DevTools Network Tab Response Preview
Component: Security → Framework
Product: Firefox → DevTools
Component: Framework → Netmonitor

Thanks for filing.

The preview displayed in the netmonitor is not actually showing the exact same page as the one loaded in your tab. It is an iframe using a data URI to look like the retrieved HTML. So it sounds unlikely that requests initiated from this iframe will be able to leak critical information? But maybe I am wrong, did you build a test case which really illustrates a leak ?

Let us know,
thanks

Flags: needinfo?(t.satoki111)

Thank you for your reply.
At first glance, it may seem like there’s no information leakage. I initially thought the same. Since JavaScript doesn’t execute, it seems safe against XSS. However, the key point to note here is that this bug bypasses CSP, allowing CSS injection and network requests to be issued. In Chrome, requests from the developer tools preview are completely blocked.

A simple case of information leakage involves exposing paths like those in the img tags. Similar to CVE-2022-40956, which I previously reported, the URL path meant to be hidden is leaked due to the use of the base tag. (poc1.py)
A more dangerous scenario is that CSS injection can be freely executed. Even if CSP is set to block all loads (set to none), elements in the HTML can be leaked via CSS injection. Even though CSS injection is blocked when accessing `http://localhost:31415/?cssi=<style>input[value^="e.g_csrftoken"]{background:url(http://localhost:31415/omg) !important;}</style>`, when previewed from the network tab, 'OMG' is printed on the server console. This indicates that the CSS injection was successful. In the poc, it's represented as a string, but it's generally known that individual characters can be leaked one at a time per access. (poc2.py)
An interesting behavior, though I’m not sure if it qualifies as a vulnerability, is that by using the meta tag, I was able to redirect the user to a site different from the actual one.
Flags: needinfo?(t.satoki111)
Attached file poc1.py β€”
Attached file poc2.py β€”

This is a supplementary video and tool for CSS Injection. Various values such as CSRF tokens can be retrieved. (The amazing work of other hackers)
https://www.youtube.com/watch?v=06gHFGbhTGY
https://github.com/m---/onsen

(In reply to Satoki Tsuji from comment #0)

CSP (Content Security Policy) is a crucial security feature set by web administrators to prevent information leakage from users.

Content Security Policy is intended to prevent content injection; it is not designed to prevent information leakage and there are several known gaping holes that make it a poor tool for that use. The fervent wishes of web administrators don't change the reality of CSP.

That said, ignoring CSP headers means that content injection is possible. Pretty far-fetched as an attack, though.

Status: UNCONFIRMED → NEW
Ever confirmed: true
Keywords: sec-moderate
Summary: Information Leakage and Content Spoofing Due to Disabled CSP in DevTools Network Tab Response Preview → CSP bypass in DevTools Network Tab Response Preview because `content-security-policy:` headers ignored
Severity: -- → S3
Priority: -- → P2
Whiteboard: [client-bounty-form] → [devtools-triage][client-bounty-form]

We should try to re-apply CSP headers in our preview, the csp attribute on iframes could be a way to do that, but it's not supported on Firefox yet. https://bugzilla.mozilla.org/show_bug.cgi?id=1857140.

Alex, can you check if we have privileged apis to do the same?

Flags: needinfo?(poirot.alex)
See Also: → 1857140
Whiteboard: [devtools-triage][client-bounty-form] → [client-bounty-form]
See Also: → 1391244

(In reply to Julian Descottes [:jdescottes] from comment #8)

We should try to re-apply CSP headers in our preview, the csp attribute on iframes could be a way to do that, but it's not supported on Firefox yet

Or don't let content in the preview pane load anything else at all whether it's got a CSP or not?

I don't know if we will ever get around to implementing the "Embedded Enforcement" spec, but it wouldn't help you here. If a site could impose a CSP on another site's content it could be used to selectively disable parts of the page such as validation scripts--it would become a security-breaking tool instead of security-enhancing. CSP-EE therefore requires that the framed site respond with the CSP you're trying to enforce as an "opt-in". If it does then it's all good -- the parent site is assured the framed content has the required CSP. If it does not then our only choice is to block the content and not show it. That would defeat the purpose of a DevTool panel that's trying to render the content.

How's the progress on this bug? There's no urgent need to fix it right away, but I'm interested in any updates.

Hello, I have a feeling that this bug is not valid in the latest version. When was it fixed? I think it was an unintentional fix in the process of fixing another bug. I'm happy about it, but I'm a little unhappy.

We didn't really fix this.

We accidentally applied a strict CSP to the preview in bug 1943360, so your test case seems fixed in Firefox 137. This strict CSP caused complaints, so we had to removed that again in Firefox 138 (bug 1957333).

omg. I thought this issue was resolved. Sorry. All I want to say is that if the security risk is resolved then all is well.

Hi! Considering that I already looked at this recently in bug 1957333 I think I was able to come up with a solution. My problem is that while testing manually responseHeaders seems to work correctly for me in HtmlPreview, but during the test run of devtools/client/netmonitor/test/browser_net_html-preview.js the value of responseHeaders is undefined. Maybe because it is using fetch? (I am also curious how responseHeaders.headers works with duplicate headers)

Flags: needinfo?(jdescottes)
Assignee: nobody → tschuster
Depends on: 1957333

Thanks for looking at this bug! I added some comments to answer your questions in the patch.

Flags: needinfo?(jdescottes)
Attachment #9478600 - Attachment description: WIP: Bug 1920348 - Apply CSP header to the HTML Preview → Bug 1920348 - Apply CSP header to the HTML Preview. r?jdescottes
Pushed by ctuns@mozilla.com: https://hg.mozilla.org/mozilla-central/rev/a57982ee343f ChromeUtil for creating a nsIContentSecurityPolicy from a header string. r=simonf https://hg.mozilla.org/mozilla-central/rev/3691752b223d Apply CSP header to the HTML Preview. r=jdescottes,devtools-reviewers
Group: firefox-core-security → core-security-release
Status: NEW → RESOLVED
Closed: 9 months ago
Resolution: --- → FIXED
Target Milestone: --- → 139 Branch
Flags: sec-bounty? → sec-bounty+
See Also: → 1957333

Lowering the severity to sec-low: scripts would never run with or without CSP.

Keywords: sec-moderatesec-low
QA Whiteboard: [sec] [qa-triage-done-c140/b139]
Flags: qe-verify-
Whiteboard: [client-bounty-form] → [client-bounty-form] [adv-main139+]
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: