Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XSS prevention. Handling <script is enough?

I was wondering if checking for and removing "<script" from text entry fields would be enough to stop javascript code injection attacks?

like image 390
Karlth Avatar asked Dec 03 '10 10:12

Karlth


People also ask

Is encoding enough to prevent XSS?

Encoding is probably the most important line of XSS defense, but it is not sufficient to prevent XSS vulnerabilities in every context. You should also validate input as strictly as possible at the point when it is first received from a user.

Is Htmlentities enough to prevent XSS?

htmlentities vs htmlspecialcharsBoth will prevent XSS attacks. The difference is in the characters each encodes.

Is CSP enough for XSS?

A Content Security Policy (CSP) helps to ensure any content loaded in the page is trusted by the site owner. CSPs mitigate cross-site scripting (XSS) attacks because they can block unsafe scripts injected by attackers. However, the CSP can easily be bypassed if it is not strict enough.


1 Answers

No, blocking specific cases is not enough - sooner or later, someone will come up with a contrived case you didn't think of.

See this list of XSS attacks for the most common ones (other, still more exotic, may exist). You need to whitelist the allowed syntax instead of assuming that everything beside the known vectors should be OK.

like image 120
Piskvor left the building Avatar answered Oct 22 '22 22:10

Piskvor left the building