Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

browse: fix Content-Security-Policy warnings in Firefox #6443

Merged
merged 2 commits into from
Jul 7, 2024

Conversation

steffenbusch
Copy link
Contributor

@steffenbusch steffenbusch commented Jul 6, 2024

This PR addresses the Content-Security-Policy warnings in Firefox: #6425 (comment)

The following changes have been made:

  1. Remove strict-dynamic from style-src:

    Content-Security-Policy: Ignoring source “strict-dynamic” (Only supported within script-src).

  2. Remove block-all-mixed-content:

    Content-Security-Policy: Ignoring ‘block-all-mixed-content’ because mixed content display upgrading makes block-all-mixed-content obsolete.

See also: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/block-all-mixed-content

  1. Remove strict-dynamic, https:, and http: from script-src:

    Content-Security-Policy: Ignoring “'unsafe-inline'” within script-src: ‘strict-dynamic’ specified
    Content-Security-Policy: Ignoring “https:” within script-src: ‘strict-dynamic’ specified
    Content-Security-Policy: Ignoring “http:” within script-src: ‘strict-dynamic’ specified

After these changes, only the following warning will remain due to the presence of 'unsafe-inline' within script-src for backward compatibility with browsers not supporting Content-Security-Policy Version 3 (such as Internet Explorer 11):

> Content-Security-Policy: Ignoring “'unsafe-inline'” within script-src: nonce-source or hash-source specified

Unfortunately, Firefox will log this directive being ignored. We must make a trade-off between this warning and maintaining backward compatibility.

See also: https://developer.chrome.com/docs/lighthouse/best-practices/csp-xss/#ensure_csp_is_backwards_compatible

UPDATE:
4. Remove unsafe-inline from script-src:

Content-Security-Policy: Ignoring “'unsafe-inline'” within script-src: nonce-source or hash-source specified

No more Content-Security-Policy warnings in Firefox.

The adjusted browse.html is currently active on my playground:
https://alma.stbu.net/testing-something/

@steffenbusch steffenbusch changed the title Remove 'strict-dynamic' + block-all-mixed-content browse: fix Content-Security-Policy warnings in Firefox Jul 6, 2024
@mholt
Copy link
Member

mholt commented Jul 6, 2024

Thank you for the thoroughly explained changes!

I'm actually good with dropping IE11 at this point, for something like this.

@steffenbusch
Copy link
Contributor Author

I'm actually good with dropping IE11 at this point, for something like this.

I will make the adjustment 👍
FYI regarding support for nonce-source: https://caniuse.com/contentsecuritypolicy2

Copy link
Member

@mholt mholt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent. Thanks so much for working on this! LGTM.

@mholt mholt merged commit 88c7e53 into caddyserver:master Jul 7, 2024
23 checks passed
@steffenbusch steffenbusch deleted the fix-csp branch August 7, 2024 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants