-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Enable strict CSP headers to sandbox against any possible XSS #3632
Comments
This is P3 because it's not on our immediate roadmap, but it seems like a solid idea. I don't have a real idea for the level of effort or return on investment for Riot Web, though - I'll poke some people for some input. |
You've probably all read the articles where people are now successfully looking into finding remote code execution bugs in Electron apps. https://statuscode.ch/2017/11/from-markdown-to-rce-in-atom/ Would be good to know riot.im is prepared for that. |
We use CSP already in the media repository to stop content uploaded stuff containing XSS. Riot/Web itself isn't served with a CSP however, and unsure how Electron is configured. Bumping priority accordingly to investigate. |
marking as critical until proven otherwise |
BTW to make sure each user of Riot uses it, I highly suggest to (also) use the in-HTML version of your CSP. (It's just a meta tag, so that is a nice enhancement) I'll look into creating a CSP, which works with the current version. As always be aware, that CSPs are just additional security features, they can mitigate the attack, but they do not replace a real fix of an XSS attack or so, should one be found. |
BTW it is not critical, but it is a very good (and highly suggested!) security enhancement. |
E.g. a good step would be to do not use inline JS (i.e. don't include JS in HTML code). I think Riot works quite good with that, it just shows two errors in the console, but these seem to work:
And, of course, the |
Same with inline CSS. If you disable that it just breaks the whole styling. The good news is, it works with a relatively strong JS prevention ( BTW a CSP checker can be found at https://csp-evaluator.withgoogle.com/. |
Here is a suggestion for a CSP, which works for the current version:
It only allows |
IMO applying this rule goes a long way toward preventing XSS. |
'unsafe-eval' seems to be needed too, without it CSP reports: call to eval() or related function blocked by CSP. 1 bundle.js:80 Another error CSP reports is this: Any idea how to fix this error? This is the header with unsafe-eval enabled and only self hosted Identity server enabled that I use: |
However, that block does not result in problems, as far as I see. So maybe only something unimportant is blocked. |
I think it would be a good idea not to block parts of riot-web's code. Plus, I wonder why it's blocked in the first place. Scripts from that host should be allowed according to my CSP. |
This here is a message about blocking inline JS (not recommend but could be allowed with Of course, I agree, it would be better if that is moved in a JS file and so not blocked by the CSP. |
I'm not sure that can be moved to js trivially because webpack. As I understand it that line is important so that indexeddb operations happen in a worker. Indexeddb is needed for things like e2e. |
No, e2e and such stuff worked for me without that line. Maybe it saved the database somehow else/used some fallback, or so… |
Post the console of the app starting up, it'll say if it used a fallback storage |
Did never look at that exactly, but that also does not matter. |
If its using fallback storage then it DOES matter as the fallback has race conditions due to being synchronous and localStorage backed which causes e2e to fail in certain circumstances |
So finally the JS should just be moved to a single file or so. Can't that hard… it's one line, after all. |
Except half of that line isn't JavaScript and is instead a build tool generator placeholder for webpack. |
Ah, that's bad then. |
It sounds like it won't be mainlined without that piece of the codebase working. Could you add a build step that moves the inline script to an external file? Again, the important piece here is to get a working CSP into the codebase so we can improve things incrementally, let's not make this a blocking issue. |
Ah, so the Riot devs should add it, sure… as you've mentioned how this can be done before. |
I'm basically asking if you will make the pull request or do I have to? |
No, I'll not do a PR. |
Is there a recommended CSP string I can safely use when selfhosting riot ? And should this be documented somewhere ? |
@Nadrieril I've added mine/one in here. It should preferably not be documented, but actually tweaked (if needed) and merged into the code. |
Ok, thanks ! That'd be very cool indeed |
I would document and unit test each rule* to make sure it hasn't been borked! Declarative specs count as code 😄. *This is technically unit testing and might require a service like Sauce Labs (which has free accounts for F/OSS projects). |
@rugk Did you ever get around to that PR? |
As explained earlier no. Especially, because I don't know it is what the riot devs want. (and how strict it should be, testing etc.) |
riot.im/app now has a CSP on it. however, we have |
For the record the current CSP is, as of ^ is
|
...and we need to add the CSP as a meta tag or similar so that Electron picks it up. |
Related: #11610 |
Had a quick glance why fwiw, I'm using riot web (Firefox) without |
In addition to embedding the CSP as a meta tag in the app, we'd also like to remove |
Splitting off a new issue to track getting rid of |
Modern browsers allow sending Content-Security-Policy headers and will prevent eval() or inline
<script>
tags as well as all of the variants of onload, onerror etc. which is a formidable barrier to XSS security breach.This is an improvement suggestion which consists of removing any inline
<script>
, eval() or on* javascript (move these to remote loaded<script>
and event handlers). Then begin sending CSP headers which (for script) allow 'self' and the urls of any content delivery networks which are used.The benefit is peace of mind because modern browsers will disallow execution of XSS attack script so even if a vulnerability is discovered, the result the the vast majority of users is just an error in the console. Support: http://caniuse.com/#feat=contentsecuritypolicy
The text was updated successfully, but these errors were encountered: