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

Document "strict CSP" and recommend it over allowlists #35812

Open
wbamberg opened this issue Sep 9, 2024 · 2 comments · May be fixed by #36157
Open

Document "strict CSP" and recommend it over allowlists #35812

wbamberg opened this issue Sep 9, 2024 · 2 comments · May be fixed by #36157
Labels
Content:HTTP HTTP docs Content:Security Security docs effort: large This task is large effort. help wanted If you know something about this topic, we would love your help!

Comments

@wbamberg
Copy link
Collaborator

wbamberg commented Sep 9, 2024

The articles about CSP from both OWASP and web.dev recommend that developers use what they call a strict CSP, which uses nonces and/or hashes in script-src instead of an allowlist.

According to these articles, strict CSP is likely to be more secure than an allowlist, and is also much easier to maintain than an allowlist, as this netlify article discusses.

There are 2 guides to CSP on MDN, that I could find:

(aside, I'm not sure of the value of having two guides here)

We should update these guides to talk about strict CSPs. There are really 2 options:

  1. just present strict CSP as another approach, and describe its advantages
  2. actively recommend strict CSP, as the web.dev and OWASP articles do

We talked about this in the SWAG CG meeting and it was felt that the second, more opinionated, approach was more useful.

This work should help contribute to w3c-cg/swag#3.

@github-actions github-actions bot added needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. Content:HTTP HTTP docs Content:Security Security docs labels Sep 9, 2024
@Josh-Cena Josh-Cena added help wanted If you know something about this topic, we would love your help! effort: large This task is large effort. and removed needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. labels Sep 9, 2024
@hamishwillee
Copy link
Collaborator

FWIW:

  • Actively recommending strict CSP makes sense to me.
  • We can still talk about allowlists as an option, in particular there are likely to be cases where generating nonces is hard and managing allowlists becomes the pragmatic option. For example, if it became necessary to use a cross site resource on a static site?
  • You made a point elsewhere that generating nonces really requires some framework support to be broadly achievable, so we need to talk about that.
  • (aside, I'm not sure of the value of having two guides here). It would be better to have one. I thought this one was a bit thin - https://developer.mozilla.org/en-US/docs/Web/Security/Practical_implementation_guides/CSP - I like the idea of practical guidance as a section in the other document.

@wbamberg
Copy link
Collaborator Author

Thanks for the comments Hamish!

We can still talk about allowlists as an option,

Yes, for sure.

in particular there are likely to be cases where generating nonces is hard and managing allowlists becomes the pragmatic option. For example, if it became necessary to use a cross site resource on a static site?

In cases like this the guidance is to use a hash instead, because you can then serve it statically (the hash is always the same, unlike the nonce).

(aside, I'm not sure of the value of having two guides here). It would be better to have one. I thought this one was a bit thin - https://developer.mozilla.org/en-US/docs/Web/Security/Practical_implementation_guides/CSP - I like the idea of practical guidance as a section in the other document.

I might get around to this in the scope of this issue :).

@wbamberg wbamberg linked a pull request Oct 3, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:HTTP HTTP docs Content:Security Security docs effort: large This task is large effort. help wanted If you know something about this topic, we would love your help!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants