mirror of
https://github.com/icecoder/ICEcoder.git
synced 2026-03-08 01:26:47 +01:00
Largely adjusted XSS protection
Adjusted to match that implemented by Ashar Javed (https://twitter.com/soaj1664ashar, demo: http://xssplaygroundforfunandlearn.netai.net/final.html). Was unbreakable against 78k XSS attempts, so seems very solid
This commit is contained in:
@@ -71,31 +71,33 @@ function xssClean($data,$type) {
|
||||
|
||||
// === style ===
|
||||
if ($type == "style") {
|
||||
$bad = array("\"", "``", "(", ")", "&", ".", "\\");
|
||||
$good = array(""", "``", "(", ")", "&", ".", "\");
|
||||
$bad = array("<", ">", "\"", "'", "``", "(", ")", "&", "\\\\");
|
||||
$good = array("<", ">", """, "'", "`", "(", ")", "&", "\");
|
||||
}
|
||||
|
||||
// === attribute ===
|
||||
if ($type == "attribute") {
|
||||
$bad = array("\"", "``");
|
||||
$good = array(""", "``");
|
||||
$bad = array("\"", "'", "``");
|
||||
$good = array(""", "'", "`");
|
||||
}
|
||||
|
||||
// === script ===
|
||||
if ($type == "script") {
|
||||
$bad = array("<", ">", "(", ")", "[", "]", "\"", "'", ";");
|
||||
$good = array("<", ">", "(", ")", "[", "]", """, "'", ";");
|
||||
$bad = array("<", ">", "\"", "'", "\\\\", "%", "&");
|
||||
$good = array("<", ">", """, "'", "\", "%", "&");
|
||||
}
|
||||
|
||||
// === url ===
|
||||
if ($type == "url") {
|
||||
$bad = array("\"", "``");
|
||||
$good = array("%22", "%60%60");
|
||||
if(preg_match("#^(?:(?:https?|ftp):{1})\/\/[^\"\s\\\\]*.[^\"\s\\\\]*$#iu",(string)$data,$match)) {
|
||||
return $match[0];
|
||||
} else {
|
||||
return 'javascript:void(0)';
|
||||
}
|
||||
}
|
||||
|
||||
$data = str_replace($bad, $good, $data);
|
||||
|
||||
return $data;
|
||||
$output = str_replace($bad, $good, $data);
|
||||
return $output;
|
||||
}
|
||||
|
||||
// returns a UTF8 based string with any UFT8 BOM removed
|
||||
|
||||
Reference in New Issue
Block a user