- Notifications
You must be signed in to change notification settings - Fork 14.1k
Add Content Security Policy to default #50771
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
Conversation
This CSP intends to prevent pwnie attacks as seen in https://docs.rs/pwnies/0.0.14/pwnies/ The idea is that we don't allow script tags unless they are hosted in the same origin. (We also have to disallow plugins (Java, Flash) because they do weird things with the Same Origin Policy)
| Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @QuietMisdreavus (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
| The job Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
| I'm opposed to this PR. This has been debated before and the conclusion was more or less that abusers would get blacklisted. |
| @hdevalence @isislovecruft since y'all were the ones who popularized linking in JS - Would a CSP like this allow you to do what you needed? (I don't fully understand CSP so i'll need everyone else to describe what's going on... |
| This will break people who use KaTeX in their docs, right? |
| docs.rs definitely needs to set a CSP. I don't think it's right for rustdoc to have one by default, especially if it can't be disabled. |
| @ollie27 Yes, I'd expect a hosted service like docs.rs to set a CSP via the HTTP header. I'd also expect it to have a (documented) set of domains that it actually does allow to load resources from – e.g. CDNs like cdn.jsdelivr.net so people can include KaTeX without adding its source to their crate. |
| No, KaTeX wouldn't work anymore. And I think the same: CSP should be up to the host, not to rustdoc. |
| At a glance, I think this change will break our docs on https://doc.dalek.rs and https://doc-internal.dalek.rs . IMO the root of the |
| Hi! My recommendation to the awesome people running the docs.rs server was to set a CSP and whitelist some common CDNs. I'm uncertain whether rustdoc should be setting the CSP policy, but it might not be the worst idea? Pros:
Cons:
|
| Thank you folks for helping me getting a better picture of the issue at hand. I'll come up with a better plan then :) |
| Ping from triage @mozfreddyb! Did you came up with a plan for this? |
| Thank you for this PR @mozfreddyb! Unfortunately we haven't heard from you on this in a while, so I'm closing the PR to keep things tidy. Don't worry though, if you'll have time again in the future please reopen this PR, we'll be happy to review it again! |
This CSP intends to prevent pwnie attacks as seen in https://docs.rs/pwnies/0.0.14/pwnies/
The idea is that we don't allow script tags with inline scripts. And no scripts from JSfiles unless they are hosted in the same origin.
(We also have to disallow plugins (Java, Flash) because they do weird things with the Same Origin Policy)
This might leave in an attack where a crate contains the JS file itself though?