Ejemplo n.º 1
0
        public void AnchorTagContentReplaceXSSTest()
        {
            // Arrange
            HtmlAgilityPackSanitizerProvider target = new HtmlAgilityPackSanitizerProvider();
            Dictionary<string, string[]> elementWhiteList = CreateElementWhiteList();
            Dictionary<string, string[]> attributeWhiteList = CreateAttributeWhiteList();

            // Act
            string htmlFragment = "<A HREF=\"http://www.gohttp://www.google.com/ogle.com/\">XSS</A>";
            string actual = target.GetSafeHtmlFragment(htmlFragment, elementWhiteList);

            // Assert
            string expected = "<A HREF=\"http&#x3A;&#x2F;&#x2F;www&#x2E;gohttp&#x3A;&#x2F;&#x2F;www&#x2E;google&#x2E;com&#x2F;ogle&#x2E;com&#x2F;\">XSS</A>";
            StringAssert.AreEqualIgnoringCase(expected, actual);
        }
Ejemplo n.º 2
0
        public void MakeSureItSanitized()
        {
            var target             = new HtmlAgilityPackSanitizerProvider();
            var elementWhiteList   = CreateElementWhiteList();
            var attributeWhiteList = CreateAttributeWhiteList();

            var htmlFragment = (string)TestContext.DataRow["code"];
            var label        = " ---> " + (string)TestContext.DataRow["label"];
            var actual       = target.GetSafeHtmlFragment(htmlFragment, elementWhiteList, attributeWhiteList);

            if (htmlFragment != "See Below")
            {
                Assert.AreNotEqual(htmlFragment, actual, true, label);
            }
        }
Ejemplo n.º 3
0
        public void ImageXSS2Test()
        {
            // Arrange
            HtmlAgilityPackSanitizerProvider target = new HtmlAgilityPackSanitizerProvider();
            Dictionary<string, string[]> elementWhiteList = CreateElementWhiteList();
            Dictionary<string, string[]> attributeWhiteList = CreateAttributeWhiteList();

            // Act
            string htmlFragment = "<IMG SRC=javascript:alert('XSS')>";
            string actual = target.GetSafeHtmlFragment(htmlFragment, elementWhiteList);

            // Assert
            string expected = "<IMG SRC=\"&#x3A;alert&#x28;&#x26;&#x23;39&#x3B;XSS&#x26;&#x23;39&#x3B;&#x29;\">";
            StringAssert.AreEqualIgnoringCase(expected, actual);
        }
Ejemplo n.º 4
0
        public void AnchorTagNoQuotesXSSTest()
        {
            // Arrange
            HtmlAgilityPackSanitizerProvider target = new HtmlAgilityPackSanitizerProvider();
            Dictionary<string, string[]> elementWhiteList = CreateElementWhiteList();
            Dictionary<string, string[]> attributeWhiteList = CreateAttributeWhiteList();

            // Act
            string htmlFragment = "<A HREF=\"http://www.codeplex.com?url=<SCRIPT>a=/XSS/alert(a.source)</SCRIPT>\">XSS</A>";
            string actual = target.GetSafeHtmlFragment(htmlFragment, elementWhiteList);

            // Assert
            string expected = "<A HREF=\"http&#x3A;&#x2F;&#x2F;www&#x2E;codeplex&#x2E;com&#x3F;url&#x3D;&#x26;lt&#x3B;&#x26;gt&#x3B;a&#x3D;&#x2F;XSS&#x2F;alert&#x28;a&#x2E;source&#x29;&#x26;lt&#x3B;&#x2F;&#x26;gt&#x3B;\">XSS</A>";
            StringAssert.AreEqualIgnoringCase(expected, actual);
        }
Ejemplo n.º 5
0
        public void AnchorTagDownlevelHiddenBlockXSSTest()
        {
            // Arrange
            HtmlAgilityPackSanitizerProvider target = new HtmlAgilityPackSanitizerProvider();
            Dictionary<string, string[]> elementWhiteList = CreateElementWhiteList();
            Dictionary<string, string[]> attributeWhiteList = CreateAttributeWhiteList();

            // Act
            string htmlFragment = "<A HREF=\"http://www.codeplex.com?url=<!--[if gte IE 4]><SCRIPT>alert('XSS');</SCRIPT><![endif]-->\">XSS</A>";
            string actual = target.GetSafeHtmlFragment(htmlFragment, elementWhiteList);

            // Assert
            string expected = "<A HREF=\"http&#x3A;&#x2F;&#x2F;www&#x2E;codeplex&#x2E;com&#x3F;url&#x3D;&#x26;lt&#x3B;&#x21;&#x2D;&#x2D;&#x5B;if&#x20;gte&#x20;IE&#x20;4&#x5D;&#x26;gt&#x3B;&#x26;lt&#x3B;&#x26;gt&#x3B;alert&#x28;&#x26;&#x23;39&#x3B;XSS&#x26;&#x23;39&#x3B;&#x29;&#x3B;&#x26;lt&#x3B;&#x2F;&#x26;gt&#x3B;&#x26;lt&#x3B;&#x21;&#x5B;endif&#x5D;&#x2D;&#x2D;&#x26;gt&#x3B;\">XSS</A>";
            StringAssert.AreEqualIgnoringCase(expected, actual);
        }
Ejemplo n.º 6
0
        public void DivExtraneousOpenBracketsXSSTest()
        {
            // Arrange
            HtmlAgilityPackSanitizerProvider target = new HtmlAgilityPackSanitizerProvider();
            Dictionary<string, string[]> elementWhiteList = CreateElementWhiteList();
            Dictionary<string, string[]> attributeWhiteList = CreateAttributeWhiteList();

            // Act
            string htmlFragment = "<Div style=\"background-color: http://www.codeplex.com?url=<<SCRIPT>alert(\"XSS\");//<</SCRIPT>\">";
            string actual = target.GetSafeHtmlFragment(htmlFragment, elementWhiteList);

            // Assert
            string expected = "<Div style=\"background&#x2D;color&#x3A;&#x20;http&#x3A;&#x2F;&#x2F;www&#x2E;codeplex&#x2E;com&#x3F;url&#x3D;&#x26;lt&#x3B;&#x26;lt&#x3B;&#x26;gt&#x3B;alert&#x28;\"></Div>\">";
            StringAssert.AreEqualIgnoringCase(expected, actual);
        }
Ejemplo n.º 7
0
        public void PWithUrlInStyleXSSTest()
        {
            // Arrange
            HtmlAgilityPackSanitizerProvider target = new HtmlAgilityPackSanitizerProvider();
            Dictionary<string, string[]> elementWhiteList = CreateElementWhiteList();
            Dictionary<string, string[]> attributeWhiteList = CreateAttributeWhiteList();

            // Act
            string htmlFragment = "<p STYLE=\"behavior: url(www.ha.ckers.org);\">";
            string actual = target.GetSafeHtmlFragment(htmlFragment, elementWhiteList);

            // Assert
            // intentionally keep it failing to get notice when reviewing unit tests so can disucss
            string expected = "<p STYLE=\"&#x3A;&#x20;url&#x28;www&#x2E;ha&#x2E;ckers&#x2E;org&#x29;&#x3B;\">";
            StringAssert.AreEqualIgnoringCase(expected, actual);
        }
Ejemplo n.º 8
0
        public void DivBackgroundImageXSSTest()
        {
            // Arrange
            HtmlAgilityPackSanitizerProvider target = new HtmlAgilityPackSanitizerProvider();
            Dictionary<string, string[]> elementWhiteList = CreateElementWhiteList();
            Dictionary<string, string[]> attributeWhiteList = CreateAttributeWhiteList();

            // Act
            string htmlFragment = "<DIV STYLE=\"background-image: url(javascript:alert('XSS'))\">";
            string actual = target.GetSafeHtmlFragment(htmlFragment, elementWhiteList);

            // Assert
            string expected = "<DIV STYLE=\"background&#x2D;image&#x3A;&#x20;url&#x28;&#x3A;alert&#x28;&#x26;&#x23;39&#x3B;XSS&#x26;&#x23;39&#x3B;&#x29;&#x29;\"></div>";
            StringAssert.AreEqualIgnoringCase(expected, actual);
        }
Ejemplo n.º 9
0
        public void XmlWithEmbeddedScriptXSSTest()
        {
            // Arrange
            HtmlAgilityPackSanitizerProvider target = new HtmlAgilityPackSanitizerProvider();
            Dictionary<string, string[]> elementWhiteList = CreateElementWhiteList();
            Dictionary<string, string[]> attributeWhiteList = CreateAttributeWhiteList();

            // Act
            string htmlFragment = "<XML SRC=\"xsstest.xml\" ID=I></XML><SPAN DATASRC=#I DATAFLD=C DATAFORMATAS=HTML></SPAN>";
            string actual = target.GetSafeHtmlFragment(htmlFragment, elementWhiteList);

            // Assert
            string expected = "<SPAN></SPAN>";
            StringAssert.AreEqualIgnoringCase(expected, actual);
        }
Ejemplo n.º 10
0
        public void AnchorTagStyleExpressionXSSTest()
        {
            // Arrange
            HtmlAgilityPackSanitizerProvider target = new HtmlAgilityPackSanitizerProvider();
            Dictionary<string, string[]> elementWhiteList = CreateElementWhiteList();
            Dictionary<string, string[]> attributeWhiteList = CreateAttributeWhiteList();

            // Act
            string htmlFragment = "exp/*<A STYLE='no\\xss:noxss(\"*//*\");xss:&#101;x&#x2F;*XSS*//*/*/pression(alert(\"XSS\"))'>";
            string actual = target.GetSafeHtmlFragment(htmlFragment, elementWhiteList);

            // Assert
            string expected = "exp/*<a></a>";
            StringAssert.AreEqualIgnoringCase(expected, actual);
        }
Ejemplo n.º 11
0
        public void XmlWithCDataXSSTest()
        {
            // Arrange
            HtmlAgilityPackSanitizerProvider target = new HtmlAgilityPackSanitizerProvider();
            Dictionary<string, string[]> elementWhiteList = CreateElementWhiteList();
            Dictionary<string, string[]> attributeWhiteList = CreateAttributeWhiteList();

            // Act
            string htmlFragment = "<XML ID=I><X><C><![CDATA[<IMG SRC=\"javas]]><![CDATA[cript:alert('XSS');\">]]></C></X></xml><SPAN DATASRC=#I DATAFLD=C DATAFORMATAS=HTML></SPAN>";
            string actual = target.GetSafeHtmlFragment(htmlFragment, elementWhiteList);

            // Assert
            string expected = "<SPAN></SPAN>";
            StringAssert.AreEqualIgnoringCase(expected, actual);
        }
Ejemplo n.º 12
0
        public void XmlWithCommentObfuscationXSSTest()
        {
            // Arrange
            HtmlAgilityPackSanitizerProvider target = new HtmlAgilityPackSanitizerProvider();
            Dictionary<string, string[]> elementWhiteList = CreateElementWhiteList();
            Dictionary<string, string[]> attributeWhiteList = CreateAttributeWhiteList();

            // Act
            string htmlFragment = "<XML ID=\"xss\"><I><B>&lt;IMG SRC=\"javas<!-- -->cript:alert('XSS')\"&gt;</B></I></XML><SPAN DATASRC=\"#xss\" DATAFLD=\"B\" DATAFORMATAS=\"HTML\"></SPAN>";
            string actual = target.GetSafeHtmlFragment(htmlFragment, elementWhiteList);

            // Assert
            string expected = "<SPAN></SPAN>";
            StringAssert.AreEqualIgnoringCase(expected, actual);
        }
Ejemplo n.º 13
0
        public void XmlNamespaceXSSTest()
        {
            // Arrange
            HtmlAgilityPackSanitizerProvider target = new HtmlAgilityPackSanitizerProvider();
            Dictionary<string, string[]> elementWhiteList = CreateElementWhiteList();
            Dictionary<string, string[]> attributeWhiteList = CreateAttributeWhiteList();

            // Act
            string htmlFragment = "<HTML xmlns:xss>  <?import namespace=\"xss\" implementation=\"http://ha.ckers.org/xss.htc\">  <xss:xss>XSS</xss:xss></HTML>";
            string actual = target.GetSafeHtmlFragment(htmlFragment, elementWhiteList);

            // Assert
            string expected = "";
            StringAssert.AreEqualIgnoringCase(expected, actual);
        }
Ejemplo n.º 14
0
        public void TDXSSTest()
        {
            // Arrange
            HtmlAgilityPackSanitizerProvider target = new HtmlAgilityPackSanitizerProvider();
            Dictionary<string, string[]> elementWhiteList = CreateElementWhiteList();
            Dictionary<string, string[]> attributeWhiteList = CreateAttributeWhiteList();

            // Act
            string htmlFragment = "<TABLE><TD BACKGROUND=\"javascript:alert('XSS')\">";
            string actual = target.GetSafeHtmlFragment(htmlFragment, elementWhiteList);

            // Assert
            string expected = "";
            StringAssert.AreEqualIgnoringCase(expected, actual);
        }
Ejemplo n.º 15
0
        public void PWithWapExtension()
        {
            // Arrange
            HtmlAgilityPackSanitizerProvider target = new HtmlAgilityPackSanitizerProvider();
            Dictionary<string, string[]> elementWhiteList = CreateElementWhiteList();
            Dictionary<string, string[]> attributeWhiteList = CreateAttributeWhiteList();

            // Act
            string htmlFragment = "<p style=\"display: -wap-marquee; -wap-marquee-dir: ltr\">Hello, welcome to our WCSS Tutorial.</p>";
            string actual = target.GetSafeHtmlFragment(htmlFragment, elementWhiteList);

            // Assert
            string expected = "<p style=\"display&#x3A;&#x20;marquee&#x3B;&#x20;marquee&#x2D;dir&#x3A;&#x20;ltr\">Hello, welcome to our WCSS Tutorial.</p>";
            StringAssert.AreEqualIgnoringCase(expected, actual);
        }
Ejemplo n.º 16
0
        public void AnchorTagOctalEncodingXSSTest()
        {
            // Arrange
            HtmlAgilityPackSanitizerProvider target = new HtmlAgilityPackSanitizerProvider();
            Dictionary<string, string[]> elementWhiteList = CreateElementWhiteList();
            Dictionary<string, string[]> attributeWhiteList = CreateAttributeWhiteList();

            // Act
            string htmlFragment = "<A HREF=\"http://0102.0146.0007.00000223/\">XSS</A>";
            string actual = target.GetSafeHtmlFragment(htmlFragment, elementWhiteList);

            // Assert
            string expected = "<A HREF=\"http&#x3A;&#x2F;&#x2F;0102&#x2E;0146&#x2E;0007&#x2E;00000223&#x2F;\">XSS</A>";
            StringAssert.AreEqualIgnoringCase(expected, actual);
        }
Ejemplo n.º 17
0
        public void AnchorTagUrlEncodingXSSTest()
        {
            // Arrange
            HtmlAgilityPackSanitizerProvider target = new HtmlAgilityPackSanitizerProvider();
            Dictionary<string, string[]> elementWhiteList = CreateElementWhiteList();
            Dictionary<string, string[]> attributeWhiteList = CreateAttributeWhiteList();

            // Act
            string htmlFragment = "<A HREF=\"http://%77%77%77%2E%67%6F%6F%67%6C%65%2E%63%6F%6D\">XSS</A>";
            string actual = target.GetSafeHtmlFragment(htmlFragment, elementWhiteList);

            // Assert
            string expected = "<A HREF=\"http&#x3A;&#x2F;&#x2F;&#x25;77&#x25;77&#x25;77&#x25;2E&#x25;67&#x25;6F&#x25;6F&#x25;67&#x25;6C&#x25;65&#x25;2E&#x25;63&#x25;6F&#x25;6D\">XSS</A>";
            StringAssert.AreEqualIgnoringCase(expected, actual);
        }
Ejemplo n.º 18
0
        public void AnchorTagProtocolResolutionScriptXSSTest()
        {
            // Arrange
            HtmlAgilityPackSanitizerProvider target = new HtmlAgilityPackSanitizerProvider();
            Dictionary<string, string[]> elementWhiteList = CreateElementWhiteList();
            Dictionary<string, string[]> attributeWhiteList = CreateAttributeWhiteList();

            // Act
            string htmlFragment = "<A HREF=\"http://www.codeplex.com?url=<SCRIPT SRC=//ha.ckers.org/.j>\">XSS</A>";
            string actual = target.GetSafeHtmlFragment(htmlFragment, elementWhiteList);

            // Assert
            string expected = "<A HREF=\"http&#x3A;&#x2F;&#x2F;www&#x2E;codeplex&#x2E;com&#x3F;url&#x3D;&#x26;lt&#x3B;SRC&#x3D;&#x2F;&#x2F;ha&#x2E;ckers&#x2E;org&#x2F;&#x2E;j&#x26;gt&#x3B;\">XSS</A>";
            StringAssert.AreEqualIgnoringCase(expected, actual);
        }
Ejemplo n.º 19
0
        public void BRJavascriptIncludeXSSTest()
        {
            // Arrange
            HtmlAgilityPackSanitizerProvider target = new HtmlAgilityPackSanitizerProvider();
            Dictionary<string, string[]> elementWhiteList = CreateElementWhiteList();
            Dictionary<string, string[]> attributeWhiteList = CreateAttributeWhiteList();

            // Act
            string htmlFragment = "<BR SIZE=\"&{alert('XSS')}\">";
            string actual = target.GetSafeHtmlFragment(htmlFragment, elementWhiteList);

            // Assert
            string expected = "<BR>";
            StringAssert.AreEqualIgnoringCase(expected, actual);
        }
Ejemplo n.º 20
0
        public void XSSLocatorTest()
        {
            // Arrange
            HtmlAgilityPackSanitizerProvider target = new HtmlAgilityPackSanitizerProvider();
            Dictionary<string, string[]> elementWhiteList = CreateElementWhiteList();
            Dictionary<string, string[]> attributeWhiteList = CreateAttributeWhiteList();

            // Act
            string htmlFragment = "<a href=\"'';!--\"<XSS>=&{()}\">";
            string actual = target.GetSafeHtmlFragment(htmlFragment, elementWhiteList);

            // Assert
            string expected = "<a href=\"&#x26;&#x23;39&#x3B;&#x26;&#x23;39&#x3B;&#x3B;&#x21;&#x2D;&#x2D;\"></a>";
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 21
0
        public void LinkWithWebKitCSS()
        {
            // Arrange
            HtmlAgilityPackSanitizerProvider target = new HtmlAgilityPackSanitizerProvider();
            Dictionary<string, string[]> elementWhiteList = CreateElementWhiteList();
            Dictionary<string, string[]> attributeWhiteList = CreateAttributeWhiteList();

            // Act
            string htmlFragment = "<link rel=\"stylesheet\" media=\"screen and -webkit-min-device-pixel-ratio: 0\" href=\"webkit.css\">";
            string actual = target.GetSafeHtmlFragment(htmlFragment, elementWhiteList);

            // Assert
            string expected = "<link rel=\"stylesheet\" media=\"screen&#x20;and&#x20;minpixel&#x2D;ratio&#x3A;&#x20;0\" href=\"webkit&#x2E;css\">";
            StringAssert.AreEqualIgnoringCase(expected, actual);
        }
Ejemplo n.º 22
0
        public void AnchorTagUSASCIIEncodingXSSTest()
        {
            // Arrange
            HtmlAgilityPackSanitizerProvider target = new HtmlAgilityPackSanitizerProvider();
            Dictionary<string, string[]> elementWhiteList = CreateElementWhiteList();
            Dictionary<string, string[]> attributeWhiteList = CreateAttributeWhiteList();

            // Act
            string htmlFragment = "<A HREF=\"http://www.codeplex.com?url=¼script¾alert(¢XSS¢)¼/script¾\">XSS</A>";
            string actual = target.GetSafeHtmlFragment(htmlFragment, elementWhiteList);

            // Assert
            string expected = "<A HREF=\"http&#x3A;&#x2F;&#x2F;www&#x2E;codeplex&#x2E;com&#x3F;url&#x3D;&#x26;&#x23;188&#x3B;&#x26;&#x23;190&#x3B;alert&#x28;&#x26;&#x23;162&#x3B;XSS&#x26;&#x23;162&#x3B;&#x29;&#x26;&#x23;188&#x3B;&#x2F;&#x26;&#x23;190&#x3B;\">XSS</A>";
            StringAssert.AreEqualIgnoringCase(expected, actual);
        }
Ejemplo n.º 23
0
        public void AnchorTagHtmlQuotesEncapsulation7XSSTest()
        {
            // Arrange
            HtmlAgilityPackSanitizerProvider target = new HtmlAgilityPackSanitizerProvider();
            Dictionary<string, string[]> elementWhiteList = CreateElementWhiteList();
            Dictionary<string, string[]> attributeWhiteList = CreateAttributeWhiteList();

            // Act
            string htmlFragment = "<A HREF=\"http://www.codeplex.com?url=<SCRIPT>document.write(\"<SCRI\");</SCRIPT>PT SRC=\"http://ha.ckers.org/xss.js\"></SCRIPT>\">XSS</A>";
            string actual = target.GetSafeHtmlFragment(htmlFragment, elementWhiteList);

            // Assert
            string expected = "<A HREF=\"http&#x3A;&#x2F;&#x2F;www&#x2E;codeplex&#x2E;com&#x3F;url&#x3D;&#x26;lt&#x3B;&#x26;gt&#x3B;document&#x2E;write&#x28;\"></a>PT SRC=\"http://ha.ckers.org/xss.js\">\">XSS";
            StringAssert.AreEqualIgnoringCase(expected, actual);
        }
Ejemplo n.º 24
0
        public void DivBackgroundImageWithUnicodedXSSTest()
        {
            // Arrange
            HtmlAgilityPackSanitizerProvider target = new HtmlAgilityPackSanitizerProvider();
            Dictionary<string, string[]> elementWhiteList = CreateElementWhiteList();
            Dictionary<string, string[]> attributeWhiteList = CreateAttributeWhiteList();

            // Act
            string htmlFragment = "<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.1027\0058.1053\0053\0027\0029'\0029\">";
            string actual = target.GetSafeHtmlFragment(htmlFragment, elementWhiteList);

            // Assert
            string expected = "<DIV STYLE=\"background&#x2D;image&#x3A;&#xfffd;075&#xfffd;072&#xfffd;06C&#xfffd;028&#x26;&#x23;39&#x3B;&#xfffd;06a&#xfffd;061&#xfffd;076&#xfffd;061&#xfffd;073&#xfffd;063&#xfffd;072&#xfffd;069&#xfffd;070&#xfffd;074&#xfffd;03a&#xfffd;061&#xfffd;06c&#xfffd;065&#xfffd;072&#xfffd;074&#xfffd;028&#x2E;1027&#xfffd;058&#x2E;1053&#xfffd;053&#xfffd;027&#xfffd;029&#x26;&#x23;39&#x3B;&#xfffd;029\"></div>";
            StringAssert.AreEqualIgnoringCase(expected, actual);
        }
Ejemplo n.º 25
0
        public void AnchorTagIPVersesHostnameXSSTest()
        {
            // Arrange
            HtmlAgilityPackSanitizerProvider target = new HtmlAgilityPackSanitizerProvider();
            Dictionary<string, string[]> elementWhiteList = CreateElementWhiteList();
            Dictionary<string, string[]> attributeWhiteList = CreateAttributeWhiteList();

            // Act
            string htmlFragment = "<A HREF=\"http://66.102.7.147/\">XSS</A>";
            string actual = target.GetSafeHtmlFragment(htmlFragment, elementWhiteList);

            // Assert
            string expected = "<A HREF=\"http&#x3A;&#x2F;&#x2F;66&#x2E;102&#x2E;7&#x2E;147&#x2F;\">XSS</A>";
            StringAssert.AreEqualIgnoringCase(expected, actual);
        }
Ejemplo n.º 26
0
        public void DivDoubleSuspiciousWordHtmlQuotesEncapsulation7XSSTest()
        {
            // Arrange
            HtmlAgilityPackSanitizerProvider target = new HtmlAgilityPackSanitizerProvider();
            Dictionary<string, string[]> elementWhiteList = CreateElementWhiteList();
            Dictionary<string, string[]> attributeWhiteList = CreateAttributeWhiteList();

            // Act
            string htmlFragment = "<Div style=\"background-color: expexpressionression(<SCRIPT>document.write(\"<SCRI\");</SCRIPT>PT SRC=\"http://ha.ckers.org/xss.js\"></SCRIPT>)\">";
            string actual = target.GetSafeHtmlFragment(htmlFragment, elementWhiteList);

            // Assert
            string expected = "<Div style=\"background&#x2D;color&#x3A;&#x28;&#x26;lt&#x3B;&#x26;gt&#x3B;document&#x2E;write&#x28;\"></div>PT SRC=\"http://ha.ckers.org/xss.js\">)\">";
            StringAssert.AreEqualIgnoringCase(expected, actual);
        }
Ejemplo n.º 27
0
        public void AnchorTagJavascriptLinkLocationXSSTest()
        {
            // Arrange
            HtmlAgilityPackSanitizerProvider target = new HtmlAgilityPackSanitizerProvider();
            Dictionary<string, string[]> elementWhiteList = CreateElementWhiteList();
            Dictionary<string, string[]> attributeWhiteList = CreateAttributeWhiteList();

            // Act
            string htmlFragment = "<A HREF=\"javascript:document.location='http://www.google.com/'\">XSS</A>";
            string actual = target.GetSafeHtmlFragment(htmlFragment, elementWhiteList);

            // Assert
            string expected = "<A HREF=\"&#x3A;document&#x2E;location&#x3D;&#x26;&#x23;39&#x3B;http&#x3A;&#x2F;&#x2F;www&#x2E;google&#x2E;com&#x2F;&#x26;&#x23;39&#x3B;\">XSS</A>";
            StringAssert.AreEqualIgnoringCase(expected, actual);
        }
Ejemplo n.º 28
0
        public void DivExpressionXSSTest()
        {
            // Arrange
            HtmlAgilityPackSanitizerProvider target = new HtmlAgilityPackSanitizerProvider();
            Dictionary<string, string[]> elementWhiteList = CreateElementWhiteList();
            Dictionary<string, string[]> attributeWhiteList = CreateAttributeWhiteList();

            // Act
            string htmlFragment = "<DIV STYLE=\"width: expression(alert('XSS'));\">";
            string actual = target.GetSafeHtmlFragment(htmlFragment, elementWhiteList);

            // Assert
            string expected = "<DIV STYLE=\"width&#x3A;&#x28;alert&#x28;&#x26;&#x23;39&#x3B;XSS&#x26;&#x23;39&#x3B;&#x29;&#x29;&#x3B;\"></Div>";
            StringAssert.AreEqualIgnoringCase(expected, actual);
        }
Ejemplo n.º 29
0
        public void AnchorTagMixedEncodingXSSTest()
        {
            // Arrange
            HtmlAgilityPackSanitizerProvider target = new HtmlAgilityPackSanitizerProvider();
            Dictionary<string, string[]> elementWhiteList = CreateElementWhiteList();
            Dictionary<string, string[]> attributeWhiteList = CreateAttributeWhiteList();

            // Act
            string htmlFragment = @"<A HREF=""h
            tt	p://6&#9;6.000146.0x7.147/"">XSS</A>";
            string actual = target.GetSafeHtmlFragment(htmlFragment, elementWhiteList);

            // Assert
            string expected = "<A HREF=\"h&#x0D;&#x0A;tt&#x09;p&#x3A;&#x2F;&#x2F;6&#x26;amp&#x3B;&#x23;9&#x3B;6&#x2E;000146&#x2E;0x7&#x2E;147&#x2F;\">XSS</A>";
            StringAssert.AreEqualIgnoringCase(expected, actual);
        }
Ejemplo n.º 30
0
        public void DivHtmlQuotesEncapsulation5XSSTest()
        {
            // Arrange
            HtmlAgilityPackSanitizerProvider target = new HtmlAgilityPackSanitizerProvider();
            Dictionary<string, string[]> elementWhiteList = CreateElementWhiteList();
            Dictionary<string, string[]> attributeWhiteList = CreateAttributeWhiteList();

            // Act
            string htmlFragment = "<Div style=\"background-color: http://www.codeplex.com?url=<SCRIPT a=`>` SRC=\"http://ha.ckers.org/xss.js\"></SCRIPT>\">";
            string actual = target.GetSafeHtmlFragment(htmlFragment, elementWhiteList);

            // Assert
            string expected = "<Div style=\"background&#x2D;color&#x3A;&#x20;http&#x3A;&#x2F;&#x2F;www&#x2E;codeplex&#x2E;com&#x3F;url&#x3D;&#x26;lt&#x3B;a&#x3D;&#x60;&#x26;gt&#x3B;&#x60;&#x20;SRC&#x3D;\">\"></Div>";
            StringAssert.AreEqualIgnoringCase(expected, actual);
        }
Ejemplo n.º 31
0
        public void AnchorTagNonAlphaNonDigitXSSTest()
        {
            // Arrange
            HtmlAgilityPackSanitizerProvider target = new HtmlAgilityPackSanitizerProvider();
            Dictionary<string, string[]> elementWhiteList = CreateElementWhiteList();
            Dictionary<string, string[]> attributeWhiteList = CreateAttributeWhiteList();

            // Act
            string htmlFragment = "<A HREF=\"http://www.codeplex.com?url=<SCRIPT/XSS SRC=\"http://ha.ckers.org/xss.js\"></SCRIPT>\">XSS</A>";
            string actual = target.GetSafeHtmlFragment(htmlFragment, elementWhiteList);

            // Assert
            string expected = "<A HREF=\"http&#x3A;&#x2F;&#x2F;www&#x2E;codeplex&#x2E;com&#x3F;url&#x3D;&#x26;lt&#x3B;&#x2F;XSS&#x20;SRC&#x3D;\">\">XSS</A>";
            StringAssert.AreEqualIgnoringCase(expected, actual);
        }