Closed Bug 1730668 Opened 5 years ago Closed 3 years ago

CSP incorrectly blocks scripts on public.bitmex.com, ignoring or miscalculating script-src hash-

Categories

(Core :: DOM: Security, defect, P3)

Firefox 92
defect

Tracking

()

RESOLVED DUPLICATE of bug 1409200

People

(Reporter: n.goeggi, Unassigned)

References

()

Details

(Whiteboard: [domsecurity-backlog])

Opening https://public.bitmex.com/?prefix=data/porl/ in Firefox yields a blank white page while in Chrome for example the intended content is loaded.

The CSP logs from the console:

Content Security Policy: The page’s settings blocked the loading of a resource at https://public.bitmex.com/jquery.min.js (“script-src”).
Content Security Policy: The page’s settings blocked the loading of a resource at https://public.bitmex.com/init.js (“script-src”).
Content Security Policy: The page’s settings blocked the loading of a resource at https://public.bitmex.com/list.js (“script-src”).

The CSP is defined as:

<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src 'self'; connect-src https://s3-eu-west-1.amazonaws.com; script-src 'sha384-3ceskX3iaEnIogmQchP8opvBy3Mi7Ce34nWjpBIwVTHfGYWQS9jwHDVRnpKKHJg7' 'sha384-n0cKBy1+1+ACIC9J2XunFZItQjpIi1bilP1FCayDxybB40OcUY1ipK4Qjr856KWI' 'sha384-Rncjr7coAsbMCINMdkum6h64TPVhqlDpqulDQB/a68yABAgOU21duBLDdlm86oKP'; child-src 'none'; object-src 'none'; require-sri-for script style; block-all-mixed-content;">

And the blocked resources as:

<script type="text/javascript" src="https://public.bitmex.com/jquery.min.js" integrity="sha384-3ceskX3iaEnIogmQchP8opvBy3Mi7Ce34nWjpBIwVTHfGYWQS9jwHDVRnpKKHJg7" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://public.bitmex.com/init.js" integrity="sha384-n0cKBy1+1+ACIC9J2XunFZItQjpIi1bilP1FCayDxybB40OcUY1ipK4Qjr856KWI" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://public.bitmex.com/list.js" integrity="sha384-Rncjr7coAsbMCINMdkum6h64TPVhqlDpqulDQB/a68yABAgOU21duBLDdlm86oKP" crossorigin="anonymous"></script>

Based on the CSP i would have expected the resources to load and the page to display normally like in Chrome for example.

I only checked the jquery.min.js file, but the CSP and integrity attributes match what I get when I download the file and calculate the hash.

Summary: Can't open https://public.bitmex.com/?prefix=data/porl/ because CSP blocks loading of resource → CSP incorrectly blocks scripts on public.bitmex.com, ignoring or miscalculating script-src hash-

Another interesting testcase might be https://tcckonsult.com/ from bug 1729135. It's a working site and more complicated (bitmex is nothing but 3 script tags that build the site), but only one of their hashed script files fail and others work fine. Might be a clue in that difference.

Assignee: nobody → ngogge
Severity: -- → S2
Priority: -- → P2
Whiteboard: [domsecurity-active]

This appears to be a symptom of not having implemented CSP 3.0 support for matching hashes from external sources (Bug 1409200).

nsCSPHashSrc does not override permits which would be responsible for checking the script hash from external sources. As a result nsCSPBaseSrc::permits is called which will never allow the load.

On https://tcckonsult.com/ all external scripts get blocked as well but only the blocking of https://cdn.jsdelivr.net/npm/emailjs-com@2/dist/email.min.js shows up in the devtools console for some reason.

(In reply to Niklas from comment #4)
The other external scripts on tcckonsult.com loads fine for me?
https://ibb.co/z4KD3Yj

(In reply to Anders from comment #5)

(In reply to Niklas from comment #4)
The other external scripts on tcckonsult.com loads fine for me?
https://ibb.co/z4KD3Yj

Hm, you are right, i think i was confused by something that i saw in the debug logs.
For example i saw this for https://unpkg.com/aos@2.3.1/dist/aos.js

[Child 84530: Main Thread]: D/CSPUtils nsCSPDirective::permits, aUri: https://unpkg.com/aos@2.3.1/dist/aos.js
[...]
[Child 84530: Main Thread]: D/CSPUtils nsCSPNonceSrc::permits, aUri: https://unpkg.com/aos@2.3.1/dist/aos.js, aNonce:
[Child 84530, Main Thread] WARNING: NS_ENSURE_SUCCESS(rv, rv) failed with result 0x805E0006 (NS_ERROR_CONTENT_BLOCKED): file /Users/niklasgogge/workspace/mozilla-central/dom/security/nsContentSecurityManager.cpp:1230
[Child 84530, Main Thread] WARNING: 'NS_FAILED(rv)', file /Users/niklasgogge/workspace/mozilla-central/netwerk/protocol/http/HttpChannelChild.cpp:1927
[Child 84530, Main Thread] WARNING: NS_ENSURE_SUCCESS(rv, rv) failed with result 0x805E0006 (NS_ERROR_CONTENT_BLOCKED): file /Users/niklasgogge/workspace/mozilla-central/dom/script/ScriptLoader.cpp:1721

The NS_ERROR_CONTENT_BLOCKED result made me think the script got blocked but later on the same script gets checked by nsCSPDirective::permits again without getting blocked.

The only difference between the script that gets blocked and the ones that don't seems to be the nonce attribute. The scripts that have an empty nonce attribute don't get blocked.

tcckonsult.com
So I tried changing the hash to 256 version. This did nothing.
Added a nonce. Using a nonce worked!

Assignee: ngogge → nobody
Blocks: csp-w3c-3
Whiteboard: [domsecurity-active]
Whiteboard: [domsecurity-backlog]

We're going to work on this via https://bugzilla.mozilla.org/show_bug.cgi?id=1409200, but likely not before the end of the year.
Setting Priority/Severity accordingly.

Severity: S2 → S3
Priority: P2 → P3

The content seems to be displayed correctly now.

No longer blocks: csp-w3c-3
Status: NEW → RESOLVED
Closed: 3 years ago
No longer depends on: csp-external-hashes
Duplicate of bug: csp-external-hashes
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.