Answer the question
In order to leave comments, you need to log in
Would this XSS protection work?
Good afternoon! I came across an article where the author gives such a function
function defender_xss($arr){
$filter = array("<", ">","="," (",")",";","/");
foreach($arr as $num=>$xss){
$arr[$num]=str_replace ($filter, "|", $xss);
}
return $arr;
}
//используйте функцию перед обработкой входящих данных:
$_REQUEST=defender_xss($_REQUEST);
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteRule ^(.*)$ index.php [F,L]
Answer the question
In order to leave comments, you need to log in
array("<", ">","="," (",")",";","/") - but what if you really have text with quotes and brackets at the input?
And it is better to do the filtering itself before displaying it on the page, so that the actual data is stored in the database.
www.php.net/manual/ru/function.htmlspecialchars.php
// upd
XSS protection occurs only at the time of rendering the data.
@Hakkunamatata @Miraage i.e. it turns out that everything can be written to the database calmly, checked only for SQL injections, and already when outputting, in order to avoid misunderstandings, put htmlspecialchars? and it will save from XSS?
The approach is absolutely correct. The reason for XSS and SQL Inj is the lack of user data filtering.
The given example of filtering will help only from elementary attacks, because. you can transfer data using special characters and entities.
I personally prefer to build protection based on whitelisting and escaping.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question