Objective response!
strip_tags () allows other types of XSS then use htmlspecialchars ()
echo htmlspecialchars($Variavel, ENT_QUOTES, 'UTF-8');
Long answer .....
Let's begin in parts, what you want and protect yourself from the XSS , your data entry is enabling the injection of commands or markings, we will analyze this well to be able to create a solution 100% functional, in security we must be calculating.
Analyzing the scenario where XSS can happen!
Let's put two scenarios for this situation
<input type="text" value="$Suspeito">
And another common good is when we put the content into a div
<div class="container" id="ct">
<?php echo $Suspeito ?>
</div>
Now, let's replace this variable with an xss classic
It does not work!
<input type="text" value="<script> alert("Xss here");</script> ">
It works!
<div class="container" id="ct">
<script> alert("Xss here");</script>
</div>
Solution at first sight!
We can add extra protection using strip_tags () to escape the tags!
Let's see how it would look if our variable had a protection with strip_tags ()
It does not work!
<input type="text" value="alert("Xss here"); ">
It does not work!
<div class="container" id="ct">
alert("Xss here");
</div>
Just like in Brazil, there is a way for everything and this solution is far from solving any problem, just use your imagination.
imagine this situation, apparently there are no problems right?
Wrong, let's force our imagination, I need to fuck with this code without using tags
<?php $Suspeito = '" onfocus=document.write("");" fecha="';
<input type="text" value="" onfocus=document.write("");" fecha="">
Oops, now has trouble, is that just the one?
';alert(String.fromCharCode(88,83,83))//';alert(String.fromCharCode(88,83,83))//";
alert(String.fromCharCode(88,83,83))//";alert(String.fromCharCode(88,83,83))//--
></SCRIPT>">'><SCRIPT>alert(String.fromCharCode(88,83,83))</SCRIPT>
'';!--"<XSS>=&{()}
<IMG SRC="javascript:alert('XSS');">
<IMG SRC=javascript:a&
#0000108ert('XSS')>
So we need another solution that does not fail that way, remembering we have another problem, if you escape the tags, no one will be able to use it ... remember math, comparisons, or even code, you just go lose data ...
More flexible solution
By limiting encoding to UTF-8 and using htmlspecialchars, it becomes possible to use tags and scripts in html without having any effect on the page, the characters are disubstituted by < > will flick
16.02.2015 / 06:10