Answer the question
In order to leave comments, you need to log in
How to know if a string is dangerous (contains XSS) or not?
Hello. How do I know if a string is dangerous or not? I've tried processing the string with HTMLPurifier and then comparing its length with the raw string. If the length is different, then HTMLPurifier removed dangerous elements from this string (tags, attributes). So the line was dangerous.
But it doesn't work. Because HTMLPurifier has Tidy built in. And you can't turn it off. And he changes the line - adds to the <br>
slashes, changes the style attribute - adds a semicolon, removes the space. I'll give you an example.
It was: <div style="color: red">это div</div>
It became: <div style="color:red;">это div</div>
Somewhere else something changes. And it's almost impossible to keep track of all this.
So how can you check if a string is dangerous or not?
Answer the question
In order to leave comments, you need to log in
If the length is different, then HTMLPurifier removed dangerous elements from this string (tags, attributes). So the line was dangerous.
<script>
, but there are many XSS variants and the goal is usually to avoid them, and not to unambiguously identify them. This task is closer to reality. Since a number of methods successfully prevent, but do not detect. Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question