(I know this topic has been discussed a lot in the past, and I've read a lot of threads here as well as OWASP, but have additional questions including the specific CSP listed below.)
We want to allow our users to write each other messages via a WYSIWYG editor, which allows html. So user1 sends user2 a message, we of course display that message to user2; a scary scenario to say the least.
Assuming that we use this editor which allows HTML, is the following plan about as safe as we can hope to be while still allowing a smooth user experience? The editor itself called "Trix" is used and actively maintained by a large company, Basecamp, and they are using it in production for a similar use case. So while I would prefer for security reasons to use markdown and stripping all user input html, if Basecamp can use the editor relatively safely, I would hope we can too.
Our plan is:
Use HTML Purifier to whitelist
A "strict" CSP, specifically Google's proposal: https://csp.withgoogle.com/docs/strict-csp.html
The CSP:
Content-Security-Policy:
object-src 'none';
script-src 'nonce-{random}' 'unsafe-inline' 'unsafe-eval' 'strict-dynamic' https: http:;
base-uri 'none';
report-uri https://your-report-collector.example.com/