4 ms·
> cleaning up user-supplied markup to at least be valid HTML The root cause of XSS is improper user input sanitization. Usually it is in places that shouldn't
by nadaviv 10y ago
> cleaning up user-supplied markup to at least be valid HTML
The root cause of XSS is improper user input sanitization. Usually it is in places that shouldn't allow HTML at all, where the developer forgot to properly HTML-escape the user-provided input. If not encoding it at all can slip by, then obviously not verifying that its valid HTML could too (plus, it doesn't make sense to verify valid HTML when you aren't even expecting HTML).
The focus on dangling markup is because a CSP policy that prevents unauthorized JavaScript from executing (no inline scripts, remote scripts from trusted hosts only) can resolve most of the XSS issues, but it doesn't resolve leakage of information over other channels (such as via images).
While CSP could be used to completely block images from external hosts (and thus solve the leakage issue), you sometimes do want to allow users to inline external images and so an alternative solution to prevent sensitive information from being leaked is required.
Edit: haven't seen ptoomey3's comment while I wrote mine. He explained it better :-)