-
Notifications
You must be signed in to change notification settings - Fork 206
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
Add content-security-policy #234
Conversation
|
- Isn't this missing style-src 'self' cdnjs.cloudflare.com? Looking at files header.hbs and rustdoc.hbs.
Yeah. Thanks for the reminder.
- It would be more secure to drop cdnjs.cloudflare.com from the CSP, and instead use hashes (static) or nonces (dynamic) as described [here](https://www.w3.org/TR/CSP2/#source-list-syntax) - note, it's not supported in CSP1 (IE11). This way it is only allowed to use the specified files and not every file in the CDN. An alternative of course is to host the files directly, not through CDN.
Yeah, but I'd rather do that as a separate pull request. This is already an improvement.
|
If merged this should close #167 as it would completely disable inline scripts for all modern browser users, even including IE. |
Okay, I added the style-src. |
Is there anything else that needs to be done before this can be merged? |
I just did the barest reading of CSP formatting, so forgive me if i'm misunderstanding. Should this include an This will neuter the |
Ideally I would like either rustdoc or docs.rs to have its own support for KaTeX, so that any crate could just use it directly by some first-class mechanism. (I realize this is somewhat orthogonal to the issue at hand, just restating it for clarity). The |
I'd also like to add the ability to link in some libraries as a first-class mechanism (#302). If i can get that in, then we can get these libraries to work properly on docs.rs without having to resort to XSS. If everyone's okay with fixing the XSS first and adding the features later, then i can work on the libraries feature in due time. |
Ah, it looks like our version of Iron has possibly updated since this PR was originally posted, or something else happened that made these imports not work:
|
We should also add |
I took the branch and started updating it to properly compile. It turns out that the version of Hyper that Iron used doesn't have a header struct for CSP, so i had to write a basic one myself. (I didn't try to properly parse out a typed CSP, only store the text used for it. There's a However, when i tried to test it, i ran into problems with all the inline scripts used in the docs.rs template files. Since we don't have separate JavaScript files for the little scripts used on docs.rs's own pages, we'll need to either split those into separate files, or start including nonces/hashes in our CSP. I'll work on this. In addition, i have doubts that including In addition, including |
Cloudfront doesn't care about the header (it's only used by browser), and its configuration explicitly says to only use HTTP when contacting the server. I'll try to find time to investigate what's happening with the favicon. |
I've hit another hurdle: Rustdoc itself adds some inline
I was able to put nonces on all of docs.rs's own inline scripts, but since these are controlled by upstream rustdoc, it's going to be more difficult to properly allow these without just setting |
Looking at it again, it looks like the reason for the inline style was because the SVG being linked in has the resource suffix applied, so from rustdoc's perspective it's going to be different per-crate. I have an idea for how to allow these, but it will probably slow down our web server: we can dynamically insert nonces into rustdoc output, but skip I have a branch available at https://github.com/QuietMisdreavus/docs.rs/tree/csp - i will push it over this PR when i believe that it's ready to be live. It's almost there, pending whether there's another way around the inline script issue. |
I don't think that's going to work, an attacker can find ways to inject custom code outside of docblocks. |
Closing this PR, as we'll need to take a different approach to fix the problem. The team is working on it, and I hope I'll have public information to share soon. |
Related to #167