Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XSS regular expression

What is an regular expression that can be used to determine if a string is an XSS (cross site scripting) security risk?

like image 282
Phil Avatar asked Feb 26 '23 10:02

Phil


1 Answers

That depends on the context in which that string is being used.

For instance, if the string is being printed out as part of an HTML page, then the special HTML characters <, >, ", and ' can potentially be XSS risks.

If it's being passed around via JSON, then ' and " could potentially be XSS risks.

If it's being included in SQL statements (which it really shouldn't be, at least not directly - use parameterized queries), then things like ; and backticks may be an issue.

Et cetera.

like image 121
Amber Avatar answered Mar 08 '23 14:03

Amber