format = $this->getMockBuilder('\Drupal\filter\Entity\FilterFormat') ->disableOriginalConstructor() ->getMock(); $this->format->expects($this->any()) ->method('getFilterTypes') ->will($this->returnValue([FilterInterface::TYPE_HTML_RESTRICTOR])); $restrictions = [ 'allowed' => [ 'p' => TRUE, 'a' => TRUE, '*' => [ 'style' => FALSE, 'on*' => FALSE, ], ], ]; $this->format->expects($this->any()) ->method('getHtmlRestrictions') ->will($this->returnValue($restrictions)); } /** * Provides test data for testFilterXss(). * * @see \Drupal\Tests\editor\Unit\editor\EditorXssFilter\StandardTest::testFilterXss() */ public function providerTestFilterXss() { $data = []; $data[] = ['

Hello, world!

Pink Fairy Armadillo', '

Hello, world!

Pink Fairy Armadillo']; $data[] = ['

Hello, world!

Pink Fairy Armadillo', '

Hello, world!

Pink Fairy Armadillo']; $data[] = ['

Hello, world!

Pink Fairy Armadillo', '

Hello, world!

Pink Fairy Armadilloalert("evil");']; $data[] = ['

Hello, world!

Pink Fairy Armadillotest', '

Hello, world!

Pink Fairy Armadillotest']; // All cases listed on https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet // No Filter Evasion. // @see https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet#No_Filter_Evasion $data[] = ['', '']; // Image XSS using the JavaScript directive. // @see https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet#Image_XSS_using_the_JavaScript_directive $data[] = ['', '']; // No quotes and no semicolon. // @see https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet#No_quotes_and_no_semicolon $data[] = ['', '']; // Case insensitive XSS attack vector. // @see https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet#Case_insensitive_XSS_attack_vector $data[] = ['', '']; // HTML entities. // @see https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet#HTML_entities $data[] = ['', '']; // Grave accent obfuscation. // @see https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet#Grave_accent_obfuscation $data[] = ['', '']; // Malformed A tags. // @see https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet#Malformed_A_tags $data[] = ['xxs link', 'xxs link']; $data[] = ['xxs link', 'xxs link']; // Malformed IMG tags. // @see https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet#Malformed_IMG_tags $data[] = ['">', 'alert("XSS")">']; // fromCharCode. // @see https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet#fromCharCode $data[] = ['', '']; // Default SRC tag to get past filters that check SRC domain. // @see https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet#Default_SRC_tag_to_get_past_filters_that_check_SRC_domain $data[] = ['', '']; // Default SRC tag by leaving it empty. // @see https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet#Default_SRC_tag_by_leaving_it_empty $data[] = ['', '']; // Default SRC tag by leaving it out entirely. // @see https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet#Default_SRC_tag_by_leaving_it_out_entirely $data[] = ['', '']; // Decimal HTML character references. // @see https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet#Decimal_HTML_character_references $data[] = ['', '']; // Decimal HTML character references without trailing semicolons. // @see https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet#Decimal_HTML_character_references_without_trailing_semicolons $data[] = ['', '']; // Hexadecimal HTML character references without trailing semicolons. // @see https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet#Hexadecimal_HTML_character_references_without_trailing_semicolons $data[] = ['', '']; // Embedded tab. // @see https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet#Embedded_tab $data[] = ['', '']; // Embedded Encoded tab. // @see https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet#Embedded_Encoded_tab $data[] = ['', '']; // Embedded newline to break up XSS. // @see https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet#Embedded_newline_to_break_up_XSS $data[] = ['', '']; // Embedded carriage return to break up XSS. // @see https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet#Embedded_carriage_return_to_break_up_XSS $data[] = ['', '']; // Null breaks up JavaScript directive. // @see https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet#Null_breaks_up_JavaScript_directive $data[] = ["", '']; // Spaces and meta chars before the JavaScript in images for XSS. // @see https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet#Spaces_and_meta_chars_before_the_JavaScript_in_images_for_XSS // @fixme This dataset currently fails under 5.4 because of // https://www.drupal.org/node/1210798. Restore after it's fixed. if (version_compare(PHP_VERSION, '5.4.0', '<')) { $data[] = ['', '']; } // Non-alpha-non-digit XSS. // @see https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet#Non-alpha-non-digit_XSS $data[] = ['', '']; $data[] = ['', '']; $data[] = ['', '']; // Extraneous open brackets. // @see https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet#Extraneous_open_brackets $data[] = ['<', '<alert("XSS");//<']; // No closing script tags. // @see https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet#No_closing_script_tags $data[] = ['', 'alert("XSS");']; // INPUT image. // @see https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet#INPUT_image $data[] = ['', '']; // BODY image. // @see https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet#BODY_image $data[] = ['', '']; // IMG Dynsrc. // @see https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet#IMG_Dynsrc $data[] = ['', '']; // IMG lowsrc. // @see https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet#IMG_lowsrc $data[] = ['', '']; // List-style-image. // @see https://www.owasp.org/index.php/XSS_Filter_Evasion_Cheat_Sheet#List-style-image $data[] = ['