-
Notifications
You must be signed in to change notification settings - Fork 14
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
Remove dangerous HTML from emails #7
Comments
After working on this for a while, I concluded that we should not use DOMPurify, but instead do proper sandboxing. This is the simplest way to protect from dangerous HTML. See PR #11 (comment) Sandboxing with iFramesAs it seems to be done by Mailpile. They sandbox the HTML, and only use DOMPurify to block remote content. See their code to display emails https://www.html5rocks.com/en/tutorials/security/sandboxed-iframes/ <iframe sandbox seamless srcdoc="{emailHtml}"></iframe> Sandboxing in special Electron viewsUsing BrowserView with the necessary https://electronjs.org/docs/api/browser-view https://electronjs.org/docs/tutorial/security Sandboxing with a React Native WebViewDisabling JS and other options are available for WebViews. https://github.com/react-native-community/react-native-webview/blob/master/docs/Reference.md |
We can always cleanup the HTML a bit, by removing all scripts resources for example, but that's just optimization. Edit:
|
Mailspring has a whitelist of allowed tags and attributes that they use in conjunction with a sandboxed iFrame: source |
Thanks for the thorough research and examples! Sandboxing the IFRAME and disabling JS for the react-native Webview sounds like the way to go. Would setting the necessary |
I'm still thinking about this. I'm not a security expert, but I know that several safety nets are better than a single one. And it's best to whitelist things, and only allow what we need. So we need to ensure minimal security protection, and then find a balance between perf/maintenance and added security. MobileFor mobile, the minimum is using a WebView with JS disabled ([K-9 only does that](K-9 does just that)). It will act as a sandbox. But as Android doc recommends, WebView can have vulnerability. We could add an iFrame on top of that, if we find there's no added cost. Here is what I would do for the WebView:
I don't know how an attacker could access the cache. So I don't know if this affects us or not. ElectronFor Electron, using a
Here is what I would do for the BrowserView:
And also use a sandboxed iframe inside that BrowserView <iframe sandbox seamless srcdoc="{emailHtml}"></iframe> |
Without completely relying on DOMPurify for security, we can still use it to whitelist things as Mailspring does. I'll try their approach |
In retrospect, DOMPurify is quite heavy. |
Thanks for documenting all suggestions. This is great! Going to try them this week. It's really hard for me to judge the security quality of DOMPurify vs the others. Perhaps we can start with the low hanging fruit? |
If you mean libs similar to DOMPurify, like then yes, I agree it's hard to tell. I feel like DOMPurify is quite mature and is the most secure, while still preserving as much of the original HTML as possible. Performance is not their main priority of course xss-filters is not adapted for our use case And sanitize-html seems simpler, with safe default options, although it's aimed a HTML fragments, rather than whole documents. I added it to the benchmarks and it's fast. We may use instead of DOMPurify for this suggestion. I don't know other alternatives. |
Other sanitizing lib https://github.com/bevacqua/insane |
To protect the apps (especially the Electron app) from XSS attacks, we want to sanitize the displayed HTML.
DOMPurify is promising, we need to make sure it has not impact on performance.
The text was updated successfully, but these errors were encountered: