Closed Bug 1769581 Opened 4 years ago Closed 4 years ago

Content-Security-Policy: default-src ‘self’ breaks website

Categories

(Core :: DOM: Security, defect)

Firefox 100
defect

Tracking

()

RESOLVED DUPLICATE of bug 1764261

People

(Reporter: mail4ilia, Unassigned)

Details

User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:100.0) Gecko/20100101 Firefox/100.0

Steps to reproduce:

A government website I must use responds to my GET request with the following headers:

Content-Security-Policy: default-src ‘self’
X-Content-Security-Policy: default-src ‘self’

Note the UTF-8, not ASCII apostrophe symbols, which are visible in the hexdump:

00000000 43 6f 6e 74 65 6e 74 2d 53 65 63 75 72 69 74 79 |Content-Security|
00000010 2d 50 6f 6c 69 63 79 3a 20 64 65 66 61 75 6c 74 |-Policy: default|
00000020 2d 73 72 63 20 e2 80 98 73 65 6c 66 e2 80 99 |-src ...self...|

Actual results:

Firefox reports a error in the console:

Content Security Policy: Couldn’t parse invalid host self

Afterward loading of any script resource fails with a warning:

Loading failed for the <script> with source "SOME_URL"

followed by a error

Content Security Policy: The page’s settings blocked the loading of a resource at SOME_URL (“default-src”).

(SOME_URL is a URL, not a literal string)

Network developer panel also describes the request as blocked due to CSP.

Expected results:

When the problematic page is loaded in Chrome it reports a error in the console:

The value for the Content-Security-Policy directive 'default-src' contains one or more invalid characters. In a source expression, non-whitespace characters outside ASCII 0x21-0x7E must be Punycode-encoded, as described in RFC 3492 (https://tools.ietf.org/html/rfc3492), if part of the hostname and percent-encoded, as described in RFC 3986, section 2.1 (http://tools.ietf.org/html/rfc3986#section-2.1), if part of the path.

However, this error does not preclude Chrome from loading all the linked resources. It also seems like web developers are only testing with Chrome. Welcome back to IE-only web :(

Given the Chrome market share and the amount of lazy/unprofessional webdevs maybe firefox should adopt a similar policy for handling invalid CSP header. For example display a prompt/warning to the user. Currently all resource loading is effectively blocked by Firefox and such a website becomes unusable.

The Bugbug bot thinks this bug should belong to the 'Core::DOM: Security' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: Untriaged → DOM: Security
Product: Firefox → Core

Chrome's behavior is technically wrong according to the spec, but we're trying to work it out with them.

Status: UNCONFIRMED → RESOLVED
Closed: 4 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.