I'm trying to understand why certain CSPs block inline javascript. Is the concern that a user will be able to insert javascript that will then be served to other users? If so, isn't this an issue with the fact that a user somehow has the ability to serve whatever they want to users from your site? How is this a CSP problem?
2 Answers
If so, isn't this an issue with the fact that a user somehow has the ability to serve whatever they want to users from your site?
It is actually very common that users have the ability to serve their own content. Just have a look at all the social networks and public blog sites where users can provide their own content within a site they don't own.
How is this a CSP problem?
Usually the content added by users gets sanitized, i.e. script and other things are removed. But, this sanitizing might have bugs. CSP offers an additional line of defense: if CSP disallows inline script no inline script will be executed even though some inline script might have bypassed the sanitizing.
- 201,479
- 30
- 402
- 465
Is the concern that a user will be able to insert javascript that will then be served to other users?
Yes, and that JS can do whatever it wants, just like a full script tag, with a few minor inconvenient syntax restrictions.
If so, isn't this an issue with the fact that a user somehow has the ability to serve whatever they want to users from your site?
Yes, you don't want that happening at all, CSP or not. You want to convey the user's intent, not republish the user's input. CSP is not the front line of defense, it's a backup to mitigate the harm from mistakes like not enough sanitizing, too-smart template engines, and plain bugs.
How is this a CSP problem?
It's content, and it relates to security, so the Content Security Policy is a good place to address the issue, right?
- 2,693
- 11
- 16
eval, etc.) then you've become nigh-invulnerable to XSS, at least for CSP-supporting clients. If you leave any of those protections out, you may be vulnerable to XSS. Of course, other non-script insertion attacks may still work, and some people still use IE11, so you still need to secure your user input. – CBHacking Oct 09 '17 at 07:12<script>tag but not, for some reason, an event handler (perhaps your input filter rejects=characters). Slightly better than nothing. – CBHacking Oct 09 '17 at 07:32