new pisilinux web sites
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
<?php namespace ZN\Security;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
class CrossSiteScripting
|
||||
{
|
||||
/**
|
||||
* Script Bad Chars
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $scriptBadChars =
|
||||
[
|
||||
'document\.cookie' => 'document.cookie',
|
||||
'document\.write' => 'document.write',
|
||||
'\.parentNode' => '.parentNode',
|
||||
'\.innerHTML' => '.innerHTML',
|
||||
'\-moz\-binding' => '–moz–binding',
|
||||
'<' => '<',
|
||||
'>' => '>',
|
||||
];
|
||||
|
||||
/**
|
||||
* Encode Cross Site Scripting
|
||||
*
|
||||
* @param string $string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function encode(string $string) : string
|
||||
{
|
||||
$secBadChars = self::$scriptBadChars;
|
||||
|
||||
if( ! empty($secBadChars) )
|
||||
{
|
||||
foreach( $secBadChars as $badChar => $changeChar )
|
||||
{
|
||||
$badChar = trim($badChar, '/');
|
||||
|
||||
$string = preg_replace('/'.$badChar.'/xi', $changeChar, $string);
|
||||
}
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user