riganti / dotvvm

Open source MVVM framework for Web Apps
https://www.dotvvm.com
Apache License 2.0
743 stars 97 forks source link

Make DotVVM CSP compliant #275

Open djanosik opened 7 years ago

djanosik commented 7 years ago

As of now every DotVVM application uses inline scripts and unsafe functions like new Function(...), eval(...), setTimeout(string), etc. It means you need to specify unsafe-inline and unsafe-eval options when you want to use CSP header to make your application secure.

This makes CSP practically useless and we should think about how to use DotVVM along with CSP restrictions.

I suggest to:

exyi commented 7 years ago

I think we could use the in the script-src header to get rid of unsafe-inline and do it completely automatically using the resource system. The unsafe-eval condition is unfortunately not relaxed, but we could at least modify knockout.js to check hashes of the evaluated before evaluating them so that data-bind injection would not work.

The second step could be made with the VDOM upgrade #383, maybe it will be possible to eliminate the unsafe-eval condition and render all bindings in a render script.

exyi commented 6 years ago

Btw, nice post "why would you want CSP" - https://hackernoon.com/im-harvesting-credit-card-numbers-and-passwords-from-your-site-here-s-how-9a8cb347c5b5. Although it's not a perfect protection, it may help a lot.

exyi commented 2 years ago

https://content-security-policy.com/strict-dynamic/

With strict-dynamic in CSP 3 we might be actually able to finally implement it. This would solve the problem of loading new scripts / knockout expressions after a postback