Completed
Push — master ( 8edf32...d75900 )
by Lars
03:24
created

XssTest   D

Complexity

Total Complexity 39

Size/Duplication

Total Lines 1122
Duplicated Lines 7.49 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 39
c 2
b 0
f 1
lcom 1
cbo 4
dl 84
loc 1122
rs 4.093

24 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A test_xss_hash() 0 4 1
A test_no_xss_url_with_json() 0 10 2
A test_no_xss() 0 21 2
A test_xss_clean() 0 8 1
A test_xss_clean_string_array() 0 18 2
A test_xss_clean_image_valid() 0 8 1
A test_xss_clean_image_invalid() 0 8 1
A testHtmlXssFile() 7 7 1
A testSvgXssFileV1() 7 7 1
A testSvgXssFileV2() 11 11 1
A testScriptEncoding() 15 15 2
A testOnError() 0 17 2
B testXssClean() 0 353 6
B testSvgXss() 44 44 2
B testJavaScriptCleaning() 0 137 3
A test_xss_clean_entity_double_encoded() 0 15 2
A test_xss_clean_js_img_removal() 0 5 1
A test_xss_clean_js_a_removal() 0 5 1
A test_xss_clean_js_div_removal() 0 14 1
A test_naughty_html_plus_evil_attributes() 0 4 1
A test_xss_clean_sanitize_naughty_html() 0 8 1
A test_xss_clean_sanitize_naughty_html_attributes() 0 22 1
B testXss() 0 334 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
use voku\helper\AntiXSS;
4
use voku\helper\Bootup;
5
use voku\helper\UTF8;
6
7
class XssTest extends PHPUnit_Framework_TestCase {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
8
9
  // INFO: here you can find some more tests
10
  //
11
  // - https://www.xssposed.org/incidents/
12
  // - http://www.bioinformatics.org/phplabware/internal_utilities/htmLawed/htmLawed_TESTCASE.txt
13
  // - http://htmlpurifier.org/live/smoketests/xssAttacks.php
14
  // - http://hackingforsecurity.blogspot.de/2013/11/xss-cheat-sheet-huge-list.html
15
16
  /**
17
   * @var $security AntiXSS
18
   */
19
  public $security;
20
21
  public function setUp()
22
  {
23
    $this->security = new AntiXSS();
24
  }
25
26
  public function test_no_xss_url_with_json()
27
  {
28
    $testArray = array(
29
        'http://foo.bar/tpl_preview.php?pid=122&json=%7B%22recipe_id%22%3A-1%2C%22recipe_created%22%3A%22%22%2C%22recipe_title%22%3A%22vxcvxc%22%2C%22recipe_description%22%3A%22%22%2C%22recipe_yield%22%3A0%2C%22recipe_prepare_time%22%3A0%2C%22recipe_image%22%3A%22%22%2C%22recipe_legal%22%3A0%2C%22recipe_live%22%3A0%2C%22recipe_user_guid%22%3A%22%22%2C%22recipe_category_id%22%3A%5B%5D%2C%22recipe_category_name%22%3A%5B%5D%2C%22recipe_variety_id%22%3A%5B%5D%2C%22recipe_variety_name%22%3A%5B%5D%2C%22recipe_tag_id%22%3A%5B%5D%2C%22recipe_tag_name%22%3A%5B%5D%2C%22recipe_instruction_id%22%3A%5B%5D%2C%22recipe_instruction_text%22%3A%5B%5D%2C%22recipe_ingredient_id%22%3A%5B%5D%2C%22recipe_ingredient_name%22%3A%5B%5D%2C%22recipe_ingredient_amount%22%3A%5B%5D%2C%22recipe_ingredient_unit%22%3A%5B%5D%2C%22formMatchingArray%22%3A%7B%22unites%22%3A%5B%22Becher%22%2C%22Beete%22%2C%22Beutel%22%2C%22Blatt%22%2C%22Bl%5Cu00e4tter%22%2C%22Bund%22%2C%22B%5Cu00fcndel%22%2C%22cl%22%2C%22cm%22%2C%22dicke%22%2C%22dl%22%2C%22Dose%22%2C%22Dose%5C%2Fn%22%2C%22d%5Cu00fcnne%22%2C%22Ecke%28n%29%22%2C%22Eimer%22%2C%22einige%22%2C%22einige+Stiele%22%2C%22EL%22%2C%22EL%2C+geh%5Cu00e4uft%22%2C%22EL%2C+gestr.%22%2C%22etwas%22%2C%22evtl.%22%2C%22extra%22%2C%22Fl%5Cu00e4schchen%22%2C%22Flasche%22%2C%22Flaschen%22%2C%22g%22%2C%22Glas%22%2C%22Gl%5Cu00e4ser%22%2C%22gr.+Dose%5C%2Fn%22%2C%22gr.+Fl.%22%2C%22gro%5Cu00dfe%22%2C%22gro%5Cu00dfen%22%2C%22gro%5Cu00dfer%22%2C%22gro%5Cu00dfes%22%2C%22halbe%22%2C%22Halm%28e%29%22%2C%22Handvoll%22%2C%22K%5Cu00e4stchen%22%2C%22kg%22%2C%22kl.+Bund%22%2C%22kl.+Dose%5C%2Fn%22%2C%22kl.+Glas%22%2C%22kl.+Kopf%22%2C%22kl.+Scheibe%28n%29%22%2C%22kl.+St%5Cu00fcck%28e%29%22%2C%22kl.Flasche%5C%2Fn%22%2C%22kleine%22%2C%22kleinen%22%2C%22kleiner%22%2C%22kleines%22%2C%22Knolle%5C%2Fn%22%2C%22Kopf%22%2C%22K%5Cu00f6pfe%22%2C%22K%5Cu00f6rner%22%2C%22Kugel%22%2C%22Kugel%5C%2Fn%22%2C%22Kugeln%22%2C%22Liter%22%2C%22m.-gro%5Cu00dfe%22%2C%22m.-gro%5Cu00dfer%22%2C%22m.-gro%5Cu00dfes%22%2C%22mehr%22%2C%22mg%22%2C%22ml%22%2C%22Msp.%22%2C%22n.+B.%22%2C%22Paar%22%2C%22Paket%22%2C%22Pck.%22%2C%22Pkt.%22%2C%22Platte%5C%2Fn%22%2C%22Port.%22%2C%22Prise%28n%29%22%2C%22Prisen%22%2C%22Prozent+%25%22%2C%22Riegel%22%2C%22Ring%5C%2Fe%22%2C%22Rippe%5C%2Fn%22%2C%22Rolle%28n%29%22%2C%22Sch%5Cu00e4lchen%22%2C%22Scheibe%5C%2Fn%22%2C%22Schuss%22%2C%22Spritzer%22%2C%22Stange%5C%2Fn%22%2C%22St%5Cu00e4ngel%22%2C%22Stiel%5C%2Fe%22%2C%22Stiele%22%2C%22St%5Cu00fcck%28e%29%22%2C%22Tafel%22%2C%22Tafeln%22%2C%22Tasse%22%2C%22Tasse%5C%2Fn%22%2C%22Teil%5C%2Fe%22%2C%22TL%22%2C%22TL+%28geh%5Cu00e4uft%29%22%2C%22TL+%28gestr.%29%22%2C%22Topf%22%2C%22Tropfen%22%2C%22Tube%5C%2Fn%22%2C%22T%5Cu00fcte%5C%2Fn%22%2C%22viel%22%2C%22wenig%22%2C%22W%5Cu00fcrfel%22%2C%22Wurzel%22%2C%22Wurzel%5C%2Fn%22%2C%22Zehe%5C%2Fn%22%2C%22Zweig%5C%2Fe%22%5D%2C%22yield%22%3A%7B%221%22%3A%221+Portion%22%2C%222%22%3A%222+Portionen%22%2C%223%22%3A%223+Portionen%22%2C%224%22%3A%224+Portionen%22%2C%225%22%3A%225+Portionen%22%2C%226%22%3A%226+Portionen%22%2C%227%22%3A%227+Portionen%22%2C%228%22%3A%228+Portionen%22%2C%229%22%3A%229+Portionen%22%2C%2210%22%3A%2210+Portionen%22%2C%2211%22%3A%2211+Portionen%22%2C%2212%22%3A%2212+Portionen%22%7D%2C%22prepare_time%22%3A%7B%221%22%3A%22schnell%22%2C%222%22%3A%22mittel%22%2C%223%22%3A%22aufwendig%22%7D%2C%22category%22%3A%7B%221%22%3A%22Vorspeise%22%2C%222%22%3A%22Suppe%22%2C%223%22%3A%22Salat%22%2C%224%22%3A%22Hauptspeise%22%2C%225%22%3A%22Beilage%22%2C%226%22%3A%22Nachtisch%5C%2FDessert%22%2C%227%22%3A%22Getr%5Cu00e4nke%22%2C%228%22%3A%22B%5Cu00fcffet%22%2C%229%22%3A%22Fr%5Cu00fchst%5Cu00fcck%5C%2FBrunch%22%7D%2C%22variety%22%3A%7B%221%22%3A%22Basmati+Reis%22%2C%222%22%3A%22Basmati+%26amp%3B+Wild+Reis%22%2C%223%22%3A%22R%5Cu00e4ucherreis%22%2C%224%22%3A%22Jasmin+Reis%22%2C%225%22%3A%221121+Basmati+Wunderreis%22%2C%226%22%3A%22Spitzen+Langkorn+Reis%22%2C%227%22%3A%22Wildreis%22%2C%228%22%3A%22Naturreis%22%2C%229%22%3A%22Sushi+Reis%22%7D%2C%22tag--ingredient%22%3A%7B%221%22%3A%22Eier%22%2C%222%22%3A%22Gem%5Cu00fcse%22%2C%223%22%3A%22Getreide%22%2C%224%22%3A%22Fisch%22%2C%225%22%3A%22Fleisch%22%2C%226%22%3A%22Meeresfr%5Cu00fcchte%22%2C%227%22%3A%22Milchprodukte%22%2C%228%22%3A%22Obst%22%2C%229%22%3A%22Salat%22%7D%2C%22tag--preparation%22%3A%7B%2210%22%3A%22Backen%22%2C%2211%22%3A%22Blanchieren%22%2C%2212%22%3A%22Braten%5C%2FSchmoren%22%2C%2213%22%3A%22D%5Cu00e4mpfen%5C%2FD%5Cu00fcnsten%22%2C%2214%22%3A%22Einmachen%22%2C%2215%22%3A%22Frittieren%22%2C%2216%22%3A%22Gratinieren%5C%2F%5Cu00dcberbacken%22%2C%2217%22%3A%22Grillen%22%2C%2218%22%3A%22Kochen%22%7D%2C%22tag--kitchen%22%3A%7B%2219%22%3A%22Afrikanisch%22%2C%2220%22%3A%22Alpenk%5Cu00fcche%22%2C%2221%22%3A%22Asiatisch%22%2C%2222%22%3A%22Deutsch+%28regional%29%22%2C%2223%22%3A%22Franz%5Cu00f6sisch%22%2C%2224%22%3A%22Mediterran%22%2C%2225%22%3A%22Orientalisch%22%2C%2226%22%3A%22Osteurop%5Cu00e4isch%22%2C%2227%22%3A%22Skandinavisch%22%2C%2228%22%3A%22S%5Cu00fcdamerikanisch%22%2C%2229%22%3A%22US-Amerikanisch%22%2C%2230%22%3A%22%22%7D%2C%22tag--difficulty%22%3A%7B%2231%22%3A%22Einfach%22%2C%2232%22%3A%22Mittelschwer%22%2C%2233%22%3A%22Anspruchsvoll%22%7D%2C%22tag--feature%22%3A%7B%2234%22%3A%22Gut+vorzubereiten%22%2C%2235%22%3A%22Kalorienarm+%5C%2F+leicht%22%2C%2236%22%3A%22Klassiker%22%2C%2237%22%3A%22Preiswert%22%2C%2238%22%3A%22Raffiniert%22%2C%2239%22%3A%22Vegetarisch+%5C%2F+Vegan%22%2C%2240%22%3A%22Vitaminreich%22%2C%2241%22%3A%22Vollwert%22%2C%2242%22%3A%22%22%7D%2C%22tag%22%3A%7B%221%22%3A%22Eier%22%2C%222%22%3A%22Gem%5Cu00fcse%22%2C%223%22%3A%22Getreide%22%2C%224%22%3A%22Fisch%22%2C%225%22%3A%22Fleisch%22%2C%226%22%3A%22Meeresfr%5Cu00fcchte%22%2C%227%22%3A%22Milchprodukte%22%2C%228%22%3A%22Obst%22%2C%229%22%3A%22Salat%22%2C%2210%22%3A%22Backen%22%2C%2211%22%3A%22Blanchieren%22%2C%2212%22%3A%22Braten%5C%2FSchmoren%22%2C%2213%22%3A%22D%5Cu00e4mpfen%5C%2FD%5Cu00fcnsten%22%2C%2214%22%3A%22Einmachen%22%2C%2215%22%3A%22Frittieren%22%2C%2216%22%3A%22Gratinieren%5C%2F%5Cu00dcberbacken%22%2C%2217%22%3A%22Grillen%22%2C%2218%22%3A%22Kochen%22%2C%2219%22%3A%22Afrikanisch%22%2C%2220%22%3A%22Alpenk%5Cu00fcche%22%2C%2221%22%3A%22Asiatisch%22%2C%2222%22%3A%22Deutsch+%28regional%29%22%2C%2223%22%3A%22Franz%5Cu00f6sisch%22%2C%2224%22%3A%22Mediterran%22%2C%2225%22%3A%22Orientalisch%22%2C%2226%22%3A%22Osteurop%5Cu00e4isch%22%2C%2227%22%3A%22Skandinavisch%22%2C%2228%22%3A%22S%5Cu00fcdamerikanisch%22%2C%2229%22%3A%22US-Amerikanisch%22%2C%2230%22%3A%22%22%2C%2231%22%3A%22Einfach%22%2C%2232%22%3A%22Mittelschwer%22%2C%2233%22%3A%22Anspruchsvoll%22%2C%2234%22%3A%22Gut+vorzubereiten%22%2C%2235%22%3A%22Kalorienarm+%5C%2F+leicht%22%2C%2236%22%3A%22Klassiker%22%2C%2237%22%3A%22Preiswert%22%2C%2238%22%3A%22Raffiniert%22%2C%2239%22%3A%22Vegetarisch+%5C%2F+Vegan%22%2C%2240%22%3A%22Vitaminreich%22%2C%2241%22%3A%22Vollwert%22%2C%2242%22%3A%22%22%7D%7D%2C%22errorArray%22%3A%7B%22recipe_prepare_time%22%3A%22error%22%2C%22recipe_yield%22%3A%22error%22%2C%22recipe_category_name%22%3A%22error%22%2C%22recipe_tag_name%22%3A%22error%22%2C%22recipe_instruction_text%22%3A%22error%22%2C%22recipe_ingredient_name%22%3A%22error%22%7D%2C%22errorMessage%22%3A%22Bitte+f%5Cu00fclle+die+rot+markierten+Felder+korrekt+aus.%22%2C%22db%22%3A%7B%22query_count%22%3A20%7D%7D' => 'http://foo.bar/tpl_preview.php?pid=122&json={"recipe_id":-1,"recipe_created":"","recipe_title":"vxcvxc","recipe_description":"","recipe_yield":0,"recipe_prepare_time":0,"recipe_image":"","recipe_legal":0,"recipe_live":0,"recipe_user_guid":"","recipe_category_id":[],"recipe_category_name":[],"recipe_variety_id":[],"recipe_variety_name":[],"recipe_tag_id":[],"recipe_tag_name":[],"recipe_instruction_id":[],"recipe_instruction_text":[],"recipe_ingredient_id":[],"recipe_ingredient_name":[],"recipe_ingredient_amount":[],"recipe_ingredient_unit":[],"formMatchingArray":{"unites":["Becher","Beete","Beutel","Blatt","Blätter","Bund","Bündel","cl","cm","dicke","dl","Dose","Dose\/n","dünne","Ecke(n)","Eimer","einige","einige Stiele","EL","EL, gehäuft","EL, gestr.","etwas","evtl.","extra","Fläschchen","Flasche","Flaschen","g","Glas","Gläser","gr. Dose\/n","gr. Fl.","große","großen","großer","großes","halbe","Halm(e)","Handvoll","Kästchen","kg","kl. Bund","kl. Dose\/n","kl. Glas","kl. Kopf","kl. Scheibe(n)","kl. Stück(e)","kl.Flasche\/n","kleine","kleinen","kleiner","kleines","Knolle\/n","Kopf","Köpfe","Körner","Kugel","Kugel\/n","Kugeln","Liter","m.-große","m.-großer","m.-großes","mehr","mg","ml","Msp.","n. B.","Paar","Paket","Pck.","Pkt.","Platte\/n","Port.","Prise(n)","Prisen","Prozent %","Riegel","Ring\/e","Rippe\/n","Rolle(n)","Schälchen","Scheibe\/n","Schuss","Spritzer","Stange\/n","Stängel","Stiel\/e","Stiele","Stück(e)","Tafel","Tafeln","Tasse","Tasse\/n","Teil\/e","TL","TL (gehäuft)","TL (gestr.)","Topf","Tropfen","Tube\/n","Tüte\/n","viel","wenig","Würfel","Wurzel","Wurzel\/n","Zehe\/n","Zweig\/e"],"yield":{"1":"1 Portion","2":"2 Portionen","3":"3 Portionen","4":"4 Portionen","5":"5 Portionen","6":"6 Portionen","7":"7 Portionen","8":"8 Portionen","9":"9 Portionen","10":"10 Portionen","11":"11 Portionen","12":"12 Portionen"},"prepare_time":{"1":"schnell","2":"mittel","3":"aufwendig"},"category":{"1":"Vorspeise","2":"Suppe","3":"Salat","4":"Hauptspeise","5":"Beilage","6":"Nachtisch\/Dessert","7":"Getränke","8":"Büffet","9":"Frühstück\/Brunch"},"variety":{"1":"Basmati Reis","2":"Basmati & Wild Reis","3":"Räucherreis","4":"Jasmin Reis","5":"1121 Basmati Wunderreis","6":"Spitzen Langkorn Reis","7":"Wildreis","8":"Naturreis","9":"Sushi Reis"},"tag--ingredient":{"1":"Eier","2":"Gemüse","3":"Getreide","4":"Fisch","5":"Fleisch","6":"Meeresfrüchte","7":"Milchprodukte","8":"Obst","9":"Salat"},"tag--preparation":{"10":"Backen","11":"Blanchieren","12":"Braten\/Schmoren","13":"Dämpfen\/Dünsten","14":"Einmachen","15":"Frittieren","16":"Gratinieren\/Überbacken","17":"Grillen","18":"Kochen"},"tag--kitchen":{"19":"Afrikanisch","20":"Alpenküche","21":"Asiatisch","22":"Deutsch (regional)","23":"Französisch","24":"Mediterran","25":"Orientalisch","26":"Osteuropäisch","27":"Skandinavisch","28":"Südamerikanisch","29":"US-Amerikanisch","30":""},"tag--difficulty":{"31":"Einfach","32":"Mittelschwer","33":"Anspruchsvoll"},"tag--feature":{"34":"Gut vorzubereiten","35":"Kalorienarm \/ leicht","36":"Klassiker","37":"Preiswert","38":"Raffiniert","39":"Vegetarisch \/ Vegan","40":"Vitaminreich","41":"Vollwert","42":""},"tag":{"1":"Eier","2":"Gemüse","3":"Getreide","4":"Fisch","5":"Fleisch","6":"Meeresfrüchte","7":"Milchprodukte","8":"Obst","9":"Salat","10":"Backen","11":"Blanchieren","12":"Braten\/Schmoren","13":"Dämpfen\/Dünsten","14":"Einmachen","15":"Frittieren","16":"Gratinieren\/Überbacken","17":"Grillen","18":"Kochen","19":"Afrikanisch","20":"Alpenküche","21":"Asiatisch","22":"Deutsch (regional)","23":"Französisch","24":"Mediterran","25":"Orientalisch","26":"Osteuropäisch","27":"Skandinavisch","28":"Südamerikanisch","29":"US-Amerikanisch","30":"","31":"Einfach","32":"Mittelschwer","33":"Anspruchsvoll","34":"Gut vorzubereiten","35":"Kalorienarm \/ leicht","36":"Klassiker","37":"Preiswert","38":"Raffiniert","39":"Vegetarisch \/ Vegan","40":"Vitaminreich","41":"Vollwert","42":""}},"errorArray":{"recipe_prepare_time":"error","recipe_yield":"error","recipe_category_name":"error","recipe_tag_name":"error","recipe_instruction_text":"error","recipe_ingredient_name":"error"},"errorMessage":"Bitte fülle die rot markierten Felder korrekt aus.","db":{"query_count":20}}'
30
    );
31
32
    foreach ($testArray as $before => $after) {
33
      self::assertEquals($after, $this->security->xss_clean($before), 'testing: ' . $before);
34
    }
35
  }
36
37
  public function test_no_xss()
38
  {
39
    $testArray = array(
40
      '<meta name="viewport" content="width=device-width, initial-scale=1.0, minimal-ui">' => '&lt;meta name="viewport" content="width=device-width, initial-scale=1.0, minimal-ui"&gt;',
41
      '<meta property="og:description" content="Lars Moelleken: Webentwickler & Sysadmin aus Krefeld" />' => '&lt;meta property="og:description" content="Lars Moelleken: Webentwickler & Sysadmin aus Krefeld" /&gt;',
42
      '<style type="text/css">html{font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}</style>' => '&lt;style type="text/css"&gt;html{font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}&lt;/style&gt;',
43
      '<nav class="top-bar" data-topbar data-options="back_text: Zurück"><ul><li>foo</li><li>bar</li></ul></nav>' => '<nav class="top-bar" data-topbar data-options="back_text: Zurück"><ul><li>foo</li><li>bar</li></ul></nav>',
44
      '<link href="//fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet" type="text/css"/>' => '&lt;link href="//fonts.googleapis.com/css?family=Open Sans" rel="stylesheet" type="text/css"/&gt;',
45
      '<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>' => '',
46
      '<!--[if lt IE 9]><script src="http://moelleken.org/vendor/bower/nwmatcher/src/nwmatcher.js"></script><![endif]-->' => '&lt;!--[if lt IE 9]><![endif]--&gt;',
47
      '<a href="http://suckup.de/about" target="_blank">About</a>' => '<a href="http://suckup.de/about" target="_blank">About</a>',
48
      "<a href='http://suckup.de/about' target='_blank'>About</a>" => "<a href='http://suckup.de/about' target='_blank'>About</a>",
49
      '<a href="http://moelleken.org/Kontakt/" class="mail"><i class="fa fa-envelope fa-3x"></i></a>' => '<a href="http://moelleken.org/Kontakt/" class="mail"><i class="fa fa-envelope fa-3x"></i></a>',
50
      '<a href="https://plus.google.com/u/0/115714615799970937533/about" rel="me" target="_blank" title="Add Me To Your Circle"><i class="fa fa-google-plus fa-3x"></i></a>' => '<a href="https://plus.google.com/u/0/115714615799970937533/about" rel="me" target="_blank" title="Add Me To Your Circle"><i class="fa fa-google-plus fa-3x"></i></a>',
51
      'eval is evil and xss is bad, but this is only a string : onerror ...' => 'eval is evil and xss is bad, but this is only a string : onerror ...',
52
    );
53
54
    foreach ($testArray as $before => $after) {
55
      self::assertEquals($after, $this->security->xss_clean($before), 'testing: ' . $before);
56
    }
57
  }
58
59
  public function test_xss_clean()
60
  {
61
    $harm_string = "Hello, i try to <script>alert('Hack');</script> your site";
62
63
    $harmless_string = $this->security->xss_clean($harm_string);
64
65
    self::assertEquals("Hello, i try to alert&#40;'Hack'&#41;; your site", $harmless_string);
66
  }
67
68
  public function test_xss_clean_string_array()
69
  {
70
    $harmStrings = array(
71
        "Hello, i try to <script>alert('Hack');</script> your site" => "Hello, i try to [removed]alert&#40;'Hack'&#41;;[removed] your site",
72
        'Simple clean string' => 'Simple clean string',
73
        "Hello, i try to <script>alert('Hack')</script> your site" => "Hello, i try to [removed]alert&#40;'Hack'&#41;[removed] your site",
74
        '<a href="http://test.com?param1="+onMouseOver%3D"alert%281%29%3B&step=2&param12=A">test</a>' => '<a href="http://test.com?param1=">test</a>',
75
        '<a href="http://test.com?param1=lall&colon=foo;">test</a>' => '<a href="http://test.com?param1=lall&colon=foo;">test</a>',
76
        '<a href="http://test.com?param1=lall&colon;=foo;">test</a>' => '<a href="http://test.com?param1=lall:=foo;">test</a>',
77
    );
78
79
    $this->security->setReplacement('[removed]');
80
    foreach ($harmStrings as $before => $after) {
81
      self::assertEquals($after, $this->security->xss_clean($before), 'testing: ' . $before);
82
    }
83
84
    $this->security->setReplacement('');
85
  }
86
87
  public function test_xss_clean_image_valid()
88
  {
89
    $harm_string = '<img src="test.png">';
90
91
    $xss_clean_return = $this->security->xss_clean($harm_string, true);
92
93
    self::assertTrue($xss_clean_return);
94
  }
95
96
  public function test_xss_clean_image_invalid()
97
  {
98
    $harm_string = '<img src=javascript:alert(String.fromCharCode(88,83,83))>';
99
100
    $xss_clean_return = $this->security->xss_clean($harm_string, true);
101
102
    self::assertFalse($xss_clean_return);
103
  }
104
105
  public function test_xss_hash()
106
  {
107
    self::assertTrue(preg_match('#^[0-9a-f]{32}$#iS', $this->security->xss_hash()) === 1);
108
  }
109
110
  public function testXssClean()
111
  {
112
    // \v (vertical whitespace) isn't working on travis-ci ?
113
114
    $testArray = array(
115
      '<div BACKGROUND="mocha:alert(\'XSS\')">
116
        <!-- image:xss -->
117
        <IMG SRC=&#106;&#97;&#118;&#97;&#115;&#99;&#114;&#105;&#112;&#116;&#58;&#97;&#108;&#101;&#114;&#116;&#40;&#39;&#88;&#83;&#83;&#39;&#41;>
118
        <IMG SRC="jav&#x09;ascript:alert(\'XSS\');">
119
        <!-- file:xss -->
120
        <script SRC="http://absynth.de/x.js"></script>
121
        <layer SRC="http://absynth.de/x.js"></layer>
122
        <!-- style:xss -->
123
        <LINK REL="stylesheet" HREF="javascript:alert(\'XSS\');">
124
        <DIV STYLE="background-image: url(javascript:alert(\'XSS\')">
125
          <div style=background-image:expression(alert(\'XSS\'));">lall</div>
126
        </div>
127
      </div>' => '<div BACKGROUND="alert&#40;\'XSS\'&#41;">
128
        &lt;!-- image:xss --&gt;
129
        <IMG >
130
        <>
131
        & SRC="http://absynth.de/x.js">&lt;/layer&gt;
132
        &lt;!-- style:xss --&gt;
133
        &lt;LINK REL="stylesheet" HREF="alert&#40;\'XSS\'&#41;;"&gt;
134
        <DIV =background-image:alert&#40;\'XSS\'&#41;);">lall</div>
135
        </div>
136
      </div>',
137
      '<img/src=">" onerror=alert(1)>
138
      <button/a=">" autofocus onfocus=alert&#40;1&#40;></button>
139
      <button a=">" autofocus onfocus=alert&#40;1&#40;>' => '<img/>" >
140
      <>" ></>
141
      <>" >', // autofocus trick | https://html5sec.org/#7
142
      'http://vulnerable.info/poc/poc.php?foo=%3Csvg%3E%3Cscript%3E/%3C1/%3Ealert(document.domain)%3C/script%3E%3C/svg%3E' => 'http://vulnerable.info/poc/poc.php?foo=&lt;svg&gt;/<1/>alert&#40;document.domain&#41;&lt;/svg&gt;',
143
      '"><svg><script>/<@/>alert(1337)</script>' => '">&lt;svg&gt;/<@/>alert&#40;1337&#41;', // Bypassing Chrome’s Anti-XSS Filter | 2015: http://vulnerable.info/bypassing-chromes-anti-xss-filter/
144
      'Location: https://www.google.com%3a443%2fcse%2ftools%2fcreate_onthefly%3b%3c%2ftextarea%3e%3csvg%2fonload%3dalert%28document%2edomain%29%3e%3b%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f' => 'Location: https://www.google.com:443/cse/tools/create_onthefly;&lt;/textarea&gt;&lt;svg/>;/../../../../../../../../../../../../../../', // Google XSS in IE | 2015: http://blog.bentkowski.info/2015/04/xss-via-host-header-cse.html
145
      '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><feImage> <set attributeName="xlink:href" to="data:image/svg+xml;charset=utf-8;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxzY3JpcHQ%2BYWxlcnQoMSk8L3NjcmlwdD48L3N2Zz4NCg%3D%3D"/></feImage> </svg>' => '&lt;svg :xlink="http://www.w3.org/1999/xlink"&gt;&lt;feImage> <set attributeName="xlink:href" to=PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxzY3JpcHQ+YWxlcnQoMSk8L3NjcmlwdD48L3N2Zz4NCg=="/></feImage> &lt;/svg&gt;', // SVG-XSS | https://html5sec.org/#95
146
      '<a target="_blank" href="data:text/html;BASE64youdummy,PHNjcmlwdD5hbGVydCh3aW5kb3cub3BlbmVyLmRvY3VtZW50LmRvY3VtZW50RWxlbWVudC5pbm5lckhUTUwpPC9zY3JpcHQ+">clickme in firefox</a><a/\'\'\' target="_blank" href=data:text/html;;base64,PHNjcmlwdD5hbGVydChvcGVuZXIuZG9jdW1lbnQuYm9keS5pbm5lckhUTUwpPC9zY3JpcHQ+>firefox11</a>' => '<a target="_blank">clickme in firefox</a><a/\'\'\' target="_blank">firefox11</a>', // data: URI with base64 encoding bypass exploiting Firefox | 2012: https://bugzilla.mozilla.org/show_bug.cgi?id=255107
147
      'http://securitee.tk/files/chrome_xss.php?a=<script>void(\'&b=\');alert(1);</script>' => 'http://securitee.tk/files/chrome_xss.php?a=void(\'&b=\');alert&#40;1&#41;;', // Bypassing Chrome’s Anti-XSS filter | 2012: http://blog.securitee.org/?p=37
148
      'with(document)body.appendChild(createElement(\'iframe onload=&#97&#108&#101&#114&#116(1)>\')),body.innerHTML+=\'\'' => 'with(document)body.appendChild(createElement(\'iframe alert&#40;1&#41;>\')),body =\'\'', // IE11 in IE8 docmode #mxss | https://twitter.com/0x6D6172696F/status/626379000181596160
149
      'http://www.nowvideo.sx/share.php?id=foobar&title=\'\';with(document)body.appendChild(createElement(\\\'iframe onload =&#97&#108&#101&#114&#116(1)>\\\')),body.innerHTML+=\\\'\\\'//\\\';with(document)body.appendChild(createElement(\\\'iframe onload=&#97&#108&#101&#114&#116(1)>\\\')),body.innerHTML+=\\\'\\\'//";with(document)body.appendChild(createElement(\\\'iframe onload=&#97&#108&#101&#114&#116(1)>\\\')),body.innerHTML+=\\\'\\\'//\";with(document)body.appendChild(createElement(\\\'iframe onload=&#97&#108&#101&#114&#116(1)>\\\')),body.innerHTML+=\\\'\\\'//--></SCRIPT>">\'><SCRIPT>with(document)body.appendChild(createElement(\\\'iframe onload=&#97&#108&#101&#114&#116(1)>\\\')),body.innerHTML+=\\\'\\\'</SCRIPT>=&{}' => 'http://www.nowvideo.sx/share.php?id=foobar&title=\'\';with(document)body.appendChild(createElement(\\\'iframe &#97&#108&#101&#114&#116(1)>\\\')),body+=\\\'\\\'//\\\';with(document)body.appendChild(createElement(\\\'iframe &#97&#108&#101&#114&#116(1)>\\\')),body+=\\\'\\\'//";with(document)body.appendChild(createElement(\\\'iframe &#97&#108&#101&#114&#116(1)>\\\')),body+=\\\'\\\'//\";with(document)body.appendChild(createElement(\\\'iframe &#97&#108&#101&#114&#116(1)>\\\')),body+=\\\'\\\'//--&gt;">\'>with(document)body.appendChild(createElement(\\\'iframe alert&#40;1&#41;>\\\')),body =\\\'\\\'=',
150
      '<!DOCTYPE foo [<!ENTITY xxe7eb97 SYSTEM "file:///etc/passwd"> ]>' => '&lt;!DOCTYPE foo [&lt;!ENTITY xxe7eb97 SYSTEM "file:///etc/passwd"> ]>', // XXE injection | http://phpsecurity.readthedocs.org/en/latest/Injection-Attacks.html#xml-injection
151
      '<!DOCTYPE foo [&lt;!ENTITY xxe46471 SYSTEM "http://4mr71zbvk10c5vd1k074izfvbmhnxdi7xw.burpcollaborator.net"> ]>' => '&lt;!DOCTYPE foo [&lt;!ENTITY xxe46471 SYSTEM "http://4mr71zbvk10c5vd1k074izfvbmhnxdi7xw.burpcollaborator.net"> ]>', // XXE injection | 2015: http://blog.portswigger.net/2015/05/burp-suite-now-reports-blind-xxe.html
152
      "<iframe name=alert(1) src=\"//somedomain?x=',__defineSetter__('x',eval),x=name,'\"></iframe>" => '&lt;iframe name=alert&#40;1&#41; src="//somedomain?x=\',__defineSetter__(\'x\',eval),x=name,\'"&gt;&lt;/iframe>',
153
      "<script>x = '',__defineSetter__('x',alert),x=1,'';</script>" => 'x = \'\',__defineSetter__(\'x\',alert),x=1,\'\';', // NoScript XSS filter bypass | 2015: http://blog.portswigger.net/2015/07/noscript-xss-filter-bypass.html
154
      '"><a href="JAVASCRIPT:%E2%80%A8alert`1`">CLICKME' => '"><a href="
alert`1`">CLICKME', // NoScript XSS filter bypass | 2015: https://twitter.com/0x6D6172696F/status/623081477002014720?s=02
155
      '<div id="b" style="font-family:a/**/ression(alert(1))(\'\\\')exp\\\')">aa</div>' => '<div id="b" >aa</div>', // IE | 2014: http://wooyun.org/bugs/wooyun-2014-068564
156
      '<a href="jar:http://SEVER/flash3.bin!/flash3.swf">xss</a>' => '<a href="http://SEVER/flash3.bin!/flash3.swf">xss</a>', // Firefox | 2007: https://bugzilla.mozilla.org/show_bug.cgi?id=369814
157
      '<li><a href="?bypass=%3Clink%20rel=%22import%22%20href=%22?bypass=%3Cscript%3Ealert(document.domain)%3C/script%3E%22%3E">Now click to execute arbitrary JS</a></li>' => '<li><a href="?bypass=link rel=">alert&#40;document.domain&#41;">">Now click to execute arbitrary JS</a></li>', // Chrome 33 | 2015: view-source:https://html5sec.org/test/bypass
158
      '<scr<script>ipt>alert(1)</sc<script>ri<script>pt>' => 'alert&#40;1&#41;', // 2015: https://frederic-hemberger.de/talks/froscon-xss/#/17
159
      '<svg </onload ="1> (_=alert,_(1337)) "">' => '&lt;svg &lt;/> (_=alert,_(1337)) "">',
160
      '<svg><script>/<@/>alert(1)</script>' => '&lt;svg&gt;/<@/>alert&#40;1&#41;',
161
      '<svg/onload=alert`xss`>' => '&lt;svg/&gt;', // FF34+, Edge | 2015 | https://www.davidsopas.com/win-50-amazon-gift-card-with-a-xss-challenge/
162
      '<p/onclick=alert(/xss/)>a' => '<p/>a',
163
      '<iframe/src=//14.rs>' => '&lt;iframe/src=//14.rs&gt;',
164
      '<p/oncut=alert`xss`>x' => '<p/>x',
165
      '<svg/onload=alert(/XSS/)>' => '&lt;svg/&gt;', // FF40 | 2015 | https://www.davidsopas.com/win-50-amazon-gift-card-with-a-xss-challenge/
166
      '<http://onclick%3d1/alert%601%60//' => '<http://', // 2015 | https://twitter.com/brutelogic/status/673098162635202560
167
      'http://www.wolframalpha.com/input/?i=1&n=%22%3E%3Cscript%20src=//3237054390/1%3E' => 'http://www.wolframalpha.com/input/?i=1&n=">', // 2015 | https://twitter.com/brutelogic/status/671740844450426880
168
      '<svg onload=1?alert(9):0>' => '&lt;svg &gt;', // 2015 | https://twitter.com/brutelogic/status/669852435209416704
169
      '<brute contenteditable onblur=alert(1)>lose focus!<brute onclick=alert(1)>click this!<brute oncopy=alert(1)>copy this!<brute oncontextmenu=alert(1)>right click this!<brute oncut=alert(1)>copy this!<brute ondblclick=alert(1)>double click this!<brute ondrag=alert(1)>drag this!<brute contenteditable onfocus=alert(1)>focus this!<brute contenteditable oninput=alert(1)>input here!<brute contenteditable onkeydown=alert(1)>press any key!<brute contenteditable onkeypress=alert(1)>press any key!<brute contenteditable onkeyup=alert(1)>press any key!<brute onmousedown=alert(1)>click this!<brute onmousemove=alert(1)>hover this!<brute onmouseout=alert(1)>hover this!<brute onmouseover=alert(1)>hover this!<brute onmouseup=alert(1)>click this!<brute contenteditable onpaste=alert(1)>paste here!<brute style=font-size:500px onmouseover=alert(1)>0000' => '<brute contenteditable >lose focus!<brute >click this!<brute >copy this!<brute >right click this!<brute >copy this!<brute >double click this!<brute >drag this!<brute contenteditable >focus this!<brute contenteditable >input here!<brute contenteditable >press any key!<brute contenteditable >press any key!<brute contenteditable >press any key!<brute >click this!<brute >hover this!<brute >hover this!<brute >hover this!<brute >click this!<brute contenteditable >paste here!<brute  >0000', // 2015 | http://brutelogic.com.br/blog/agnostic-event-handlers/
170
      '<x contextmenu=">"><acronym%0Cx=""%09oncut+=%09d=document;a=d.createElement("a");a.href="img/hacked1.jpg";a.download="open.me";d.body.appendChild(a);a.click()+><option><input type=submit>' => '<x contextmenu=">"><acronymx=""	 ><option>&lt;input type=submit&gt;', // http://brutelogic.com.br/webgun/
171
      '<h1/onclick=alert(1)>a' => '<h1/>a',
172
      '")}alert(/XSS/);{//' => '")}alert&#40;/XSS/&#41;;{//',
173
      '<svgonload=alert(1)>' => '&lt;svgalert&#40;1&#41;&gt;', // 2015: https://twitter.com/ret2libc/status/635923671681507328
174
      "<style onload='execScript(/**/\"\x61lert&#40 1&#41\",\"j\x61vascript\");'>" => '&lt;style  1)","javascript");\'&gt;', // IE | 2015: https://twitter.com/soaj1664ashar/status/635040931289370624
175
      '<​script>alert `1`</script>' => '&lt; script&gt;alert `1`',
176
      '<form id="test"></form><button form="test" formaction="javascript:alert(1)">X</button>' => '&lt;form id="test"&gt;&lt;/form>&lt;button action="alert&#40;1&#41;"&gt;X&lt;/button&gt;',
177
      '<input onfocus=write(1) autofocus>' => '&lt;input  autofocus&gt;',
178
      '<input onblur=write(1) autofocus><input autofocus>' => '&lt;input  autofocus&gt;&lt;input autofocus>',
179
      '<video poster=javascript:alert(1)//></video>' => '&lt;video poster=alert&#40;1&#41;//&gt;&lt;/video>',
180
      '<body onscroll=alert(1)><br><br><br><br><br><br>...<br><br><br><br><input autofocus>' => '&lt;body &gt;&lt;br><br><br><br><br><br>...<br><br><br><br>&lt;input autofocus&gt;',
181
      '<form id=test onforminput=alert(1)><input></form><button form=test onformchange=alert(2)>X</button>' => '&lt;form id=test &gt;&lt;input>&lt;/form&gt;&lt;button  >X&lt;/button&gt;',
182
      '<video><source onerror="alert(1)">' => '&lt;video&gt;&lt;source >',
183
      '<video onerror="alert(1)"><source></source></video>' => '&lt;video &gt;&lt;source></source>&lt;/video&gt;',
184
      '<form><button formaction="javascript:alert(1)">X</button>' => '&lt;form&gt;&lt;button >X&lt;/button&gt;',
185
      '<body oninput=alert(1)><input autofocus>' => '&lt;body &gt;&lt;input autofocus>',
186
      '<math href="javascript:alert(1)">CLICKME</math>' => '&lt;math href="alert&#40;1&#41;"&gt;CLICKME&lt;/math&gt;',
187
      '<math> <!-- up to FF 13 --> <maction actiontype="statusline#http://google.com" xlink:href="javascript:alert(2)">CLICKME</maction>  <!-- FF 14+ --> <maction actiontype="statusline" xlink:href="javascript:alert(3)">CLICKME<mtext>http://http://google.com</mtext></maction> </math>' => '&lt;math&gt; &lt;!-- up to FF 13 --&gt; <maction actiontype="statusline#http://google.com" ="alert&#40;3&#41;">CLICKME<mtext>http://http://google.com</mtext></maction> &lt;/math&gt;',
188
      '<​img[a][b]src=x[d]onerror[c]=[e]"alert(1)">' => '< img[a][b]src=x[d][e]"alert&#40;1&#41;">',
189
      '<a href="[a]java[b]script[c]:alert(1)">XXX</a>' => '<a >XXX</a>',
190
      '<form action="" method="post"> <input name="username" value="admin" /> <input name="password" type="password" value="secret" /> <input name="injected" value="injected" dirname="password" /> <input type="submit"> </form>' => '&lt;form action="" method="post"&gt; &lt;input name="username" value="admin" /&gt; &lt;input name="password" type="password" value="secret" /&gt; &lt;input name="injected" value="injected" dirname="password" /&gt; &lt;input type="submit"&gt; &lt;/form&gt;',
191
      '<link rel="import" href="test.svg" />' => '&lt;link rel="import" href="test.svg" /&gt;',
192
      '<iframe srcdoc="&lt;img src&equals;x:x onerror&equals;alert&lpar;1&rpar;&gt;" />' => '&lt;iframe srcdoc="&lt;img >" />',
193
      '<picture><source srcset="x"><img onerror="alert(1)"></picture>' => '<picture><source srcset="x"><img ></>',
194
      '<picture><img srcset="x" onerror="alert(1)"></picture>' => '<picture><img srcset="x" ></picture>',
195
      '<img srcset=",,,,,x" onerror="alert(1)">' => '<img srcset=",,,,,x" >',
196
      '<table background="javascript:alert(1)"></table>' => '<table background="alert&#40;1&#41;"></table>',
197
      '<comment><img src="</comment><img src=x onerror=alert(1)//">' => '&lt;comment&gt;< >< >',
198
      '<![><img src="]><img src=x onerror=alert(1)//">' => '<![>< >< >', // up to Opera 11.52, FF 3.6.28
199
      '<svg><![CDATA[><image xlink:href="]]><img src=xx:x onerror=alert(2)//"></svg>' => '&lt;svg&gt;&lt;![CDATA[><image ><img ></>', // IE9+, FF4+, Opera 11.60+, Safari 4.0.4+, GC7+
200
      '<img src onerror /" \'"= alt=alert(1)//">' => '<img >',
201
      '<style><img src="</style><img src=x onerror=alert(1)//">' => '&lt;style&gt;&lt; >< >',
202
      '<head><base href="javascript://"/></head><body><a href="/. /,alert(1)//#">XXX</a></body>' => '&lt;head&gt;&lt;base href="//"/>&lt;/head&gt;&lt;body><a >XXX</a>&lt;/body&gt;',
203
      '<SCRIPT FOR=document EVENT=onreadystatechange>alert(1)</SCRIPT>' => 'alert&#40;1&#41;',
204
      '<OBJECT CLASSID="clsid:333C7BC4-460F-11D0-BC04-0080C7055A83"><PARAM NAME="DataURL" VALUE="javascript:alert(1)"></OBJECT>' => '&lt;OBJECT CLASSID="clsid:333C7BC4-460F-11D0-BC04-0080C7055A83"&gt;&lt;PARAM NAME="DataURL" VALUE="alert&#40;1&#41;">&lt;/OBJECT&gt;',
205
      '<object data="data:text/html;base64,PHNjcmlwdD5hbGVydCgxKTwvc2NyaXB0Pg=="></object>' => '&lt;object data=PHNjcmlwdD5hbGVydCgxKTwvc2NyaXB0Pg=="&gt;&lt;/object>',
206
      '<embed src="data:text/html;base64,PHNjcmlwdD5hbGVydCgxKTwvc2NyaXB0Pg=="></embed>' => '&lt;embed src=PHNjcmlwdD5hbGVydCgxKTwvc2NyaXB0Pg=="&gt;&lt;/embed>',
207
      '<b <script>alert(1)//</script>0</script></b>' => '<b alert&#40;1&#41;//0</b>',
208
      '<// style=x:expression\28write(1)\29>' => '<// >', // IE7
209
      '<style>*{x:expression(write(1))}</style>' => '&lt;style&gt;*{x:expression(write(1))}&lt;/style&gt;', // IE6
210
      '<div style="background:url(test5.svg)">PRESS ENTER</div>' => '<div >PRESS ENTER</div>', // Up to Opera 12.x
211
      '<?xml-stylesheet type="text/css"?><root style="x:expression(write(1))"/>' => '&lt;?xml-stylesheet type="text/css"?&gt;<root >', // IE7
212
      '<?xml-stylesheet type="text/css" href="data:,*%7bx:expression(write(2));%7d"?>' => '&lt;?xml-stylesheet type="text/css" href="data:,*{x:write(2));}"?&gt;', // IE8 -> IE10
213
      '<x xmlns:ev="http://www.w3.org/2001/xml-events" ev:event="load" ev:handler="javascript:alert(1)//#x"/>' => '<x xmlns:ev="http://www.w3.org/2001/xml-events" "load" "alert&#40;1&#41;//#x"/>',
214
      '<iframe sandbox="allow-same-origin allow-forms allow-scripts" src="http://example.org/"></iframe>' => '&lt;iframe sandbox="allow-same-origin allow-forms allow-scripts" src="http://example.org/"&gt;&lt;/iframe>',
215
      '<!-- `<img/src=xx:xx onerror=alert(1)//--!>' => '&lt;!-- `<img/>',
216
      '<title onpropertychange=alert(1)></title><title title=></title>' => '&lt;title &gt;&lt;/title>&lt;title title=&gt;&lt;/title>',
217
      '<​iframe src="data:text/html,&lt;iframe src=\'data:text/html,%26lt;iframe onload=alert(1)&gt;\'&gt;"></iframe>' => '&lt; iframe src="data:text/html,&lt;iframe src=\'data:text/html,&lt;iframe &gt;\'>">&lt;/iframe&gt;',
218
      '<!--<img src="--><​img src=x onerror=alert(1)//">' => '&lt;!--<img >',
219
      '<​frameset onload=alert(1)>' => '&lt; frameset &gt;',
220
      '<​body oninput=alert(1)><​input autofocus>' => '&lt; body &gt;&lt; input autofocus>',
221
      '<​video poster=javascript:alert(1)//></video>' => '&lt; video poster=alert&#40;1&#41;//&gt;&lt;/video>',
222
      '<a style="-o-link:\'javascript:alert(1)\';-o-link-source:current">X</a>' => '<a >X</a>',
223
      '<a href="applescript://com.apple.scripteditor?action=new&script=display%20dialog%20%22Hello%2C%20World%21%22">applescript</a>' => '<a href="//com.apple.scripteditor?action=new&script=display%20dialog%20%22Hello%2C%20World%21%22">applescript</a>',
224
      '<a onmouseover="alert(document.cookie)">xxs</a>' => '<a >xxs</a>',
225
      '<a onmouseover=alert(document.cookie)>xxs</a>' => '<a >xxs</a>',
226
      '<a onerror="alert(document.cookie)">xxs</a>' => '<a >xxs</a>',
227
      '<a onerror=`alert(document.cookie)`>xxs</a>' => '<a >xxs</a>',
228
      '<a href=http://foo.bar STYLE=xss:expression(alert("XSS"))>xxs style</a>' => '<a >xxs style</a>',
229
      '<SCRIPT>alert(\'XSS\');</SCRIPT>' => 'alert&#40;\'XSS\'&#41;;',
230
      '\'\';!--"<XSS>=&{()}' => '\'\';!--"=',
231
      '<SCRIPT SRC=http://ha.ckers.org/xss.js></SCRIPT>' => '',
232
      '<IMG SRC="javascript:alert(\'XSS\');">' => '<IMG >',
233
      '<IMG SRC=javascript:alert(\'XSS\')>' => '<IMG >',
234
      '<IMG SRC=JaVaScRiPt:alert(\'XSS\')>' => '<IMG >',
235
      '<IMG SRC=javascript:alert(&quot;XSS&quot;)>' => '<IMG >',
236
      '<IMG SRC=`javascript:alert("RSnake says, \'XSS\'")`>' => '<IMG >',
237
      '<IMG SRC=javascript:alert(String.fromCharCode(88,83,83))>' => '<IMG >',
238
      'SRC=&#10<IMG 6;&#97;&#118;&#97;&#115;&#99;&#114;&#105;&#112;&#116;&#58;&#97;&#108;&#101;&#114;&#116;&#40;&#39;&#88;&#83;&#83;&#39;&#41;>' => 'SRC=&#10<IMG >',
239
      '<IMG SRC=&#0000106&#0000097&#0000118&#0000097&#0000115&#0000099&#0000114&#0000105&#0000112&#0000116&#0000058&#0000097&#0000108&#0000101&#0000114&#0000116&#0000040&#0000039&#0000088&#0000083&#0000083&#0000039&#0000041>' => '<IMG >',
240
      '<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>' => '<IMG >',
241
      '<IMG SRC="jav	ascript:alert(\'XSS\');">' => '<IMG >',
242
      '<IMG SRC="jav&#x09;ascript:alert(\'XSS\');">' => '<IMG >',
243
      '<IMG SRC="jav&#x0A;ascript:alert(\'XSS\');">' => '<IMG >',
244
      '<IMG SRC=" &#14;  javascript:alert(\'XSS\');">' => '<IMG >',
245
      '<IMG%0aSRC%0a=%0a"%0aj%0aa%0av%0aa%0as%0ac%0ar%0ai%0ap%0at%0a:%0aa%0al%0ae%0ar%0at%0a(%0a\'%0aX%0aS%0aS%0a\'%0a)%0a"%0a>' => "<IMG\nSRC\n=\n\"\n\nalert\n&#40;\n'\nX\nS\nS\n'\n&#41;\n\"\n>",
246
      '<IMG SRC=java%00script:alert(\"XSS\")>' => '<IMG >',
247
      '<SCR%00IPT>alert(\"XSS\")</SCR%00IPT>' => 'alert&#40;\"XSS\"&#41;',
248
      '<SCRIPT/XSS SRC="http://ha.ckers.org/xss.js"></SCRIPT>' => '',
249
      '<SCRIPT SRC=http://ha.ckers.org/xss.js?<B>' => '',
250
      '<IMG SRC="javascript:alert(\'XSS\')"' => '<IMG ',
251
      '<SCRIPT>a=/XSS/' => 'a=/XSS/',
252
      '\";alert(\'XSS\');//' => '\";alert&#40;\'XSS\'&#41;;//',
253
      '<INPUT TYPE="IMAGE" SRC="javascript:alert(\'XSS\');">' => '&lt;INPUT TYPE="IMAGE" SRC="alert&#40;\'XSS\'&#41;;"&gt;',
254
      '<BODY BACKGROUND="javascript:alert(\'XSS\')">' => '&lt;BODY BACKGROUND="alert&#40;\'XSS\'&#41;"&gt;',
255
      '<BODY ONLOAD=alert(\'XSS\')>' => '&lt;BODY &gt;',
256
      '<IMG DYNSRC="javascript:alert(\'XSS\')">' => '<IMG >',
257
      '<IMG LOWSRC="javascript:alert(\'XSS\')">' => '<IMG >',
258
      '<BGSOUND SRC="javascript:alert(\'XSS\');">' => '<IMG >',
259
      '<BR SIZE="&{alert(\'XSS\')}">' => '',
260
      '<DIV STYLE="width:' . "\n" . 'expression(alert(\'XSS\'));">' => '<DIV ' . "\n" . 'alert&#40;\'XSS\'&#41;);">',
261
      '<LAYER SRC="http://ha.ckers.org/scriptlet.html"></LAYER>' => '&lt;LAYER SRC="http://ha.ckers.org/scriptlet.html"&gt;&lt;/LAYER>',
262
      '<LINK REL="stylesheet" HREF="javascript:alert(\'XSS\');">' => '&lt;LINK REL="stylesheet" HREF="http://ha.ckers.org/xss.css"&gt;',
263
      '<LINK REL="stylesheet" HREF="http://ha.ckers.org/xss.css">' => '&lt;LINK REL="stylesheet" HREF="http://ha.ckers.org/xss.css"&gt;',
264
      '<link rel=stylesheet href=data:,*%7bx:expression(write(1))%7d' => '&lt;link rel=stylesheet href=data:,*{x:write(1))}',
265
      '<STYLE>@import\'http://ha.ckers.org/xss.css\';</STYLE>' => '&lt;STYLE&gt;@import\'http://ha.ckers.org/xss.css\';&lt;/STYLE&gt;',
266
      '<style>p[foo=bar{}*{-o-link:\'javascript:alert(1)\'}{}*{-o-link-source:current}*{background:red}]{background:green};</style>' => '&lt;style&gt;p[foo=bar{}*{-o-link:\'alert&#40;1&#41;\'}{}*{-o-link-source:current}*{background:red}]{background:green};&lt;/style&gt;',
267
      '<DIV STYLE="width: expression(alert(\'XSS\'));">lall</div>' => '<DIV  alert&#40;\'XSS\'&#41;);">lall</div>',
268
      '<META HTTP-EQUIV="Link" Content="<http://ha.ckers.org/xss.css>; REL=stylesheet">' => '&lt;META HTTP-EQUIV="Link" Content="&lt;http://ha.ckers.org/xss.css>; REL=stylesheet">',
269
      '<STYLE>BODY{-moz-binding:url("http://ha.ckers.org/xssmoz.xml#xss")}</STYLE>' => '&lt;STYLE&gt;BODY{:url("http://ha.ckers.org/xssmoz.xml#xss")}&lt;/STYLE&gt;',
270
      '<IMG SRC=\'vbscript:msgbox("XSS")\'>' => '<IMG SRC=\'msgbox("XSS")\'>',
271
      '<IMG SRC="mocha:[code]">' => '<IMG SRC="[code]">',
272
      '<IMG SRC="livescript:[code]">' => '<IMG SRC="[code]">',
273
      '<META HTTP-EQUIV="refresh" CONTENT="0;url=javascript:alert(\'XSS\');">' => '&lt;META HTTP-EQUIV="refresh" CONTENT="PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4K"&gt;',
274
      '<META HTTP-EQUIV="refresh" CONTENT="0;url=data:text/html;base64,PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4K">' => '&lt;META HTTP-EQUIV="refresh" CONTENT="PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4K"&gt;',
275
      '<META HTTP-EQUIV="Link" Content="<javascript:alert(\'XSS\')>; REL=stylesheet">' => '&lt;META HTTP-EQUIV="Link" Content="&lt;alert&#40;\'XSS\'&#41;>; REL=stylesheet">',
276
      '<META HTTP-EQUIV="refresh" CONTENT="0; URL=http://;URL=javascript:alert(\'XSS\');">' => '&lt;META HTTP-EQUIV="refresh" CONTENT="0; URL=http://;URL=alert&#40;\'XSS\'&#41;;"&gt;',
277
      '<IFRAME SRC="javascript:alert(\'XSS\');"></IFRAME>' => '&lt;FRAMESET&gt;&lt;FRAME SRC="alert&#40;\'XSS\'&#41;;">&lt;/FRAMESET&gt;',
278
      '<FRAMESET><FRAME SRC="javascript:alert(\'XSS\');"></FRAMESET>' => '&lt;FRAMESET&gt;&lt;FRAME SRC="alert&#40;\'XSS\'&#41;;">&lt;/FRAMESET&gt;',
279
      '<TABLE BACKGROUND="javascript:alert(\'XSS\')">' => '<TABLE BACKGROUND="alert&#40;\'XSS\'&#41;">',
280
      '<DIV STYLE="background-image: url(javascript:alert(\'XSS\'))">' => '<DIV  url(alert&#40;\'XSS\'&#41;)">',
281
      '<DIV STYLE="width: expression(alert(\'XSS\'));">' => '<DIV  alert&#40;\'XSS\'&#41;);">',
282
      '<STYLE>@im\port\'\ja\vasc\ript:alert("XSS")\';</STYLE>' => '&lt;STYLE&gt;@im\port\'\ja\vasc\ript:alert&#40;"XSS"&#41;\';&lt;/STYLE&gt;',
283
      '<IMG STYLE="xss:expr/*XSS*/ession(alert(\'XSS\'))">' => '<IMG >',
284
      '<XSS STYLE="xss:expression(alert(\'XSS\'))">' => '',
285
      'exp/*<XSS STYLE=\'no\xss:noxss("*//*");' => 'exp/*&lt;XSS ',
286
      '<STYLE TYPE="text/javascript">alert(\'XSS\');</STYLE>' => '&lt;STYLE TYPE="text/javascript"&gt;alert&#40;\'XSS\'&#41;;&lt;/STYLE&gt;',
287
      '<STYLE>.XSS{background-image:url("javascript:alert(\'XSS\')");}</STYLE><A CLASS=XSS></A>' => '&lt;STYLE TYPE="text/javascript"&gt;alert&#40;\'XSS\'&#41;;&lt;/STYLE&gt;',
288
      '<STYLE type="text/css">BODY{background:url("javascript:alert(\'XSS\')")}</STYLE>' => '&lt;STYLE type="text/css"&gt;BODY{background:url("alert&#40;\'XSS\'&#41;")}&lt;/STYLE&gt;',
289
      '<BASE HREF="javascript:alert(\'XSS\');//">' => '&lt;BASE HREF="alert&#40;\'XSS\'&#41;;//"&gt;',
290
      '<object allowscriptaccess="always" data="test.swf"></object>' => '&lt;object allowscriptaccess="always" data="test.swf"&gt;&lt;/object>',
291
      '<OBJECT TYPE="text/x-scriptlet" DATA="http://ha.ckers.org/scriptlet.html"></OBJECT>' => '&lt;OBJECT TYPE="text/x-scriptlet" DATA="http://ha.ckers.org/scriptlet.html"&gt;&lt;/OBJECT>',
292
      '<OBJECT classid=clsid:ae24fdae-03c6-11d1-8b76-0080c744f389><param name=url value=javascript:alert(\'XSS\')></OBJECT>' => '&lt;OBJECT classid=clsid:ae24fdae-03c6-11d1-8b76-0080c744f389&gt;&lt;param name=url value=alert&#40;\'XSS\'&#41;>&lt;/OBJECT&gt;',
293
      'getURL("javascript:alert(\'XSS\')")' => 'getURL("alert&#40;\'XSS\'&#41;")',
294
      'a="get";' => 'a="get";',
295
      '<EMBED SRC="http://ha.ckers.Using an EMBED tag you can embed a Flash movie that contains XSS. Click here for a demo. If you add the attributes allowScriptAccess="never" and allownetworking="internal" it can mitigate this risk (thank you to Jonathan Vanasco for the info).:
296
org/xss.swf" AllowScriptAccess="always"></EMBED>' => '&lt;EMBED SRC="http://ha.ckers.Using an EMBED tag you can embed a Flash movie that contains XSS. Click here for a demo. If you add the attributes allowScriptAccess="never" and allownetworking="internal" it can mitigate this risk (thank you to Jonathan Vanasco for the info).:
297
org/xss.swf" AllowScriptAccess="always"&gt;&lt;/EMBED>',
298
      '<EMBED SRC="data:image/svg+xml;base64,PHN2ZyB4bWxuczpzdmc9Imh0dH A6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcv MjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hs aW5rIiB2ZXJzaW9uPSIxLjAiIHg9IjAiIHk9IjAiIHdpZHRoPSIxOTQiIGhlaWdodD0iMjAw IiBpZD0ieHNzIj48c2NyaXB0IHR5cGU9InRleHQvZWNtYXNjcmlwdCI+YWxlcnQoIlh TUyIpOzwvc2NyaXB0Pjwvc3ZnPg==" type="image/svg+xml" AllowScriptAccess="always"></EMBED>' => '&lt;EMBED SRC=PHN2ZyB4bWxuczpzdmc9Imh0dH A6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcv MjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hs aW5rIiB2ZXJzaW9uPSIxLjAiIHg9IjAiIHk9IjAiIHdpZHRoPSIxOTQiIGhlaWdodD0iMjAw IiBpZD0ieHNzIj48c2NyaXB0IHR5cGU9InRleHQvZWNtYXNjcmlwdCI YWxlcnQoIlh TUyIpOzwvc2NyaXB0Pjwvc3ZnPg==" type="image/svg xml" AllowScriptAccess="always"&gt;&lt;/EMBED>',
299
      '<!--<value><![CDATA[<XML ID=I><X><C><![CDATA[<IMG SRC="javas<![CDATA[cript:alert(\'XSS\');">' => '&lt;!--<value>&lt;![CDATA[&lt;XML ID=I&gt;&lt;X><C>&lt;![CDATA[<IMG >',
300
      '<XML SRC="http://ha.ckers.org/xsstest.xml" ID=I></XML>' => '&lt;XML SRC="http://ha.ckers.org/xsstest.xml" ID=I&gt;&lt;/XML>',
301
      '<XML ID="xss"><I><B><IMG SRC="javas<!-- -->cript:alert(\'XSS\')"></B></I></XML>' => '&lt;XML ID="xss"&gt;&lt;I><B><MG ></></>&lt;/XML&gt;',
302
      '<HTML><BODY>' => '&lt;HTML&gt;&lt;BODY>',
303
      '<SCRIPT SRC="http://ha.ckers.org/xss.jpg"></SCRIPT>' => '',
304
      '<!--#exec cmd="/bin/echo \'<SCRIPT SRC\'"--><!--#exec cmd="/bin/echo \'=http://ha.ckers.org/xss.js></SCRIPT>\'"-->' => '&lt;!--#exec cmd="/bin/echo \'\'"--&gt;',
305
      '<? echo(\'<SCR)\';' => '&lt;? echo(\'<SCR)\';',
306
      '<META HTTP-EQUIV="Set-Cookie" Content="USERID=&lt;SCRIPT&gt;alert(\'XSS\')&lt;/SCRIPT&gt;">' => '&lt;META HTTP-EQUIV="Set-Cookie" Content="alert&#40;\'XSS\'&#41;"&gt;',
307
      '<HEAD><META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=UTF-7"> </HEAD>+ADw-SCRIPT+AD4-alert(\'XSS\');+ADw-/SCRIPT+AD4-' => '&lt;HEAD&gt;&lt;META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=UTF-7"> &lt;/HEAD&gt; ADw-SCRIPT AD4-alert&#40;\'XSS\'&#41;; ADw-/SCRIPT AD4-', // UTF-7
308
      '<img src="http://test.de/[0xE0]">
309
      ... foo ...
310
      ... bar ...
311
      " onerror="alert(\'XSS\')"
312
      <div>lall</div>' => '<img src="http://test.de/[0xE0]">
313
      ... foo ...
314
      ... bar ...
315
      " "alert&#40;\'XSS\'&#41;"
316
      <div>lall</div>',
317
      '<script>+-+-1-+-+alert(1)</script>' => ' - -1- - alert&#40;1&#41;',
318
      '<body/onload=&lt;!--&gt;&#10alert(1)>' => "&lt;body/\nalert&#40;1&#41;&gt;",
319
      '<a aa aaa aaaa aaaaa aaaaaa aaaaaaa aaaaaaaa  aaaaaaaaa aaaaaaaaaa  href=j&#97v&#97script&#x3A;&#97lert(1)>ClickMe' => '<a >ClickMe',
320
      '<--`<img/src=` onerror=alert(1)> --!>' => '<--`<img/> --!>',
321
      '<script/src=&#100&#97&#116&#97:text/&#x6a&#x61&#x76&#x61&#x73&#x63&#x72&#x69&#x000070&#x074,&#x0061;&#x06c;&#x0065;&#x00000072;&#x00074;(1)></script> ​' => '  ',
322
      '<meta charset="x-imap4-modified-utf7">&<script&S1&TS&1>alert&A7&(1)&R&UA;&&<&A9&11/script&X&>' => '&lt;meta charset="x-imap4-modified-utf7"&gt;&alert&A7&(1)&R&UA;&&<&A9&11/script&X&>',
323
      '<div id=”3″><meta charset=”x-imap4-modified-utf7″>&<script&S1&TS&1>alert&A7&(1)&R&UA;&&<&A9&11/script&X&>//[“‘`–>]]>]</div>' => '<div id=”3″>&lt;meta charset=”x-imap4-modified-utf7″&gt;&alert&A7&(1)&R&UA;&&<&A9&11/script&X&>//[“‘`–>]]>]</div>',
324
      '<SCRIPT a=">" SRC="http://ha.ckers.org/xss.js"></SCRIPT>' => '" SRC="http://ha.ckers.org/xss.js">',
325
      '<SCRIPT a=">" \'\' SRC="http://ha.ckers.org/xss.js"></SCRIPT>' => '" \'\' SRC="http://ha.ckers.org/xss.js">',
326
      '<SCRIPT "a=\'>\'" SRC="http://ha.ckers.org/xss.js"></SCRIPT>' => '\'" SRC="http://ha.ckers.org/xss.js">',
327
      '<SCRIPT a=`>` SRC="http://ha.ckers.org/xss.js"></SCRIPT>' => '` SRC="http://ha.ckers.org/xss.js">',
328
      'onAttribute="bar"' => '"bar"',
329
      "onAttribute=\"<script>alert('bar')</script>\"" => "\"alert&#40;'bar'&#41;\"",
330
      "<BGSOUND SRC=\"javascript:alert('XSS');\">" => "&lt;BGSOUND SRC=\"alert&#40;'XSS'&#41;;\"&gt;", // BGSOUND
331
      "<BR SIZE=\"&{alert('XSS')}\">" => '<BR SIZE="">', // & JavaScript includes
332
      "<LINK REL=\"stylesheet\" HREF=\"javascript:alert('XSS');\">" => "&lt;LINK REL=\"stylesheet\" HREF=\"alert&#40;'XSS'&#41;;\"&gt;", // STYLE sheet
333
      '<STYLE>BODY{-moz-binding:url("http://ha.ckers.org/xssmoz.xml#xss")}</styel>foo' => '&lt;STYLE&gt;BODY{:url("http://ha.ckers.org/xssmoz.xml#xss")}</styel>foo', // Remote style sheet
334
      "<STYLE>@im\\port'\\jaasc\ript:alert(\"XSS\")';</STYLE>" => "&lt;STYLE&gt;@im\port'\jaasc\ript:alert&#40;\"XSS\"&#41;';&lt;/STYLE&gt;", // STYLE tags with broken up JavaScript for XSS
335
      "<XSS STYLE=\"xss:expression_r(alert('XSS'))\">" => '', // Anonymous HTML with STYLE attribute
336
      '<XSS STYLE="behavior: url(xss.htc);">' => '', // Local htc file
337
      '¼script¾alert(¢XSS¢)¼/script¾' => '¼script¾alert&#40;¢XSS¢&#41;¼/script¾', // US-ASCII encoding
338
      "<IMG defang_SRC=javascript:alert\(&quot;XSS&quot;\)>" => '<IMG >', // IMG
339
      '<IMG SRC=&#106;&#97;&#118;&#97;&#115;&#99;&#114;&#105;&#112;&#116;&#58;&#97;&#108;&#101;&#114;&#116;&#40;&#39;&#88;&#83;&#83;&#39;&#41;>' => '<IMG >',
340
      '<img src =x onerror=confirm(document.cookie);>' => '<img >',
341
      "<IMG SRC=\"jav	ascript:alert('XSS');\">" => '<IMG >',
342
      "<IMG SRC=\"jav&#x09;ascript:alert('XSS');\">" => '<IMG >',
343
      "<IMG SRC=\"jav&#x09;ascript:alert&rpar;'XSS'&rpar;;\">" => '<IMG >',
344
      "<IMG SRC=\"jav&#x0A;ascript:alert('XSS');\">" => '<IMG >',
345
      '<test lall=&amp;amp;#039;jav&#x0A;ascript:alert(\\&amp;amp;#039;XSS\\&amp;amp;#039;);&amp;amp;#039;>' => "<test lall='alert&#40;\'XSS\'&#41;;'>",
346
      "<IMG SRC\n=\n\"\nj\na\nv\n&#x0A;a\ns\nc\nr\ni\np\nt\n:\na\nl\ne\nr\nt\n(\n'\nX\nS\nS\n'\n)\n;\">" => "<IMG SRC\n=\n\"\n\nalert\n&#40;\n'\nX\nS\nS\n'\n&#41;\n;\">",
347
      "<IMG SRC=java�script:alert('XSS')>" => '<IMG >',
348
      "<DIV STYLE=\"background-image:\\0075\\0072\\006C\\0028'\\006a\\0061\\0076\\0061\\0073\\0063\\0072\\0069\\0070\\0074\\003a\\0061\\006c\\0065\\0072\\0074\\0028\\0027\\0058\\0053\\0053\\0027\\0029'\\0029\">" => '<DIV >',
349
      "<STYLE>.XSS{background-image:url(\"javascript:alert('XSS')\");}</STYLE><A CLASS=XSS></A>" => "&lt;STYLE&gt;.XSS{background-image:url(\"alert&#40;'XSS'&#41;\");}&lt;/STYLE&gt;&lt;A ></A>",
350
      "<META HTTP-EQUIV=\"refresh\" CONTENT=\"0;url=javascript:alert('XSS');\">" => "&lt;META HTTP-EQUIV=\"refresh\" CONTENT=\"alert&#40;'XSS'&#41;;\"&gt;", // META
351
      "<IFRAME SRC=\"javascript:alert('XSS');\"></IFRAME>" => "&lt;IFRAME SRC=\"alert&#40;'XSS'&#41;;\"&gt;&lt;/IFRAME>", // IFRAME
352
      '<applet code=A21 width=256 height=256 archive="toir.jar"></applet>' => '&lt;applet code=A21 width=256 height=256 archive="toir.jar"&gt;&lt;/applet>',
353
      '<script Language="JavaScript" event="FSCommand (command, args)" for="theMovie">...</script>' => '...', // <script>
354
      '<SCRIPT>document.write("<SCRI");</SCRIPT>PT SRC="http://ha.ckers.org/xss.js"></SCRIPT>' => '("<SCRI");PT SRC="http://ha.ckers.org/xss.js">', // XSS using HTML quote encapsulation
355
      '<SCR�IPT>alert("XSS")</SCR�IPT>' => 'alert&#40;"XSS"&#41;',
356
      "Би шил идэй чадна,<STYLE>li {list-style-image: url(\"javascript:alert('XSS')\");}</STYLE><UL><LI>我能吞下玻璃而不傷身體</br>" => "Би шил идэй чадна,&lt;STYLE&gt;li {list-style-image: url(\"alert&#40;'XSS'&#41;\");}&lt;/STYLE&gt;&lt;UL><LI>我能吞下玻璃而不傷身體</br>",
357
      "';alert(String.fromCharCode(88,83,83))//';alert(String.fromCharCode(88,83,83))//\"\; alert(String.fromCharCode(88,83,83))//\"\;alert(String.fromCharCode(88,83,83))//--></SCRIPT>\">'><SCRIPT>alert(String.fromCharCode(88,83,83))</SCRIPT>" => "';alert&#40;String.fromCharCode(88,83,83&#41;)//';alert&#40;String.fromCharCode(88,83,83&#41;)//\"\\; alert&#40;String.fromCharCode(88,83,83&#41;)//\"\\;alert&#40;String.fromCharCode(88,83,83&#41;)//--&gt;\">'>alert&#40;String.fromCharCode(88,83,83&#41;)",
358
      'म काँच खान सक्छू र मलाई केहि नी हुन्‍न् <IMG SRC=javascript:alert(String.fromCharCode(88,83,83))>।' => 'म काँच खान सक्छू र मलाई केहि नी हुन्‍न् <IMG >।',
359
      "https://[host]/testing?foo=bar&tab=<script>alert('foobar')</script>" => "https://[host]/testing?foo=bar&tab=alert&#40;'foobar'&#41;",
360
      'https://[host]/diag_logs_filter.phpfilterlogentries_submit=1&filterlogentries_qty=%27%22%3E%3Cscript%3Ealert%28%27ImmuniWeb%27%29;%3C/script%3E' => "https://[host]/diag_logs_filter.phpfilterlogentries_submit=1&filterlogentries_qty='\">alert&#40;'ImmuniWeb'&#41;;", // XSS to attack "pfSense" - https://www.htbridge.com/advisory/HTB23251
361
      'https://[host]/diag_logs_filter.phpfilterlogentries_submit=1&filterlogentries_protocolflags=%27%22%3E%3Cscript%3Ealert%28%27ImmuniWeb%27%29;%3C/script%3E' => "https://[host]/diag_logs_filter.phpfilterlogentries_submit=1&filterlogentries_protocolflags='\">alert&#40;'ImmuniWeb'&#41;;",
362
      'https://[host]/diag_logs_filter.php?filterlogentries_submit=1&filterlogentries_s ourceport=%27%22%3E%3Cscript%3Ealert%28%27ImmuniWeb%27%29;%3C/script%3E' => "https://[host]/diag_logs_filter.php?filterlogentries_submit=1&filterlogentries_s ourceport='\">alert&#40;'ImmuniWeb'&#41;;",
363
      'https://[host]/diag_logs_filter.phpfilterlogentries_submit=1&filterlogentries_destinationport=%27%22%3E%3Cscript%3Ealert%28%27ImmuniWeb%27%29;%3C/script%3E' => "https://[host]/diag_logs_filter.phpfilterlogentries_submit=1&filterlogentries_destinationport='\">alert&#40;'ImmuniWeb'&#41;;",
364
      'https://[host]/diag_logs_filter.phpfilterlogentries_submit=1&filterlogentries_destinationipaddress=%27%22%3E%3Cscript%3Ealert%28%27ImmuniWeb%27%29;%3C/script%3 E' => "https://[host]/diag_logs_filter.phpfilterlogentries_submit=1&filterlogentries_destinationipaddress='\">alert&#40;'ImmuniWeb'&#41;;&lt;/script%3 E",
365
      'https://[host]/diag_logs_filter.phpfilterlogentries_submit=1&filterlogentries_sourceport=%27%22%3E%3Cscript%3Ealert%28%27ImmuniWeb%27%29;%3C/script%3E' => "https://[host]/diag_logs_filter.phpfilterlogentries_submit=1&filterlogentries_sourceport='\">alert&#40;'ImmuniWeb'&#41;;",
366
      'https://[host]/diag_logs_filter.phpfilterlogentries_submit=1&filterlogentries_sourceipaddress=%27%22%3E%3Cscript%3Ealert%28%27ImmuniWeb%27%29;%3C/script%3E' => "https://[host]/diag_logs_filter.phpfilterlogentries_submit=1&filterlogentries_sourceipaddress='\">alert&#40;'ImmuniWeb'&#41;;",
367
      'https://[host]/diag_logs_filter.phpfilterlogentries_submit=1&filterlogentries_time=%27%22%3E%3Cscript%3Ealert%28%27ImmuniWeb%27%29;%3C/script%3E' => "https://[host]/diag_logs_filter.phpfilterlogentries_submit=1&filterlogentries_time='\">alert&#40;'ImmuniWeb'&#41;;",
368
      "http://www.amazon.com/review/R3FSGZJ3NBYZM/?id=brute'-alert('XSSPOSED' )-'logic" => "http://www.amazon.com/review/R3FSGZJ3NBYZM/?id=brute'-alert&#40;'XSSPOSED' &#41;-'logic", // XSS from amazon -> https://www.xssposed.org/search/?search=amazon.com&type=host&
369
      "User-Agent: </script><svg/onload=alert('xssposed')>" => 'User-Agent: &lt;svg/&gt;',
370
      "https://www.amazon.com/gp/aw/ya/181-1583093-7256013/\"></form><script>a lert('Lohit Tummalapenta')</script>" => "https://www.amazon.com/gp/aw/ya/181-1583093-7256013/\">&lt;/form&gt;alert&#40;'Lohit Tummalapenta'&#41;",
371
      "https://aws.amazon.com/amis?ami_provider_id=4&amp;architecture='\"--></ style></script><script>alert(0x015E00)</script>&amp;selection=ami_prov ider_id+architecture" => "https://aws.amazon.com/amis?ami_provider_id=4&amp;architecture='\"--&gt;&lt;/ style&gt;alert&#40;0x015E00&#41;&selection=ami_prov ider_id architecture",
372
      'pipe=ssrProductAds&amp;step=2&amp;userName=1211&amp;replyTo=test%40xssed.com&amp;subjectEscape=&amp;subject=Unable+to+re gister+for+Product+Ads&amp;emailMessageEscape=&amp;emailMessage=&amp;displayName=%27%22%3E%3Ciframe+src%3Dhttp:% 2F%2Fxssed.com%3E&amp;companyURL=&amp;address1=&amp;address2=&amp;city=&amp;state=&amp;zipCode=&amp;country=United+States&amp;ccCard holderName=&amp;ccIssuer=V&amp;addCreditCardNumber=&amp;ccExpMonth=10&amp;ccExpYear=2010&amp;businessAddressCheck=useBus inessAddress&amp;billingAddress1=&amp;billingAddress2=&amp;billingCity=&amp;billingState=&amp;billingZipCode=&amp;billingCou ntry=United+States&amp;Continue=&amp;_pi_legalName=121&amp;_pi_tokenID=A1F3841M9ZHMMV&amp;_pi_pipe=ssrProductAds&amp;_pi _email=kf%40xssed.com&amp;_pi_step=1&amp;_pi_areaCode=112&amp;_pi_phone1=121&amp;_pi_userName=1211&amp;_pi_ext=211221212 1&amp;_pi_phone2=1221' => "pipe=ssrProductAds&step=2&userName=1211&[email protected]&subjectEscape=&subject=Unable to re gister for Product Ads&emailMessageEscape=&emailMessage=&displayName='\">&lt;iframe src=http:% 2F/xssed.com&gt;&companyURL=&address1=&address2=&city=&state=&zipCode=&country=United States&ccCard holderName=&ccIssuer=V&addCreditCardNumber=&ccExpMonth=10&ccExpYear=2010&businessAddressCheck=useBus inessAddress&billingAddress1=&billingAddress2=&billingCity=&billingState=&billingZipCode=&billingCou ntry=United States&Continue=&_pi_legalName=121&_pi_tokenID=A1F3841M9ZHMMV&_pi_pipe=ssrProductAds&_pi [email protected]&_pi_step=1&_pi_areaCode=112&_pi_phone1=121&_pi_userName=1211&_pi_ext=211221212 1&_pi_phone2=1221",
373
      'http://www.amazon.com/s?ie=UTF5&amp;keywords="><script>alert(document. cookie)</script>' => 'http://www.amazon.com/s?ie=UTF5&amp;keywords=">alert&#40;document. cookie&#41;',
374
      'http://www.amazon.com/gp/digital/rich-media/media-player.html?ie=UTF8& amp;location=javascript:alert(1)&amp;ASIN=B000083JTS' => 'http://www.amazon.com/gp/digital/rich-media/media-player.html?ie=UTF8& amp;location=alert&#40;1&#41;&ASIN=B000083JTS',
375
      'http://r-images.amazon.com/s7ondemand/brochure/flash_brochure.jsp?comp any=ama1&amp;sku=AtHome7&amp;windowtitle=XSS&lt;/title&gt;&lt;script/s rc=//z.l.to&gt;&lt;/script&gt;&lt;plaintext&gt;' => 'http://r-images.amazon.com/s7ondemand/brochure/flash_brochure.jsp?comp any=ama1&sku=AtHome7&windowtitle=XSS&lt;/title&gt;&lt;plaintext>',
376
      "https://sellercentral.amazon.com/gp/change-password/change-password-em ail.html?errorMessage=I'm%20sorry,%20the%20Password%20Assistance%20pag e%20is%20temporarily%20unavailable.%20%20Please%20try%20again%20in%201 5%2" => "https://sellercentral.amazon.com/gp/change-password/change-password-em ail.html?errorMessage=I'm sorry, the Password Assistance pag e is temporarily unavailable.  Please try again in 1 5%2",
377
      "http://www.amazon.com/s/ref=amb_link_7189562_72/002-2069697-5560831?ie =UTF8&amp;node=&quot;/&gt;&lt;script&gt;alert('XSS');&lt;/script&gt;&a mp;pct-off=25-&amp;hidden-keywords=athletic|outdoor&amp;pf_rd_m=ATVPDK IKX0DER&amp;pf_rd_s=center-5&amp;pf_r" => "http://www.amazon.com/s/ref=amb_link_7189562_72/002-2069697-5560831?ie =UTF8&node=\"/>alert&#40;'XSS'&#41;;&a mp;pct-off=25-&hidden-keywords=athletic|outdoor&pf_rd_m=ATVPDK IKX0DER&pf_rd_s=center-5&pf_r",
378
      'https://sellercentral.amazon.com/gp/on-board/workflow/Registration/log in.html?passthrough/&amp;passthrough/account=soa"><script>alert("XSS") </script>&amp;passthrough/superSource=OAR&amp;passthrough/marketplaceI D=ATVPDKI' => 'https://sellercentral.amazon.com/gp/on-board/workflow/Registration/log in.html?passthrough/&amp;passthrough/account=soa">alert&#40;"XSS"&#41; &passthrough/superSource=OAR&passthrough/marketplaceI D=ATVPDKI',
379
      'http://sellercentral.amazon.com/gp/seller/product-ads/registration.htm l?ld="><script>alert(document.cookie)</script>' => 'http://sellercentral.amazon.com/gp/seller/product-ads/registration.htm l?ld=">alert&#40;&#41;',
380
      'https://sellercentral.amazon.com/gp/change-password/-"><script>alert(d ocument.cookie)</script>-.html' => 'https://sellercentral.amazon.com/gp/change-password/-">alert&#40;&#41;-.html',
381
      'http://www.amazon.com/script-alert-product-document-cookie/dp/B003H777 5E/ref=sr_1_3?s=gateway&amp;ie=UTF8&amp;qid=1285870078&amp;sr=8-3' => 'http://www.amazon.com/script-alert-product-document-cookie/dp/B003H777 5E/ref=sr_1_3?s=gateway&ie=UTF8&qid=1285870078&sr=8-3',
382
      'http://www.amazon.com/s/ref=sr_a9ps_home/?url=search-alias=aps&amp;tag =amzna9-1-20&amp;field-keywords=-"><script>alert(document.cookie)</scr ipt>' => 'http://www.amazon.com/s/ref=sr_a9ps_home/?url=search-alias=aps&amp;tag =amzna9-1-20&amp;field-keywords=-">alert&#40;&#41;',
383
      'http://www.amazon.com/s/ref=amb_link_7581132_5/102-9803838-3100108?ie= UTF8&amp;node=&quot;/&gt;&lt;script&gt;alert(&quot;XSS&quot;);&lt;/scr ipt&gt;&amp;keywords=Lips&amp;emi=A19ZEOAOKUUP0Q&amp;pf_rd_m=ATVPDKIKX 0DER&amp;pf_rd_s=left-1&amp;pf_rd_r=1JMP7' => 'http://www.amazon.com/s/ref=amb_link_7581132_5/102-9803838-3100108?ie= UTF8&node="/>alert&#40;"XSS"&#41;;&keywords=Lips&emi=A19ZEOAOKUUP0Q&pf_rd_m=ATVPDKIKX 0DER&pf_rd_s=left-1&pf_rd_r=1JMP7',
384
      "http://askville.amazon.com/SearchRequests.do?search=\"></script><script >alert('XSS')</script>&amp;start=0&amp;max=10&amp;open=true&amp;closed =true&amp;x=18&amp;y=7" => "http://askville.amazon.com/SearchRequests.do?search=\">alert&#40;'XSS'&#41;&start=0&max=10&open=true&closed =true&x=18&y=7",
385
      'https://sellercentral.amazon.com/gp/seller/registration/login.html?ie= UTF8&amp;email=&amp;errors=<script src=http://ha.ckers.org/xss.js?/>&amp;userName=&amp;tokenID=AO9UIQIH15 TE' => 'https://sellercentral.amazon.com/gp/seller/registration/login.html?ie= UTF8&amp;email=&amp;errors=&userName=&tokenID=AO9UIQIH15 TE',
386
      'https://sellercentral.amazon.com/gp/seller/registration/login.html?ie= UTF8&amp;email=<script src=http://ha.ckers.org/xss.js?/>&amp;userName=&amp;tokenID=AO9UIQIH15 TE' => 'https://sellercentral.amazon.com/gp/seller/registration/login.html?ie= UTF8&amp;email=&userName=&tokenID=AO9UIQIH15 TE',
387
      'address-daytime-phone=&amp;address-daytime-phone-areacode=%24Q%24%2F%3E&amp;address-daytime-phone-ext=&amp;pipel ine-return-directly=1&amp;pipeline-return-handler=fx-pay-pages%2Fmanage-pay-pages%2F&amp;pipeline-return-han dler-type=post&amp;pipeline-return-html=fx%2Fhelp%2Fgetting-started.html&amp;pipeline-type=payee&amp;register-bi lling-address-id=jgmhpujplj&amp;register-credit-card-id=A1V46DGTZUE15I&amp;register-enter-checking-info=no&amp;r egister-epay-registration-status-check=no&amp;register-nickname=pg5of16&amp;register-payment-program=tipping &amp;input-address-daytime-phone-areacode=%22%2F%3E%3Cscript+src%3Dhttp%3A%2F%2Fha.ckers.org%2Fxss.js%3F %2F%3E&amp;input-address-daytime-phone=&amp;input-address-daytime-phone-ext=&amp;input-register-nickname=xss&amp;inp ut-register-enter-checking-info=no&amp;x=0&amp;y=0' => 'address-daytime-phone=&address-daytime-phone-areacode=$Q$/>&address-daytime-phone-ext=&pipel ine-return-directly=1&pipeline-return-handler=fx-pay-pages/manage-pay-pages/&pipeline-return-han dler-type=post&pipeline-return-html=fx/help/getting-started.html&pipeline-type=payee&register-bi lling-address-id=jgmhpujplj&register-credit-card-id=A1V46DGTZUE15I&register-enter-checking-info=no&r egister-epay-registration-status-check=no&register-nickname=pg5of16&register-payment-program=tipping &input-address-daytime-phone-areacode="/>&input-address-daytime-phone=&input-address-daytime-phone-ext=&input-register-nickname=xss&inp ut-register-enter-checking-info=no&x=0&y=0',
388
      'c=A2H6YBKBHMURHR&amp;t=1&amp;o=4&amp;process_form=1&amp;email_address=%22%2F%3E%3Cscript+src%3Dhttp%3A%2F%2Fha.ckers .org%2Fxss.js%3F%2F%3E&amp;password=&amp;x=0&amp;y=0' => 'c=A2H6YBKBHMURHR&t=1&o=4&process_form=1&email_address="/>&password=&x=0&y=0',
389
      "https://affiliate-program.amazon.com/gp/associates/help/glossary/'>\">< SCRIPT/SRC=http://kusomiso.com/xss.js></SCRIPT>" => "https://affiliate-program.amazon.com/gp/associates/help/glossary/'>\">&lt; SCRIPT/SRC=http://kusomiso.com/xss.js&gt;",
390
      "https://affiliate-program.amazon.com/gp/associates/help/main.html/'>\"> <SCRIPT/SRC=http://kusomiso.com/xss.js></SCRIPT>" => "https://affiliate-program.amazon.com/gp/associates/help/main.html/'>\"> ",
391
      "http://www.amazon.com/gp/daily/ref=\"/><script>alert('XSS $4.99 S&amp;H')</script>" => "http://www.amazon.com/gp/daily/ref=\"/>alert&#40;'XSS $4.99 S&H'&#41;",
392
      'http://bilderdienst.bundestag.de/archives/btgpict/search/_%27-document.write%28String.fromCharCode%2860,105,109,103,32,115,114,99,61,34,104,116,116,112,58,47,47,98,108,111,103,46,102,100,105,107,46,111,114,103,47,50,48,49,51,45,48,54,47,51,56,56,57,50,49,56,55,46,106,112,103,34,32,115,116,121,108,101,61,34,112,97,100,100,105,110,103,58,32,50,53,48,112,120,32,51,51,48,112,120,59,10,112,111,115,105,116,105,111,110,58,32,97,98,115,111,108,117,116,101,59,10,122,45,105,110,100,101,120,58,32,49,48,59,34,62%29%29-%27/' => "http://bilderdienst.bundestag.de/archives/btgpict/search/_'-(String.fromCharCode(60,105,109,103,32,115,114,99,61,34,104,116,116,112,58,47,47,98,108,111,103,46,102,100,105,107,46,111,114,103,47,50,48,49,51,45,48,54,47,51,56,56,57,50,49,56,55,46,106,112,103,34,32,115,116,121,108,101,61,34,112,97,100,100,105,110,103,58,32,50,53,48,112,120,32,51,51,48,112,120,59,10,112,111,115,105,116,105,111,110,58,32,97,98,115,111,108,117,116,101,59,10,122,45,105,110,100,101,120,58,32,49,48,59,34,62))-'/",
393
      'https://bilderdienst.bundestag.de/archives/btgpict/search/_%27-dOcumEnt.wRite%28String.fromCharCode%2860,105,109,103,32,115,114,99,61,34,104,116,116,112,58,47,47,98,108,111,103,46,102,100,105,107,46,111,114,103,47,50,48,49,51,45,48,54,47,51,56,56,57,50,49,56,55,46,106,112,103,34,32,115,116,121,108,101,61,34,112,97,100,100,105,110,103,58,32,50,53,48,112,120,32,51,51,48,112,120,59,10,112,111,115,105,116,105,111,110,58,32,97,98,115,111,108,117,116,101,59,10,122,45,105,110,100,101,120,58,32,49,48,59,34,62%29%29-%27/' => "https://bilderdienst.bundestag.de/archives/btgpict/search/_'-(String.fromCharCode(60,105,109,103,32,115,114,99,61,34,104,116,116,112,58,47,47,98,108,111,103,46,102,100,105,107,46,111,114,103,47,50,48,49,51,45,48,54,47,51,56,56,57,50,49,56,55,46,106,112,103,34,32,115,116,121,108,101,61,34,112,97,100,100,105,110,103,58,32,50,53,48,112,120,32,51,51,48,112,120,59,10,112,111,115,105,116,105,111,110,58,32,97,98,115,111,108,117,116,101,59,10,122,45,105,110,100,101,120,58,32,49,48,59,34,62))-'/",
394
      '<IMG SRC="jav&#x0D;ascript:alert(\'XSS\');">' => '<IMG >',
395
      '<IMG SRC="j a v a s c r i p t:alert(\'XSS\');">' => '<IMG >',
396
      '<IMG SRC="j a v a s c r i p t:alert(\'XSS\');">' => '<IMG >',
397
      '<IMG SRC="j a' . chr(0) . 'v a ' . "\xe2\x82\xa1"  . ' s c r' . "\xf0\x90\x8c\xbc" . 'i p t:alert(\'XSS\');">' => '<IMG >',
398
      '<IMG alt="中文空白" SRC="j a v a ' . "\xe2\x82\xa1"  . ' s c r' . "\xf0\x90\x8c\xbc" . 'i p t:alert(\'XSS\');">' => '<IMG alt="中文空白">',
399
      '<script>prompt(1)</script>' => 'prompt&#40;1&#41;',
400
      '<script>confirm(1)</script>' => 'confirm&#40;1&#41;',
401
      '<script>var fn=window[490837..toString(1<<5)];fn(atob(\'YWxlcnQoMSk=\'));</script>' => 'var fn=window[490837..toString(1<<5)];fn(atob(\'YWxlcnQoMSk=\'));',
402
      '<script>var fn=window[String.fromCharCode(101,118,97,108)];fn(atob(\'YWxlcnQoMSk=\'));</script>' => 'var fn=window[String.fromCharCode(101,118,97,108)];fn(atob(\'YWxlcnQoMSk=\'));',
403
      '<script>var fn=window[atob(\'ZXZhbA==\')];fn(atob(\'YWxlcnQoMSk=\'));</script>' => 'var fn=window[atob(\'ZXZhbA==\')];fn(atob(\'YWxlcnQoMSk=\'));',
404
      '<script>window[490837..toString(1<<5)](atob(\'YWxlcnQoMSk=\'))</script>' => 'window[490837..toString(1<<5)](atob(\'YWxlcnQoMSk=\'))',
405
      '<script>this[490837..toString(1<<5)](atob(\'YWxlcnQoMSk=\'))</script>' => 'this[490837..toString(1<<5)](atob(\'YWxlcnQoMSk=\'))',
406
      '<script>this[(+{}+[])[+!![]]+(![]+[])[!+[]+!![]]+([][+[]]+[])[!+[]+!![]+!![]]+(!![]+[])[+!![]]+(!![]+[])[+[]]](++[[]][+[]])</script>' => 'this[( {} [])[ !![]] (![] [])[! [] !![]] ([][ []] [])[! [] !![] !![]] (!![] [])[ !![]] (!![] [])[ []]](  [[]][ []])',
407
      '<script>this[(+{}+[])[-~[]]+(![]+[])[-~-~[]]+([][+[]]+[])[-~-~-~[]]+(!![]+[])[-~[]]+(!![]+[])[+[]]]((-~[]+[]))</script>' => 'this[( {} [])[-~[]] (![] [])[-~-~[]] ([][ []] [])[-~-~-~[]] (!![] [])[-~[]] (!![] [])[ []]]((-~[] []))',
408
      '<script>\'str1ng\'.replace(/1/,alert)</script>' => '\'str1ng\'.replace(/1/,alert)',
409
      '<script>\'bbbalert(1)cccc\'.replace(/a\w{4}\(\d\)/,eval)</script>' => '\'bbbalert&#40;1&#41;cccc\'.replace(/a\w{4}\(\d\)/,eval)',
410
      '<script>\'a1l2e3r4t6\'.replace(/(.).(.).(.).(.).(.)/, function(match,$1,$2,$3,$4,$5) { this[$1+$2+$3+$4+$5](1); })</script>' => '\'a1l2e3r4t6\'.replace(/(.).(.).(.).(.).(.)/, function(match,$1,$2,$3,$4,$5) { this[$1 $2 $3 $4 $5](1); })',
411
      '<script>eval(\'\\\\u\'+\'0061\'+\'lert(1)\')</script>' => 'eval&#40;\'\\\\u\' \'0061\' \'lert(1&#41;\')',
412
      '<script>throw~delete~typeof~prompt(1)</script>' => 'throw~delete~typeof~prompt&#40;1&#41;',
413
      '<script>delete[a=alert]/prompt a(1)</script>' => 'delete[a=alert]/prompt a(1)',
414
      '<script>delete[a=this[atob(\'YWxlcnQ=\')]]/prompt a(1)</script>' => 'delete[a=this[atob(\'YWxlcnQ=\')]]/prompt a(1)',
415
      '<script>(()=>{return this})().alert(1)</script>' => '(()=>{return this})().alert&#40;1&#41;',
416
      '<script>new function(){new.target.constructor(\'alert(1)\')();}</script>' => 'new function(){new.target.constructor(\'alert&#40;1&#41;\')();}',
417
      '<script>Reflect.construct(function(){new.target.constructor(\'alert(1)\')()},[])</script>' => 'Reflect.construct(function(){new.target.constructor(\'alert&#40;1&#41;\')()},[])',
418
      '<link/rel=prefetch&#10import href=data:q;base64,PHNjcmlwdD5hbGVydCgxKTwvc2NyaXB0Pg>' => "&lt;link/rel=prefetch\nimport href=PHNjcmlwdD5hbGVydCgxKTwvc2NyaXB0Pg&gt;",
419
      '<link rel="import" href="data:x,<script>alert(1)</script>' => '&lt;link rel="import" href="data:x,alert&#40;1&#41;',
420
      '<script>Array.from`1${alert}3${window}2`</script>' => 'Array.from`1${alert}3${window}2`',
421
      '<script>!{x(){alert(1)}}.x()</script>' => '!{x(){alert&#40;1&#41;}}.x()',
422
      '<script>Array.from`${eval}alert\`1\``</script>' => 'Array.from`${eval}alert\`1\``',
423
      '<script>Array.from([1],alert)</script>' => 'Array.from([1],alert)',
424
      '<script>Promise.reject("1").then(null,alert)</script>' => 'Promise.reject("1").then(null,alert)',
425
      '<svg </onload ="1> (_=alert,_(1)) "">' => '&lt;svg &lt;/> (_=alert,_(1)) "">',
426
      '<img onerror="location=\'javascript:=lert(1)\'" src="x">' => '<img  src="x">',
427
      '<img onerror="location=\'javascript:%61lert(1)\'" src="x">' => '<img  src="x">',
428
      '<img onerror="location=\'javascript:\x2561lert(1)\'" src="x">' => '<img  src="x">',
429
      '<img onerror="location=\'javascript:\x255Cu0061lert(1)\'" src="x" >' => '<img  src="x" >',
430
    );
431
432
    foreach ($testArray as $before => $after) {
433
      self::assertEquals($after, $this->security->xss_clean($before), 'testing: ' . $before);
434
    }
435
436
    // test for php < OR > 5.3
437
438
    if (Bootup::is_php('5.4.0') !== true || defined('HHVM_VERSION')) {
439
      $testArray = array(
440
          '<IMG SRC="jav&#x0D;ascript:alert(\'XSS\');">'                                                                            => '<IMG >',
441
          '<DIV STYLE="background-image: url(&#1;javascript:alert(\'XSS\'))">'                                                      => '<DIV  url(alert&#40;\'XSS\'&#41;)">',
442
          'If you like entities... <a href="javascript&colon;&apos;<script src=/&sol;&ETH;.pw&nvgt;</script&nvgt;&apos;">CLICK</a>' => 'If you like entities... <a href="\'script src=//Ð.pw/script\'">CLICK</a>',
443
          // https://twitter.com/0x6D6172696F/status/629754114084175872
444
          '<iframe srcdoc="<svg onload=alert(1)&nvgt;"></iframe>' => '&lt;iframe srcdoc="&lt;svg >&lt;/iframe&gt;',
445
          '<a href="javascript:&apos;<svg onload&equals;alert&lpar;1&rpar;&nvgt;&apos;">CLICK</a>' => '<a >CLICK</a>',
446
      );
447
    } else {
448
      $testArray = array(
449
          '<IMG SRC="jav&#x0D;ascript:alert(\'XSS\');">' => '<IMG >',
450
          '<DIV STYLE="background-image: url(&#1;javascript:alert(\'XSS\'))">' => '<DIV  url(&#1;alert&#40;\'XSS\'&#41;)">',
451
          'If you like entities... <a href="javascript&colon;&apos;<script src=/&sol;&ETH;.pw&nvgt;</script&nvgt;&apos;">CLICK</a>' => 'If you like entities... <a >⃒⃒\'">CLICK</a>', // https://twitter.com/0x6D6172696F/status/629754114084175872
452
          '<iframe srcdoc="<svg onload=alert(1)&nvgt;"></iframe>' => '&lt;iframe srcdoc="&lt;svg >⃒">&lt;/iframe&gt;',
453
          '<a href="javascript:&apos;<svg onload&equals;alert&lpar;1&rpar;&nvgt;&apos;">CLICK</a>' => '<a >⃒\'">CLICK</a>',
454
      );
455
    }
456
457
    for ($i = 0; $i < 5; $i++) {
458
      foreach ($testArray as $before => $after) {
459
        self::assertEquals($after, $this->security->xss_clean($before), 'testing: ' . $before);
460
      }
461
    }
462
  }
463
464 View Code Duplication
  public function testHtmlXssFile()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
465
  {
466
    $testString = UTF8::file_get_contents(__DIR__ . '/xss_v1.html');
467
    $resultString = UTF8::file_get_contents(__DIR__ . '/xss_v1_clean.html');
468
469
    self::assertEquals($resultString, UTF8::html_entity_decode($this->security->xss_clean($testString)), 'testing: ' . $testString);
470
  }
471
472 View Code Duplication
  public function testSvgXssFileV1()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
473
  {
474
    $testString = UTF8::file_get_contents(__DIR__ . '/xss_v1.svg');
475
    $resultString = UTF8::file_get_contents(__DIR__ . '/xss_v1_clean.svg');
476
477
    self::assertEquals($resultString, UTF8::html_entity_decode($this->security->xss_clean($testString)), 'testing: ' . $testString);
478
  }
479
480 View Code Duplication
  public function testSvgXssFileV2()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
481
  {
482
    // PDF-based polyglots through SVG images
483
    //
484
    // http://blog.mindedsecurity.com/2015/08/pdf-based-polyglots-through-svg-images.html
485
486
    $testString = UTF8::file_get_contents(__DIR__ . '/xss_v2.svg');
487
    $resultString = UTF8::file_get_contents(__DIR__ . '/xss_v2_clean.svg');
488
489
    self::assertEquals($resultString, UTF8::html_entity_decode($this->security->xss_clean($testString)), 'testing: ' . $testString);
490
  }
491
492 View Code Duplication
  public function testScriptEncoding()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
493
  {
494
    // https://www.owasp.org/index.php/Testing_for_Cross_site_scripting#Black_Box_testing_and_example
495
496
    $testArray = array(
497
        '<script src=http://www.example.com/malicious-code.js></script>' => '',
498
        '%3cscript src=http://www.example.com/malicious-code.js%3e%3c/script%3e' => '',
499
        "\x3cscript src=http://www.example.com/malicious-code.js\x3e\x3c/script\x3e" => '',
500
        "'`\"><\x3Cscript>javascript:alert(1)</script>'`\"><\x00script>javascript:alert(1)</script>" => "'`\">&lt;alert&#40;1&#41;'`\"&gt;alert&#40;1&#41;",
501
    );
502
503
    foreach ($testArray as $before => $after) {
504
      self::assertEquals($after, $this->security->xss_clean($before), 'testing: ' . $before);
505
    }
506
  }
507
508
  public function testOnError()
509
  {
510
    $testArray = array(
511
        '<img src=1 href=1 onerror="javascript:alert(1)"></img>' => '<  ></>',
512
        '<audio src=1 href=1 onerror="javascript:alert(1)"></audio>' => '&lt;audio src=1 href=1 &gt;&lt;/audio>',
513
        '<video src=1 href=1 onerror="javascript:alert(1)"></video>' => '&lt;video src=1 href=1 &gt;&lt;/video>',
514
        '<body src=1 href=1 onerror="javascript:alert(1)"></body>' => '&lt;body src=1 href=1 &gt;&lt;/body>',
515
        '<image src=1 href=1 onerror="javascript:alert(1)"></image>' => '<image src=1 href=1 ></image>',
516
        '<object src=1 href=1 onerror="javascript:alert(1)"></object>' => '&lt;object src=1 href=1 &gt;&lt;/object>',
517
        '<script src=1 href=1 onerror="javascript:alert(1)"></script>' => '',
518
        '<svg onResize svg onResize="javascript:javascript:alert(1)"></svg onResize>' => '&lt;svg onResize svg &gt;',
519
    );
520
521
    foreach ($testArray as $before => $after) {
522
      self::assertEquals($after, $this->security->xss_clean($before), 'testing: ' . $before);
523
    }
524
  }
525
526 View Code Duplication
  public function testSvgXss()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
527
  {
528
    $testArray = array(
529
      '<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg version="1.1" baseProfile="full" xmlns="http://www.w3.org/2000/svg"><polygon id="triangle" points="0,0 0,50 50,0" fill="#009900" stroke="#004400"/><script type="text/javascript">alert(\'This app is probably vulnerable to XSS attacks!\');</script></svg>' => '&lt;?xml version="1.0" standalone="no"?&gt;&lt;!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">&lt;svg version="1.1" baseProfile="full" &gt;&lt;polygon id="triangle" points="0,0 0,50 50,0" fill="#009900" stroke="#004400"/>alert&#40;\'This app is probably vulnerable to XSS attacks!\'&#41;;&lt;/svg&gt;',
530
      'http://vulnerabledomain.com/xss.php?x=%3Csvg%3E%3Cuse%20height=200%20width=200%20xlink:href=%27http://vulnerabledomain.com/xss.php?x=%3Csvg%20id%3D%22rectangle%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20xmlns%3Axlink%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxlink%22%20%20%20%20width%3D%22100%22%20height%3D%22100%22%3E%3Ca%20xlink%3Ahref%3D%22javascript%3Aalert%28location%29%22%3E%3Crect%20class%3D%22blue%22%20x%3D%220%22%20y%3D%220%22%20width%3D%22100%22%20height%3D%22100%22%20%2F%3E%3C%2Fa%3E%3C%2Fsvg%3E%23rectangle%27/%3E%3C/svg%3E' => 'http://vulnerabledomain.com/xss.php?x=&lt;svg&gt;&lt;use height=200 width=200  id="rectangle" :xlink="http://www.w3.org/1999/xlink"    width="100" height="100"><a ><rect class="blue" x="0" y="0" width="100" height="100" /></a>&lt;/svg&gt;#rectangle\'/>&lt;/svg&gt;',
531
      '<svg id="rectangle" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"width="100" height="100"><a xlink:href="javascript:alert(location)"><rect x="0" y="0" width="100" height="100" /></a></svg>' => '&lt;svg id="rectangle" :xlink="http://www.w3.org/1999/xlink"width="100" height="100"&gt;&lt;a ><rect x="0" y="0" width="100" height="100" /></a>&lt;/svg&gt;',
532
      '<svg><use xlink:href="data:image/svg+xml;base64,PHN2ZyBpZD0icmVjdGFuZ2xlIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiAgICB3aWR0aD0iMTAwIiBoZWlnaHQ9IjEwMCI+PHNjcmlwdD5hbGVydCgxKTwvc2NyaXB0Pg0KIDxmb3JlaWduT2JqZWN0IHdpZHRoPSIxMDAiIGhlaWdodD0iNTAiDQogICAgICAgICAgICAgICAgICAgcmVxdWlyZWRFeHRlbnNpb25zPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hodG1sIj4NCgk8ZW1iZWQgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGh0bWwiIHNyYz0iamF2YXNjcmlwdDphbGVydChsb2NhdGlvbikiIC8+DQogICAgPC9mb3JlaWduT2JqZWN0Pg0KPC9zdmc+#rectangle" /></svg>' => '&lt;svg&gt;&lt;use  PHNjcmlwdD5hbGVydCgxKTwvc2NyaXB0Pg0KIDxmb3JlaWduT2JqZWN0IHdpZHRoPSIxMDAiIGhlaWdodD0iNTAiDQogICAgICAgICAgICAgICAgICAgcmVxdWlyZWRFeHRlbnNpb25zPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hodG1sIj4NCgk8ZW1iZWQgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGh0bWwiIHNyYz0iamF2YXNjcmlwdDphbGVydChsb2NhdGlvbikiIC8 DQogICAgPC9mb3JlaWduT2JqZWN0Pg0KPC9zdmc #rectangle" />&lt;/svg&gt;',
533
      '
534
        <!DOCTYPE html>
535
        <html onAttribute="bar">
536
        <body onload    =load"myFunction()" id="">
537
        
538
        <h1 onload="test" >Hello World!</h1>
539
        
540
        <script>
541
        function myFunction() {
542
            alert("Page is loaded");
543
        }
544
        </script>
545
        
546
        </body>
547
        </html>
548
        ' => '
549
        &lt;!DOCTYPE html>
550
        &lt;html &gt;
551
        &lt;body  id=""&gt;
552
        
553
        <h1  >Hello World!</h1>
554
        
555
        
556
        function myFunction() {
557
            alert&#40;"Page is loaded"&#41;;
558
        }
559
        
560
        
561
        &lt;/body&gt;
562
        &lt;/html&gt;
563
        ',
564
    );
565
566
    foreach ($testArray as $before => $after) {
567
      self::assertEquals($after, $this->security->xss_clean($before), 'testing: ' . $before);
568
    }
569
  }
570
571
  public function testJavaScriptCleaning()
572
  {
573
    // http://cpansearch.perl.org/src/KURIANJA/HTML-Defang-1.02/t/02_xss.t
574
575
    $testArray = array(
576
        '<img FSCommand="someFunction()">',
577
        '<img onAbort="someFunction()">',
578
        '<img onActivate="someFunction()">',
579
        '<img onAfterPrint="someFunction()">',
580
        '<img onAfterUpdate="someFunction()">',
581
        '<img onBeforeActivate="someFunction()">',
582
        '<img onBeforeCopy="someFunction()">',
583
        '<img onBeforeCut="someFunction()">',
584
        '<img onBeforeDeactivate="someFunction()">',
585
        '<img onBeforeEditFocus="someFunction()">',
586
        '<img onBeforePaste="someFunction()">',
587
        '<img onBeforePrint="someFunction()">',
588
        '<img onBeforeUnload="someFunction()">',
589
        '<img onBegin="someFunction()">',
590
        '<img onBlur="someFunction()">',
591
        '<img onBounce="someFunction()">',
592
        '<img onCellChange="someFunction()">',
593
        '<img onChange="someFunction()">',
594
        '<img onClick="someFunction()">',
595
        '<img onContextMenu="someFunction()">',
596
        '<img onControlSelect="someFunction()">',
597
        '<img onCopy="someFunction()">',
598
        '<img onCut="someFunction()">',
599
        '<img onDataAvailable="someFunction()">',
600
        '<img onDataSetChanged="someFunction()">',
601
        '<img onDataSetComplete="someFunction()">',
602
        '<img onDblClick="someFunction()">',
603
        '<img onDeactivate="someFunction()">',
604
        '<img onDrag="someFunction()">',
605
        '<img onDragEnd="someFunction()">',
606
        '<img onDragLeave="someFunction()">',
607
        '<img onDragEnter="someFunction()">',
608
        '<img onDragOver="someFunction()">',
609
        '<img onDragDrop="someFunction()">',
610
        '<img onDrop="someFunction()">',
611
        '<img onEnd="someFunction()">',
612
        '<img onError="someFunction()">',
613
        '<img onErrorUpdate="someFunction()">',
614
        '<img onFilterChange="someFunction()">',
615
        '<img onFinish="someFunction()">',
616
        '<img onFocus="someFunction()">',
617
        '<img onFocusIn="someFunction()">',
618
        '<img onFocusOut="someFunction()">',
619
        '<img onHelp="someFunction()">',
620
        '<img onKeyDown="someFunction()">',
621
        '<img onKeyPress="someFunction()">',
622
        '<img onKeyUp="someFunction()">',
623
        '<img onLayoutComplete="someFunction()">',
624
        '<img onLoad="someFunction()">',
625
        '<img onLoseCapture="someFunction()">',
626
        '<img onMediaComplete="someFunction()">',
627
        '<img onMediaError="someFunction()">',
628
        '<img onMouseDown="someFunction()">',
629
        '<img onMouseEnter="someFunction()">',
630
        '<img onMouseLeave="someFunction()">',
631
        '<img onMouseMove="someFunction()">',
632
        '<img onMouseOut="someFunction()">',
633
        '<img onMouseOver="someFunction()">',
634
        '<img onMouseUp="someFunction()">',
635
        '<img onMouseWheel="someFunction()">',
636
        '<img onMove="someFunction()">',
637
        '<img onMoveEnd="someFunction()">',
638
        '<img onMoveStart="someFunction()">',
639
        '<img onOutOfSync="someFunction()">',
640
        '<img onPaste="someFunction()">',
641
        '<img onPause="someFunction()">',
642
        '<img onProgress="someFunction()">',
643
        '<img onPropertyChange="someFunction()">',
644
        '<img onReadyStateChange="someFunction()">',
645
        '<img onRepeat="someFunction()">',
646
        '<img onReset="someFunction()">',
647
        '<img onResize="someFunction()">',
648
        '<img onResizeEnd="someFunction()">',
649
        '<img onResizeStart="someFunction()">',
650
        '<img onResume="someFunction()">',
651
        '<img onReverse="someFunction()">',
652
        '<img onRowsEnter="someFunction()">',
653
        '<img onRowExit="someFunction()">',
654
        '<img onRowDelete="someFunction()">',
655
        '<img onRowInserted="someFunction()">',
656
        '<img onScroll="someFunction()">',
657
        '<img onSeek="someFunction()">',
658
        '<img onSelect="someFunction()">',
659
        '<img onSelectionChange="someFunction()">',
660
        '<img onSelectStart="someFunction()">',
661
        '<img onStart="someFunction()">',
662
        '<img onStop="someFunction()">',
663
        '<img onSyncRestored="someFunction()">',
664
        '<img onSubmit="someFunction()">',
665
        '<img onTimeError="someFunction()">',
666
        '<img onTrackChange="someFunction()">',
667
        '<img onUnload="someFunction()">',
668
        '<img onURLFlip="someFunction()">',
669
        '<img seekSegmentTime="someFunction()">',
670
    );
671
672
    foreach ($testArray as $test) {
673
      self::assertEquals('<img >', $this->security->xss_clean($test));
674
    }
675
676
    foreach ($testArray as $test) {
677
      self::assertEquals(false, $this->security->xss_clean($test, true));
678
    }
679
680
    $testString = 'http://www.buick.com/encore-luxury-small-crossover/build-your-own.html ?x-zipcode=\';\u006F\u006E\u0065rror=\u0063onfirm;throw\'XSSposed';
681
    $resultString = 'http://www.buick.com/encore-luxury-small-crossover/build-your-own.html ?x-zipcode=\';confirm;throw\'XSSposed';
682
    self::assertEquals($resultString, $this->security->xss_clean($testString));
683
684
    $testString = '<img src="http://moelleken.org/test.png" alt="bar" title="foo">';
685
    self::assertEquals('<img src="http://moelleken.org/test.png" alt="bar" title="foo">', $this->security->xss_clean($testString));
686
687
    $testString = '<img src="http://moelleken.org/test.png" alt="bar" title="foo">';
688
    self::assertEquals(true, $this->security->xss_clean($testString, true));
689
690
    $testString = '<img src="http://moelleken.org/test.png" alt="bar" title="javascript:alert(\'XSS\');">';
691
    self::assertEquals('<img >', $this->security->xss_clean($testString));
692
693
    $testString = '<img src="http://moelleken.org/test.png" alt="bar" title="javascript:alert(\'XSS\');">';
694
    self::assertEquals(false, $this->security->xss_clean($testString, true));
695
696
    $testString = '<img src="<?php echo "http://moelleken.org/test.png" ?>" alt="bar" title="foo">';
697
    self::assertEquals('<img src="&lt;?php echo " alt="bar" title="foo">', $this->security->xss_clean($testString));
698
699
    $testString = '<img src="<?php echo "http://moelleken.org/test.png" ?>" alt="bar" title="foo">';
700
    self::assertEquals(false, $this->security->xss_clean($testString, true));
701
702
    $testString = '<img src="<?php echo "http://moelleken.org/test.png" ?>" alt="bar" title="javascript:alert(\'XSS\');">';
703
    self::assertEquals('<img >', $this->security->xss_clean($testString));
704
705
    $testString = '<img src="<?php echo "http://moelleken.org/test.png" ?>" alt="bar" title="javascript:alert(\'XSS\');">';
706
    self::assertEquals(false, $this->security->xss_clean($testString, true));
707
  }
708
709
  public function test_xss_clean_entity_double_encoded()
710
  {
711
    $testArray = array(
712
        '<IMG SRC=&#0000106&#0000097&#0000118&#0000097&#0000115&#0000099&#0000114&#0000105&#0000112&#0000116&#0000058&#0000097&#0000108&#0000101&#0000114&#0000116&#0000040&#0000039&#0000088&#0000083&#0000083&#0000039&#0000041>' => '<IMG >',
713
        '<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>' => '<IMG >',
714
        "<IMG SRC=\"jav&#x09;ascript:alert('XSS');\">" => '<IMG >',
715
        '<IMG SRC=&#106;&#97;&#118;&#97;&#115;&#99;&#114;&#105;&#112;&#116;&#58;&#97;&#108;&#101;&#114;&#116;&#40;&#39;&#88;&#83;&#83;&#39;&#41;>' => '<IMG >',
716
        '<a href="&#38&#35&#49&#48&#54&#38&#35&#57&#55&#38&#35&#49&#49&#56&#38&#35&#57&#55&#38&#35&#49&#49&#53&#38&#35&#57&#57&#38&#35&#49&#49&#52&#38&#35&#49&#48&#53&#38&#35&#49&#49&#50&#38&#35&#49&#49&#54&#38&#35&#53&#56&#38&#35&#57&#57&#38&#35&#49&#49&#49&#38&#35&#49&#49&#48&#38&#35&#49&#48&#50&#38&#35&#49&#48&#53&#38&#35&#49&#49&#52&#38&#35&#49&#48&#57&#38&#35&#52&#48&#38&#35&#52&#57&#38&#35&#52&#49">Clickhere</a>' => '<a >Clickhere</a>',
717
        '<a href="http://%77%77%77%2E%67%6F%6F%67%6C%65%2E%63%6F%6D">Google</a>' => '<a href="http://www.google.com">Google</a>',
718
    );
719
720
    foreach ($testArray as $before => $after) {
721
      self::assertEquals($after, $this->security->xss_clean($before), $before);
722
    }
723
  }
724
725
  public function test_xss_clean_js_img_removal()
726
  {
727
    $input = '<img src="&#38&#35&#49&#48&#54&#38&#35&#57&#55&#38&#35&#49&#49&#56&#38&#35&#57&#55&#38&#35&#49&#49&#53&#38&#35&#57&#57&#38&#35&#49&#49&#52&#38&#35&#49&#48&#53&#38&#35&#49&#49&#50&#38&#35&#49&#49&#54&#38&#35&#53&#56&#38&#35&#57&#57&#38&#35&#49&#49&#49&#38&#35&#49&#49&#48&#38&#35&#49&#48&#50&#38&#35&#49&#48&#53&#38&#35&#49&#49&#52&#38&#35&#49&#48&#57&#38&#35&#52&#48&#38&#35&#52&#57&#38&#35&#52&#49">Clickhere';
728
    self::assertEquals('<img >', $this->security->xss_clean($input), $input);
729
  }
730
731
  public function test_xss_clean_js_a_removal()
732
  {
733
    $input = '<a src="&#38&#35&#49&#48&#54&#38&#35&#57&#55&#38&#35&#49&#49&#56&#38&#35&#57&#55&#38&#35&#49&#49&#53&#38&#35&#57&#57&#38&#35&#49&#49&#52&#38&#35&#49&#48&#53&#38&#35&#49&#49&#50&#38&#35&#49&#49&#54&#38&#35&#53&#56&#38&#35&#57&#57&#38&#35&#49&#49&#49&#38&#35&#49&#49&#48&#38&#35&#49&#48&#50&#38&#35&#49&#48&#53&#38&#35&#49&#49&#52&#38&#35&#49&#48&#57&#38&#35&#52&#48&#38&#35&#52&#57&#38&#35&#52&#49">Clickhere';
734
    self::assertEquals('<a src="confirm&#40;1&#41;">Clickhere', $this->security->xss_clean($input), $input);
735
  }
736
737
  public function test_xss_clean_js_div_removal()
738
  {
739
    $input = '<div test="&#38&#35&#49&#48&#54&#38&#35&#57&#55&#38&#35&#49&#49&#56&#38&#35&#57&#55&#38&#35&#49&#49&#53&#38&#35&#57&#57&#38&#35&#49&#49&#52&#38&#35&#49&#48&#53&#38&#35&#49&#49&#50&#38&#35&#49&#49&#54&#38&#35&#53&#56&#38&#35&#57&#57&#38&#35&#49&#49&#49&#38&#35&#49&#49&#48&#38&#35&#49&#48&#50&#38&#35&#49&#48&#53&#38&#35&#49&#49&#52&#38&#35&#49&#48&#57&#38&#35&#52&#48&#38&#35&#52&#57&#38&#35&#52&#49">Clickhere';
740
    self::assertEquals('<div test="confirm&#40;1&#41;">Clickhere', $this->security->xss_clean($input), $input);
741
742
    $input = '<div test="&#38&#35&#49&#48&#54&#38&#35&#57&#55&#38&#35&#49&#49&#56&#38&#35&#57&#55&#38&#35&#49&#49&#53&#38&#35&#57&#57&#38&#35&#49&#49&#52&#38&#35&#49&#48&#53&#38&#35&#49&#49&#50&#38&#35&#49&#49&#54&#38&#35&#53&#56&#38&#35&#57&#57&#38&#35&#49&#49&#49&#38&#35&#49&#49&#48&#38&#35&#49&#48&#50&#38&#35&#49&#48&#53&#38&#35&#49&#49&#52&#38&#35&#49&#48&#57&#38&#35&#52&#48&#38&#35&#52&#57&#38&#35&#52&#49">Clickhere</div>';
743
    self::assertEquals('<div test="confirm&#40;1&#41;">Clickhere</div>', $this->security->xss_clean($input), $input);
744
745
    $input = '<div onClick="&#38&#35&#49&#48&#54&#38&#35&#57&#55&#38&#35&#49&#49&#56&#38&#35&#57&#55&#38&#35&#49&#49&#53&#38&#35&#57&#57&#38&#35&#49&#49&#52&#38&#35&#49&#48&#53&#38&#35&#49&#49&#50&#38&#35&#49&#49&#54&#38&#35&#53&#56&#38&#35&#57&#57&#38&#35&#49&#49&#49&#38&#35&#49&#49&#48&#38&#35&#49&#48&#50&#38&#35&#49&#48&#53&#38&#35&#49&#49&#52&#38&#35&#49&#48&#57&#38&#35&#52&#48&#38&#35&#52&#57&#38&#35&#52&#49">Clickhere</div>';
746
    self::assertEquals('<div >Clickhere</div>', $this->security->xss_clean($input), $input);
747
748
    $input = '<div onClick="&#38&#35&#49&#48&#54&#38&#35&#57&#55&#38&#35&#49&#49&#56&#38&#35&#57&#55&#38&#35&#49&#49&#53&#38&#35&#57&#57&#38&#35&#49&#49&#52&#38&#35&#49&#48&#53&#38&#35&#49&#49&#50&#38&#35&#49&#49&#54&#38&#35&#53&#56&#38&#35&#57&#57&#38&#35&#49&#49&#49&#38&#35&#49&#49&#48&#38&#35&#49&#48&#50&#38&#35&#49&#48&#53&#38&#35&#49&#49&#52&#38&#35&#49&#48&#57&#38&#35&#52&#48&#38&#35&#52&#57&#38&#35&#52&#49">Clickhere';
749
    self::assertEquals('<div >Clickhere', $this->security->xss_clean($input), $input);
750
  }
751
752
  public function test_naughty_html_plus_evil_attributes()
753
  {
754
    self::assertEquals('&lt;svg&lt;img > src="x" "location=/javascript/.source /:alert/.source /(1)/.source">', $this->security->xss_clean('<svg<img > src="x" onerror="location=/javascript/.source+/:alert/.source+/(1)/.source">'));
755
  }
756
757
  public function test_xss_clean_sanitize_naughty_html()
758
  {
759
    self::assertEquals('<unclosedTag', $this->security->xss_clean('<unclosedTag'));
760
    self::assertEquals('&lt;blink&gt;', $this->security->xss_clean('<blink>'));
761
    self::assertEquals('<fubar>', $this->security->xss_clean('<fubar>'));
762
    self::assertEquals('<img &svg="" src="x">', $this->security->xss_clean('<img <svg=""> src="x">'));
763
    self::assertEquals('<img src="b =">"x "alert&#40;1&#41;">', $this->security->xss_clean('<img src="b on="<x">on=">"x onerror="alert(1)">'));
764
  }
765
766
  public function test_xss_clean_sanitize_naughty_html_attributes()
767
  {
768
    self::assertEquals('"bar"', $this->security->xss_clean('onAttribute="bar"'));
769
    self::assertEquals('<foo >', $this->security->xss_clean('<foo onAttribute="bar">'));
770
    self::assertEquals('<foo >', $this->security->xss_clean('<foo onAttributeNoQuotes=bar>'));
771
    self::assertEquals('<foo >', $this->security->xss_clean('<foo onAttributeWithSpaces = bar>'));
772
    self::assertEquals('<foo prefix"bar">', $this->security->xss_clean('<foo prefixOnAttribute="bar">'));
773
    self::assertEquals('<foo>onOutsideOfTag=test</foo>', $this->security->xss_clean('<foo>onOutsideOfTag=test</foo>', false));
774
    self::assertEquals('onNoTagAtAll = true', $this->security->xss_clean('onNoTagAtAll = true'));
775
    self::assertEquals('<foo bar=">" baz=\'>\' onAfterGreaterThan="quotes">', $this->security->xss_clean('<foo bar=">" baz=\'>\' onAfterGreaterThan="quotes">'));
776
    self::assertEquals('<foo bar=">" baz=\'>\' onAfterGreaterThan=noQuotes>', $this->security->xss_clean('<foo bar=">" baz=\'>\' onAfterGreaterThan=noQuotes>'));
777
    self::assertEquals('<img src="x">', $this->security->xss_clean('<img src="x" on=""> on=<svg> onerror=alert(1)>', false));
778
    self::assertEquals('<img  >', $this->security->xss_clean('<img src="on=\'">"<svg> onerror=alert(1) onmouseover=alert(1)>'));
779
    self::assertEquals('<img src="x"> on=\'x\' ``,alert&#40;1&#41;>', $this->security->xss_clean('<img src="x"> on=\'x\' onerror=``,alert(1)>'));
780
    self::assertEquals('<img src="x"> on=\'x\' ``,alert&#40;1&#41;>', $this->security->xss_clean('<img src="x"> on=\'x\' ononerror=error=``,alert(1)>'));
781
    self::assertEquals('<a< >', $this->security->xss_clean('<a< onmouseover="alert(1)">'));
782
    self::assertEquals('<img src="x"> on=\'x\' ,xssm()>', $this->security->xss_clean('<img src="x"> on=\'x\' onerror=,xssm()>'));
783
    self::assertEquals('<image src="<>" \'alert&#40;1&#41;\'>', $this->security->xss_clean('<image src="<>" onerror=\'alert(1)\'>'));
784
    self::assertEquals('<b "=<= >', $this->security->xss_clean('<b "=<= onmouseover=alert(1)>'));
785
    self::assertEquals('<b a=<=" >1">', $this->security->xss_clean('<b a=<=" onmouseover="alert(1),1>1">'));
786
    self::assertEquals('<b "="< x=" >', $this->security->xss_clean('<b "="< x=" onmouseover=alert(1)//">'));
787
  }
788
789
  /**
790
   * all tests from drupal
791
   */
792
  public function testXss() {
793
794
    $cases = array(
795
      // Tag stripping, different ways to work around removal of HTML tags.
796
        array(
797
            '<script>alert(0)</script>',
798
            'alert&#40;0&#41;',
799
            'script',
800
            'HTML tag stripping -- simple script without special characters.',
801
        ),
802
        array(
803
            '<script src="http://www.example.com" />',
804
            '',
805
            'script',
806
            'HTML tag stripping -- empty script with source.',
807
        ),
808
        array(
809
            '<ScRipt sRc=http://www.example.com/>',
810
            '',
811
            'script',
812
            'HTML tag stripping evasion -- varying case.',
813
        ),
814
        array(
815
            "<script\nsrc\n=\nhttp://www.example.com/\n>",
816
            '',
817
            'script',
818
            'HTML tag stripping evasion -- multiline tag.',
819
        ),
820
        array(
821
            '<script/a src=http://www.example.com/a.js></script>',
822
            '',
823
            'script',
824
            'HTML tag stripping evasion -- non whitespace character after tag name.',
825
        ),
826
        array(
827
            '<script/src=http://www.example.com/a.js></script>',
828
            '',
829
            'script',
830
            'HTML tag stripping evasion -- no space between tag and attribute.',
831
        ),
832
      // Null between < and tag name works at least with IE6.
833
        array(
834
            "<\0scr\0ipt>alert(0)</script>",
835
            'alert&#40;0&#41;',
836
            'ipt',
837
            'HTML tag stripping evasion -- breaking HTML with nulls.',
838
        ),
839
        array(
840
            '<scrscriptipt src=http://www.example.com/a.js>',
841
            '<scrscriptipt src=http://www.example.com/a.js>',
842
            'script',
843
            'HTML tag stripping evasion -- filter just removing "script".',
844
        ),
845
        array(
846
            '<<script>alert(0);//<</script>',
847
            '&lt;alert&#40;0&#41;;//&lt;',
848
            'script',
849
            'HTML tag stripping evasion -- double opening brackets.',
850
        ),
851
        array(
852
            '<script src=http://www.example.com/a.js?<b>',
853
            '',
854
            'script',
855
            'HTML tag stripping evasion -- no closing tag.',
856
        ),
857
      // DRUPAL-SA-2008-047: This doesn't seem exploitable, but the filter should
858
      // work consistently.
859
        array(
860
            '<script>>',
861
            '>',
862
            'script',
863
            'HTML tag stripping evasion -- double closing tag.',
864
        ),
865
        array(
866
            '<script src=//www.example.com/.a>',
867
            '',
868
            'script',
869
            'HTML tag stripping evasion -- no scheme or ending slash.',
870
        ),
871
        array(
872
            '<script src=http://www.example.com/.a',
873
            '&lt;script src=http://www.example.com/.a',
874
            'script',
875
            'HTML tag stripping evasion -- no closing bracket.',
876
        ),
877
        array(
878
            '<script src=http://www.example.com/ <',
879
            '&lt;script src=http://www.example.com/ &lt;',
880
            'script',
881
            'HTML tag stripping evasion -- opening instead of closing bracket.',
882
        ),
883
        array(
884
            '<nosuchtag attribute="newScriptInjectionVector">',
885
            '<nosuchtag attribute="newScriptInjectionVector">',
886
            'nosuchtag',
887
            'HTML tag stripping evasion -- unknown tag.',
888
        ),
889
        array(
890
            '<t:set attributeName="innerHTML" to="&lt;script defer&gt;alert(0)&lt;/script&gt;">',
891
            '<t:set attributeName="innerHTML" to="alert&#40;0&#41;">',
892
            't:set',
893
            'HTML tag stripping evasion -- colon in the tag name (namespaces\' tricks).',
894
        ),
895
        array(
896
            '<img """><script>alert(0)</script>',
897
            '<img """><>',
898
            'script',
899
            'HTML tag stripping evasion -- a malformed image tag.',
900
            array('img'),
901
        ),
902
        array(
903
            '<blockquote><script>alert(0)</script></blockquote>',
904
            '<blockquote>alert&#40;0&#41;</blockquote>',
905
            'script',
906
            'HTML tag stripping evasion -- script in a blockqoute.',
907
            array('blockquote'),
908
        ),
909
        array(
910
            '<!--[if true]><script>alert(0)</script><![endif]-->',
911
            '&lt;!--[if true]>alert&#40;0&#41;<![endif]--&gt;',
912
            'script',
913
            'HTML tag stripping evasion -- script within a comment.',
914
        ),
915
      // Dangerous attributes removal.
916
        array(
917
            '<p onmouseover="http://www.example.com/">',
918
            '<p >',
919
            'onmouseover',
920
            'HTML filter attributes removal -- events, no evasion.',
921
            array('p'),
922
        ),
923
        array(
924
            '<li style="list-style-image: url(javascript:alert(0))">',
925
            '<li -image: url(alert&#40;0&#41;)">',
926
            'style',
927
            'HTML filter attributes removal -- style, no evasion.',
928
            array('li'),
929
        ),
930
        array(
931
            '<img onerror   =alert(0)>',
932
            '<img >',
933
            'onerror',
934
            'HTML filter attributes removal evasion -- spaces before equals sign.',
935
            array('img'),
936
        ),
937
        array(
938
            '<img onabort!#$%&()*~+-_.,:;?@[/|\]^`=alert(0)>',
939
            '<img >',
940
            'onabort',
941
            'HTML filter attributes removal evasion -- non alphanumeric characters before equals sign.',
942
            array('img'),
943
        ),
944
        array(
945
            '<img oNmediAError=alert(0)>',
946
            '<img >',
947
            'onmediaerror',
948
            'HTML filter attributes removal evasion -- varying case.',
949
            array('img'),
950
        ),
951
      // Works at least with IE6.
952
        array(
953
            "<img o\0nfocus\0=alert(0)>",
954
            '<img >',
955
            'focus',
956
            'HTML filter attributes removal evasion -- breaking with nulls.',
957
            array('img'),
958
        ),
959
      // Only whitelisted scheme names allowed in attributes.
960
        array(
961
            '<img src="javascript:alert(0)">',
962
            '<img >',
963
            'javascript',
964
            'HTML scheme clearing -- no evasion.',
965
            array('img'),
966
        ),
967
        array(
968
            '<img src=javascript:alert(0)>',
969
            '<img >',
970
            'javascript',
971
            'HTML scheme clearing evasion -- no quotes.',
972
            array('img'),
973
        ),
974
      // A bit like CVE-2006-0070.
975
        array(
976
            '<img src="javascript:confirm(0)">',
977
            '<img >',
978
            'javascript',
979
            'HTML scheme clearing evasion -- no alert ;)',
980
            array('img'),
981
        ),
982
        array(
983
            '<img src=`javascript:alert(0)`>',
984
            '<img >',
985
            'javascript',
986
            'HTML scheme clearing evasion -- grave accents.',
987
            array('img'),
988
        ),
989
        array(
990
            '<img dynsrc="javascript:alert(0)">',
991
            '<img >',
992
            'javascript',
993
            'HTML scheme clearing -- rare attribute.',
994
            array('img'),
995
        ),
996
        array(
997
            '<table background="javascript:alert(0)">',
998
            '<table background="alert&#40;0&#41;">',
999
            'javascript',
1000
            'HTML scheme clearing -- another tag.',
1001
            array('table'),
1002
        ),
1003
        array(
1004
            '<base href="javascript:alert(0);//">',
1005
            '&lt;base href="alert&#40;0&#41;;//"&gt;',
1006
            'javascript',
1007
            'HTML scheme clearing -- one more attribute and tag.',
1008
            array('base'),
1009
        ),
1010
        array(
1011
            '<img src="jaVaSCriPt:alert(0)">',
1012
            '<img >',
1013
            'javascript',
1014
            'HTML scheme clearing evasion -- varying case.',
1015
            array('img'),
1016
        ),
1017
        array(
1018
            '<img src=&#106;&#97;&#118;&#97;&#115;&#99;&#114;&#105;&#112;&#116;&#58;&#97;&#108;&#101;&#114;&#116;&#40;&#48;&#41;>',
1019
            '<img >',
1020
            'javascript',
1021
            'HTML scheme clearing evasion -- UTF-8 decimal encoding.',
1022
            array('img'),
1023
        ),
1024
        array(
1025
            '<img src=&#00000106&#0000097&#00000118&#0000097&#00000115&#0000099&#00000114&#00000105&#00000112&#00000116&#0000058&#0000097&#00000108&#00000101&#00000114&#00000116&#0000040&#0000048&#0000041>',
1026
            '<img >',
1027
            'javascript',
1028
            'HTML scheme clearing evasion -- long UTF-8 encoding.',
1029
            array('img'),
1030
        ),
1031
        array(
1032
            '<img src=&#x6A&#x61&#x76&#x61&#x73&#x63&#x72&#x69&#x70&#x74&#x3A&#x61&#x6C&#x65&#x72&#x74&#x28&#x30&#x29>',
1033
            '<img >',
1034
            'javascript',
1035
            'HTML scheme clearing evasion -- UTF-8 hex encoding.',
1036
            array('img'),
1037
        ),
1038
        array(
1039
            "<img src=\"jav\tascript:alert(0)\">",
1040
            '<img >',
1041
            'script',
1042
            'HTML scheme clearing evasion -- an embedded tab.',
1043
            array('img'),
1044
        ),
1045
        array(
1046
            '<img src="jav&#x09;ascript:alert(0)">',
1047
            '<img >',
1048
            'script',
1049
            'HTML scheme clearing evasion -- an encoded, embedded tab.',
1050
            array('img'),
1051
        ),
1052
        array(
1053
            '<img src="jav&#x000000A;ascript:alert(0)">',
1054
            '<img >',
1055
            'script',
1056
            'HTML scheme clearing evasion -- an encoded, embedded newline.',
1057
            array('img'),
1058
        ),
1059
      // With &#xD; this test would fail, but the entity gets turned into
1060
      // &amp;#xD;, so it's OK.
1061
        array(
1062
            '<img src="jav&#x0D;ascript:alert(0)">',
1063
            '<img >',
1064
            'script',
1065
            'HTML scheme clearing evasion -- an encoded, embedded carriage return.',
1066
            array('img'),
1067
        ),
1068
        array(
1069
            "<img src=\"\n\n\nj\na\nva\ns\ncript:alert(0)\">",
1070
            '<img >',
1071
            'cript',
1072
            'HTML scheme clearing evasion -- broken into many lines.',
1073
            array('img'),
1074
        ),
1075
        array(
1076
            "<img src=\"jav\0a\0\0cript:alert(0)\">",
1077
            '<img >',
1078
            'cript',
1079
            'HTML scheme clearing evasion -- embedded nulls.',
1080
            array('img'),
1081
        ),
1082
        array(
1083
            '<img src="vbscript:msgbox(0)">',
1084
            '<img src="msgbox(0)">',
1085
            'vbscript',
1086
            'HTML scheme clearing evasion -- another scheme.',
1087
            array('img'),
1088
        ),
1089
        array(
1090
            '<img src="nosuchscheme:notice(0)">',
1091
            '<img src="nosuchscheme:notice(0)">',
1092
            'nosuchscheme',
1093
            'HTML scheme clearing evasion -- unknown scheme.',
1094
            array('img'),
1095
        ),
1096
      // Netscape 4.x javascript entities.
1097
        array(
1098
            '<br size="&{alert(0)}">',
1099
            '<br size="">',
1100
            'alert',
1101
            'Netscape 4.x javascript entities.',
1102
            array('br'),
1103
        ),
1104
      // DRUPAL-SA-2008-006: Invalid UTF-8, these only work as reflected XSS with
1105
      // Internet Explorer 6.
1106
        array(
1107
            "<p arg=\"\xe0\">\" style=\"background-image: url(j\xe0avas\xc2\xa0cript:alert(0));\"\xe0<p>",
1108
            '<p arg="">" style="background-image: url(alert&#40;0&#41;);"<p>',
1109
            'style',
1110
            'HTML filter -- invalid UTF-8.',
1111
            array('p'),
1112
        ),
1113
        array(
1114
            '<img src=" &#14;  javascript:alert(0)">',
1115
            '<img >',
1116
            'javascript',
1117
            'HTML scheme clearing evasion -- spaces and metacharacters before scheme.',
1118
            array('img'),
1119
        ),
1120
    );
1121
1122
    foreach ($cases as $caseArray) {
1123
      self::assertEquals($caseArray[1], $this->security->xss_clean($caseArray[0]), 'error by: ' . $caseArray[0]);
1124
    }
1125
  }
1126
1127
1128
}
1129