[](https://travis-ci.org/voku/anti-xss)
[](http://codecov.io/github/voku/anti-xss?branch=master)
[](https://www.codacy.com/app/voku/anti-xss)
[](https://packagist.org/packages/voku/anti-xss)
[](https://packagist.org/packages/voku/anti-xss)
[](https://packagist.org/packages/voku/anti-xss)
[](https://www.paypal.me/moelleken)
[](https://www.patreon.com/voku)
# :secret: AntiXSS
"Cross-site scripting (XSS) is a type of computer security vulnerability typically found in Web applications. XSS enables
attackers to inject client-side script into Web pages viewed by other users. A cross-site scripting vulnerability may be
used by attackers to bypass access controls such as the same origin policy. Cross-site scripting carried out on websites
accounted for roughly 84% of all security vulnerabilities documented by Symantec as of 2007." - http://en.wikipedia.org/wiki/Cross-site_scripting
### DEMO:
[http://anti-xss-demo.suckup.de/](http://anti-xss-demo.suckup.de/)
### NOTES:
1) Use [filter_input()](http://php.net/manual/de/function.filter-input.php) - don't use GLOBAL-Array (e.g. $_SESSION, $_GET, $_POST, $_SERVER) directly
2) Use [html-sanitizer](https://github.com/tgalopin/html-sanitizer) or [HTML Purifier](http://htmlpurifier.org/) if you need a more configurable solution
3) Add "Content Security Policy's" -> [Introduction to Content Security Policy](http://www.html5rocks.com/en/tutorials/security/content-security-policy/)
4) DO NOT WRITE YOUR OWN REGEX TO PARSE HTML!
5) READ THIS TEXT -> [XSS (Cross Site Scripting) Prevention Cheat Sheet](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.md)
6) TEST THIS TOOL -> [Zed Attack Proxy (ZAP)](https://github.com/zaproxy/zaproxy)
### Install via "composer require"
```shell
composer require voku/anti-xss
```
### Usage:
```php
use voku\helper\AntiXSS;
require_once __DIR__ . '/vendor/autoload.php'; // example path
$antiXss = new AntiXSS();
```
Example 1: (HTML Character)
```php
$harm_string = "Hello, i try to your site";
$harmless_string = $antiXss->xss_clean($harm_string);
// Hello, i try to alert('Hack'); your site
```
Example 2: (Hexadecimal HTML Character)
```php
$harm_string = "";
$harmless_string = $antiXss->xss_clean($harm_string);
//
```
Example 3: (Unicode Hex Character)
```php
$harm_string = "CLICK";
$harmless_string = $antiXss->xss_clean($harm_string);
// CLICK
```
Example 4: (Unicode Character)
```php
$harm_string = "CLICK";
$harmless_string = $antiXss->xss_clean($harm_string);
// CLICK
```
Example 5.1: (non Inline CSS)
```php
$harm_string = '