All Projects → voku → Anti Xss

voku / Anti Xss

Licence: mit
㊙️ AntiXSS | Protection against Cross-site scripting (XSS) via PHP

Projects that are alternatives of or similar to Anti Xss

Idea Composer Plugin
PhpStorm plugin that adds code completion in composer.json file
Stars: ✭ 346 (-14.14%)
Mutual labels:  composer
Arrayy
🗃 Array manipulation library for PHP, called Arrayy!
Stars: ✭ 363 (-9.93%)
Mutual labels:  composer
Cerberus
一款功能强大的漏洞扫描器,子域名爆破使用aioDNS,asyncio异步快速扫描,覆盖目标全方位资产进行批量漏洞扫描,中间件信息收集,自动收集ip代理,探测Waf信息时自动使用来保护本机真实Ip,在本机Ip被Waf杀死后,自动切换代理Ip进行扫描,Waf信息收集(国内外100+款waf信息)包括安全狗,云锁,阿里云,云盾,腾讯云等,提供部分已知waf bypass 方案,中间件漏洞检测(Thinkphp,weblogic等 CVE-2018-5955,CVE-2018-12613,CVE-2018-11759等),支持SQL注入, XSS, 命令执行,文件包含, ssrf 漏洞扫描, 支持自定义漏洞邮箱推送功能
Stars: ✭ 389 (-3.47%)
Mutual labels:  xss
Flex
Composer plugin for Symfony
Stars: ✭ 3,731 (+825.81%)
Mutual labels:  composer
Scaner
扫描器是来自GitHub平台的开源扫描器的集合,包括子域枚举、数据库漏洞扫描器、弱密码或信息泄漏扫描器、端口扫描器、指纹扫描器以及其他大规模扫描仪、模块扫描器等。对于其他著名的扫描工具,如:awvs、nmap,w3af将不包含在集合范围内。
Stars: ✭ 357 (-11.41%)
Mutual labels:  xss
Noscript
The popular NoScript Security Suite browser extension.
Stars: ✭ 366 (-9.18%)
Mutual labels:  xss
Owasp Java Encoder
The OWASP Java Encoder is a Java 1.5+ simple-to-use drop-in high-performance encoder class with no dependencies and little baggage. This project will help Java web developers defend against Cross Site Scripting!
Stars: ✭ 343 (-14.89%)
Mutual labels:  xss
Protect
Proactively protect your Node.js web services
Stars: ✭ 394 (-2.23%)
Mutual labels:  xss
Wssat
WEB SERVICE SECURITY ASSESSMENT TOOL
Stars: ✭ 360 (-10.67%)
Mutual labels:  xss
Easytbk
淘客5合一SDK,支持淘宝联盟、京东联盟、多多进宝、唯品会、苏宁
Stars: ✭ 383 (-4.96%)
Mutual labels:  composer
Laravel Feed
Laravelium Feed package for Laravel.
Stars: ✭ 356 (-11.66%)
Mutual labels:  composer
Lamp Cloud
lamp-cloud 基于Jdk11 + SpringCloud + SpringBoot的微服务快速开发平台,其中的可配置的SaaS功能尤其闪耀, 具备RBAC功能、网关统一鉴权、Xss防跨站攻击、自动代码生成、多种存储系统、分布式事务、分布式定时任务等多个模块,支持多业务系统并行开发, 支持多服务并行开发,可以作为后端服务的开发脚手架。代码简洁,注释齐全,架构清晰,非常适合学习和企业作为基础框架使用。
Stars: ✭ 4,125 (+923.57%)
Mutual labels:  xss
Coastercms
The repository for Coaster CMS (coastercms.org), a full featured, Laravel based Content Management System
Stars: ✭ 380 (-5.71%)
Mutual labels:  composer
Composer Doc Cn
Composer 中文文档(新版本文档重新翻译中,详见 1.6分支)
Stars: ✭ 346 (-14.14%)
Mutual labels:  composer
Php Goose
Readability / Html Content / Article Extractor & Web Scrapping library written in PHP
Stars: ✭ 392 (-2.73%)
Mutual labels:  composer
Gameq
A PHP Gameserver Status Query Library
Stars: ✭ 342 (-15.14%)
Mutual labels:  composer
Unused Scanner
Detect unused composer dependencies
Stars: ✭ 363 (-9.93%)
Mutual labels:  composer
Laravel Wallet
Easy work with virtual wallet
Stars: ✭ 401 (-0.5%)
Mutual labels:  composer
Dog Ceo Api
The API hosted at dog.ceo
Stars: ✭ 393 (-2.48%)
Mutual labels:  composer
Xsser
From XSS to RCE 2.75 - Black Hat Europe Arsenal 2017 + Extras
Stars: ✭ 381 (-5.46%)
Mutual labels:  xss

Build Status codecov.io Codacy Badge Latest Stable Version Total Downloads License Donate to this project using Paypal Donate to this project using Patreon

㊙️ 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/

NOTES:

  1. Use filter_input() - don't use GLOBAL-Array (e.g. $_SESSION, $_GET, $_POST, $_SERVER) directly

  2. Use html-sanitizer or HTML Purifier if you need a more configurable solution

  3. Add "Content Security Policy's" -> Introduction to Content Security Policy

  4. DO NOT WRITE YOUR OWN REGEX TO PARSE HTML!

  5. READ THIS TEXT -> XSS (Cross Site Scripting) Prevention Cheat Sheet

  6. TEST THIS TOOL -> Zed Attack Proxy (ZAP)

Install via "composer require"

composer require voku/anti-xss

Usage:

use voku\helper\AntiXSS;

require_once __DIR__ . '/vendor/autoload.php'; // example path

$antiXss = new AntiXSS();

Example 1: (HTML Character)

$harm_string = "Hello, i try to <script>alert('Hack');</script> your site";
$harmless_string = $antiXss->xss_clean($harm_string);

// Hello, i try to alert&#40;'Hack'&#41;; your site

Example 2: (Hexadecimal HTML Character)

$harm_string = "<IMG SRC=&#x6A&#x61&#x76&#x61&#x73&#x63&#x72&#x69&#x70&#x74&#x3A&#x61&#x6C&#x65&#x72&#x74&#x28&#x27&#x58&#x53&#x53&#x27&#x29>";
$harmless_string = $antiXss->xss_clean($harm_string);
    
// <IMG >

Example 3: (Unicode Hex Character)

$harm_string = "<a href='&#x2000;javascript:alert(1)'>CLICK</a>";
$harmless_string = $antiXss->xss_clean($harm_string);
    
// <a >CLICK</a>

Example 4: (Unicode Character)

$harm_string = "<a href=\"\u0001java\u0003script:alert(1)\">CLICK<a>";
$harmless_string = $antiXss->xss_clean($harm_string);
    
// <a >CLICK</a>

Example 5.1: (non Inline CSS)

$harm_string = '<li style="list-style-image: url(javascript:alert(0))">';
$harmless_string = $antiXss->xss_clean($harm_string);

// <li >

Example 5.2: (with Inline CSS)

$harm_string = '<li style="list-style-image: url(javascript:alert(0))">';
$antiXss->removeEvilAttributes(array('style')); // allow style-attributes
$harmless_string = $antiXss->xss_clean($harm_string);

// <li style="list-style-image: url(alert&#40;0&#41;)">

Example 6: (check if an string contains a XSS attack)

$harm_string = "\x3cscript src=http://www.example.com/malicious-code.js\x3e\x3c/script\x3e";
$harmless_string = $antiXss->xss_clean($harm_string);

// 

$antiXss->isXssFound(); 

// true

Example 7: (allow e.g. iframes)

$harm_string = "<iframe width="560" onclick="alert('xss')" height="315" src="https://www.youtube.com/embed/foobar?rel=0&controls=0&showinfo=0" frameborder="0" allowfullscreen></iframe>";

$antiXss->removeEvilHtmlTags(array('iframe'));

$harmless_string = $antiXss->xss_clean($harm_string);

// <iframe width="560"  height="315" src="https://www.youtube.com/embed/foobar?rel=0&controls=0&showinfo=0" frameborder="0" allowfullscreen></iframe>

Unit Test:

  1. Composer is a prerequisite for running the tests.
composer install
  1. The tests can be executed by running this command from the root directory:
./vendor/bin/phpunit

AntiXss methods

addEvilAttributes addEvilHtmlTags addNeverAllowedOnEventsAfterwards addNeverAllowedRegex
addNeverAllowedStrAfterwards isXssFound removeEvilAttributes removeEvilHtmlTags
removeNeverAllowedOnEventsAfterwards removeNeverAllowedRegex removeNeverAllowedStrAfterwards setReplacement
setStripe4byteChars xss_clean

addEvilAttributes(string[] $strings): $this

Add some strings to the "_evil_attributes"-array.

Parameters:

  • string[] $strings

Return:

  • $this

addEvilHtmlTags(string[] $strings): $this

Add some strings to the "_evil_html_tags"-array.

Parameters:

  • string[] $strings

Return:

  • $this

addNeverAllowedOnEventsAfterwards(string[] $strings): $this

Add some strings to the "_never_allowed_on_events_afterwards"-array.

Parameters:

  • string[] $strings

Return:

  • $this

addNeverAllowedRegex(string[] $strings): $this

Add some strings to the "_never_allowed_regex"-array.

Parameters:

  • string[] $strings

Return:

  • $this

addNeverAllowedStrAfterwards(string[] $strings): $this

Add some strings to the "_never_allowed_str_afterwards"-array.

Parameters:

  • string[] $strings

Return:

  • $this

isXssFound(): bool|null

Check if the "AntiXSS->xss_clean()"-method found an XSS attack in the last run.

Parameters: nothing

Return:

  • bool|null will return null if the "xss_clean()" wan't running at all

removeEvilAttributes(string[] $strings): $this

Remove some strings from the "_evil_attributes"-array.


WARNING: Use this method only if you have a really good reason.

Parameters:

  • string[] $strings

Return:

  • $this

removeEvilHtmlTags(string[] $strings): $this

Remove some strings from the "_evil_html_tags"-array.


WARNING: Use this method only if you have a really good reason.

Parameters:

  • string[] $strings

Return:

  • $this

removeNeverAllowedOnEventsAfterwards(string[] $strings): $this

Remove some strings from the "_never_allowed_on_events_afterwards"-array.


WARNING: Use this method only if you have a really good reason.

Parameters:

  • string[] $strings

Return:

  • $this

removeNeverAllowedRegex(string[] $strings): $this

Remove some strings from the "_never_allowed_regex"-array.


WARNING: Use this method only if you have a really good reason.

Parameters:

  • string[] $strings

Return:

  • $this

removeNeverAllowedStrAfterwards(string[] $strings): $this

Remove some strings from the "_never_allowed_str_afterwards"-array.


WARNING: Use this method only if you have a really good reason.

Parameters:

  • string[] $strings

Return:

  • $this

setReplacement(string $string): $this

Set the replacement-string for not allowed strings.

Parameters:

  • string $string

Return:

  • $this

setStripe4byteChars(bool $bool): $this

Set the option to stripe 4-Byte chars.


INFO: use it if your DB (MySQL) can't use "utf8mb4" -> preventing stored XSS-attacks

Parameters:

  • bool $bool

Return:

  • $this

xss_clean(array|mixed $str): mixed

XSS Clean


Sanitizes data so that "Cross Site Scripting" hacks can be prevented. This method does a fair amount of work but it is extremely thorough, designed to prevent even the most obscure XSS attempts. But keep in mind that nothing is ever 100% foolproof...


Note: Should only be used to deal with data upon submission. It's not something that should be used for general runtime processing.

Parameters:

  • array|mixed $str <p>input data e.g. string or array of strings</p>

Return:

  • mixed

Support

For support and donations please visit Github | Issues | PayPal | Patreon.

For status updates and release announcements please visit Releases | Twitter | Patreon.

For professional support please contact me.

Thanks

  • Thanks to GitHub (Microsoft) for hosting the code and a good infrastructure including Issues-Managment, etc.
  • Thanks to IntelliJ as they make the best IDEs for PHP and they gave me an open source license for PhpStorm!
  • Thanks to Travis CI for being the most awesome, easiest continous integration tool out there!
  • Thanks to StyleCI for the simple but powerfull code style check.
  • Thanks to PHPStan && Psalm for relly great Static analysis tools and for discover bugs in the code!

License

FOSSA Status

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].