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

loading local stylesheets without self source #676

Open
nizos opened this issue Aug 13, 2024 · 2 comments
Open

loading local stylesheets without self source #676

nizos opened this issue Aug 13, 2024 · 2 comments

Comments

@nizos
Copy link

nizos commented Aug 13, 2024

I am encountering difficulties loading local stylesheets using the style-src-elem directive without including self as a source when using default-src 'none'.

Here is a simple example of the issue:

<link rel="stylesheet" href="style.css">

This setup fails to load when using the following CSP configuration:

add_header Content-Security-Policy "default-src 'none'; img-src 'self'; style-src-elem 'sha256-B8tJV5ov4F69yB5NT1X1BQfMTYEq3RAfk1edjTXJQcF=';";

I have tried adding the integrity attribute, but it did not resolve the issue.

I tested with both Chrome and Firefox and encountered the same issue on both. The stylesheet gets blocked due to CSP violations.

Is it possible to load a local stylesheet without whitelisting 'self' as a source? Of so, what am i missing in my configuration?

I have set up a repository that replicates this behavior for testing:
https://github.com/nizos/csp-docker

Any guidance or clarification on whether this is expected behavior according to the CSP spec is greatly appreciated.

Thanks in advance!

@gapple
Copy link
Contributor

gapple commented Aug 21, 2024

It looks like you have a minor typo in your hash, but that's not the source of the issue

sha256-B8tJV5ov4F69yB5NT1X1BQfMTYEq3RAfk1edjTXJQcF=
sha256-B8tJV5ov4F69yB5NT1X1BQfMTYEq3RAfk1edjTXJQck=

From the spec, only the script matching algorithm includes "Does integrity metadata match source list?", so the spec would need a change to also permit external style resources by integrity hash.

The hash for external scripts is only checked if the <script> element includes an integrity attribute.

@nizos
Copy link
Author

nizos commented Aug 22, 2024

Hi Geoff!

Good catch! I was probably testing and forgot to revert the change.

Thanks for the reference! :)

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

No branches or pull requests

2 participants