Title: [108551] trunk
Revision
108551
Author
[email protected]
Date
2012-02-22 14:21:14 -0800 (Wed, 22 Feb 2012)

Log Message

XSSAuditor bypass with <svg> tags and html-entities.
https://bugs.webkit.org/show_bug.cgi?id=78836

Reviewed by Adam Barth.

Source/WebCore:

Tests: http/tests/security/xssAuditor/iframe-onload-in-svg-tag.html
       http/tests/security/xssAuditor/script-tag-inside-svg-tag.html
       http/tests/security/xssAuditor/script-tag-inside-svg-tag2.html
       http/tests/security/xssAuditor/script-tag-inside-svg-tag3.html

* html/parser/XSSAuditor.cpp:
(WebCore::isNonCanonicalCharacter):
(WebCore::isTerminatingCharacter):
(WebCore):
(WebCore::startsHTMLCommentAt):
(WebCore::startsSingleLineCommentAt):
(WebCore::fullyDecodeString):
(WebCore::XSSAuditor::XSSAuditor):
(WebCore::XSSAuditor::init):
(WebCore::XSSAuditor::filterToken):
(WebCore::XSSAuditor::filterStartToken):
(WebCore::XSSAuditor::filterEndToken):
(WebCore::XSSAuditor::filterCharacterToken):
(WebCore::XSSAuditor::filterScriptToken):
(WebCore::XSSAuditor::filterObjectToken):
(WebCore::XSSAuditor::filterParamToken):
(WebCore::XSSAuditor::filterEmbedToken):
(WebCore::XSSAuditor::filterAppletToken):
(WebCore::XSSAuditor::filterIframeToken):
(WebCore::XSSAuditor::filterMetaToken):
(WebCore::XSSAuditor::filterBaseToken):
(WebCore::XSSAuditor::filterFormToken):
(WebCore::XSSAuditor::decodedSnippetForAttribute):
(WebCore::XSSAuditor::snippetForJavaScript):
* html/parser/XSSAuditor.h:
(XSSAuditor):

LayoutTests:

* http/tests/security/xssAuditor/iframe-onload-in-svg-tag-expected.txt: Added.
* http/tests/security/xssAuditor/iframe-onload-in-svg-tag.html: Added.
* http/tests/security/xssAuditor/script-tag-inside-svg-tag-expected.txt: Added.
* http/tests/security/xssAuditor/script-tag-inside-svg-tag.html: Added.
* http/tests/security/xssAuditor/script-tag-inside-svg-tag2-expected.txt: Added.
* http/tests/security/xssAuditor/script-tag-inside-svg-tag2.html: Added.
* http/tests/security/xssAuditor/script-tag-inside-svg-tag3-expected.txt: Added.
* http/tests/security/xssAuditor/script-tag-inside-svg-tag3.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (108550 => 108551)


--- trunk/LayoutTests/ChangeLog	2012-02-22 22:09:54 UTC (rev 108550)
+++ trunk/LayoutTests/ChangeLog	2012-02-22 22:21:14 UTC (rev 108551)
@@ -1,3 +1,19 @@
+2012-02-22  Tom Sepez  <[email protected]>
+
+        XSSAuditor bypass with <svg> tags and html-entities.
+        https://bugs.webkit.org/show_bug.cgi?id=78836
+
+        Reviewed by Adam Barth.
+
+        * http/tests/security/xssAuditor/iframe-onload-in-svg-tag-expected.txt: Added.
+        * http/tests/security/xssAuditor/iframe-onload-in-svg-tag.html: Added.
+        * http/tests/security/xssAuditor/script-tag-inside-svg-tag-expected.txt: Added.
+        * http/tests/security/xssAuditor/script-tag-inside-svg-tag.html: Added.
+        * http/tests/security/xssAuditor/script-tag-inside-svg-tag2-expected.txt: Added.
+        * http/tests/security/xssAuditor/script-tag-inside-svg-tag2.html: Added.
+        * http/tests/security/xssAuditor/script-tag-inside-svg-tag3-expected.txt: Added.
+        * http/tests/security/xssAuditor/script-tag-inside-svg-tag3.html: Added.
+
 2012-02-22  Ken Buchanan  <[email protected]>
 
         Crash from empty anonymous block preceding :before content

Added: trunk/LayoutTests/http/tests/security/xssAuditor/iframe-onload-in-svg-tag-expected.txt (0 => 108551)


--- trunk/LayoutTests/http/tests/security/xssAuditor/iframe-onload-in-svg-tag-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/xssAuditor/iframe-onload-in-svg-tag-expected.txt	2012-02-22 22:21:14 UTC (rev 108551)
@@ -0,0 +1,3 @@
+CONSOLE MESSAGE: Refused to execute a _javascript_ script. Source code of script found within request.
+
+ Test that dangerous attributes are still filtered in netsted script contexts.

Added: trunk/LayoutTests/http/tests/security/xssAuditor/iframe-onload-in-svg-tag.html (0 => 108551)


--- trunk/LayoutTests/http/tests/security/xssAuditor/iframe-onload-in-svg-tag.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/xssAuditor/iframe-onload-in-svg-tag.html	2012-02-22 22:21:14 UTC (rev 108551)
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script>
+if (window.layoutTestController) {
+    layoutTestController.dumpAsText();
+    layoutTestController.setXSSAuditorEnabled(true);
+}
+</script>
+</head>
+<body>
+<iframe src=""
+</iframe>
+Test that dangerous attributes are still filtered in netsted script contexts.
+</body>
+</html>

Added: trunk/LayoutTests/http/tests/security/xssAuditor/script-tag-inside-svg-tag-expected.txt (0 => 108551)


--- trunk/LayoutTests/http/tests/security/xssAuditor/script-tag-inside-svg-tag-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/xssAuditor/script-tag-inside-svg-tag-expected.txt	2012-02-22 22:21:14 UTC (rev 108551)
@@ -0,0 +1,3 @@
+CONSOLE MESSAGE: Refused to execute a _javascript_ script. Source code of script found within request.
+
+ Ensures HTML entities are recognized in script blocks in a context where CDATA is allowed.

Added: trunk/LayoutTests/http/tests/security/xssAuditor/script-tag-inside-svg-tag.html (0 => 108551)


--- trunk/LayoutTests/http/tests/security/xssAuditor/script-tag-inside-svg-tag.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/xssAuditor/script-tag-inside-svg-tag.html	2012-02-22 22:21:14 UTC (rev 108551)
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script>
+if (window.layoutTestController) {
+  layoutTestController.dumpAsText();
+  layoutTestController.setXSSAuditorEnabled(true);
+}
+</script>
+</head>
+<body>
+<iframe src=""
+</iframe>
+Ensures HTML entities are recognized in script blocks in a context where CDATA is allowed.
+</body>
+</html>

Added: trunk/LayoutTests/http/tests/security/xssAuditor/script-tag-inside-svg-tag2-expected.txt (0 => 108551)


--- trunk/LayoutTests/http/tests/security/xssAuditor/script-tag-inside-svg-tag2-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/xssAuditor/script-tag-inside-svg-tag2-expected.txt	2012-02-22 22:21:14 UTC (rev 108551)
@@ -0,0 +1,3 @@
+CONSOLE MESSAGE: Refused to execute a _javascript_ script. Source code of script found within request.
+
+ Ensures HTML entities are recognized in script blocks in a context where CDATA is allowed even with <!-- comments -->.

Added: trunk/LayoutTests/http/tests/security/xssAuditor/script-tag-inside-svg-tag2.html (0 => 108551)


--- trunk/LayoutTests/http/tests/security/xssAuditor/script-tag-inside-svg-tag2.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/xssAuditor/script-tag-inside-svg-tag2.html	2012-02-22 22:21:14 UTC (rev 108551)
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script>
+if (window.layoutTestController) {
+  layoutTestController.dumpAsText();
+  layoutTestController.setXSSAuditorEnabled(true);
+}
+</script>
+</head>
+<body>
+<iframe src=""
+</iframe>
+Ensures HTML entities are recognized in script blocks in a context where CDATA is allowed even with &lt;!-- comments --&gt;.
+</body>
+</html>

Added: trunk/LayoutTests/http/tests/security/xssAuditor/script-tag-inside-svg-tag3-expected.txt (0 => 108551)


--- trunk/LayoutTests/http/tests/security/xssAuditor/script-tag-inside-svg-tag3-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/xssAuditor/script-tag-inside-svg-tag3-expected.txt	2012-02-22 22:21:14 UTC (rev 108551)
@@ -0,0 +1,5 @@
+CONSOLE MESSAGE: Refused to execute a _javascript_ script. Source code of script found within request.
+
+CONSOLE MESSAGE: Refused to execute a _javascript_ script. Source code of script found within request.
+
+ Ensures HTML entities are recognized in script blocks in a context where CDATA is allowed even with nested script blocks.

Added: trunk/LayoutTests/http/tests/security/xssAuditor/script-tag-inside-svg-tag3.html (0 => 108551)


--- trunk/LayoutTests/http/tests/security/xssAuditor/script-tag-inside-svg-tag3.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/xssAuditor/script-tag-inside-svg-tag3.html	2012-02-22 22:21:14 UTC (rev 108551)
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script>
+if (window.layoutTestController) {
+  layoutTestController.dumpAsText();
+  layoutTestController.setXSSAuditorEnabled(true);
+}
+</script>
+</head>
+<body>
+<iframe src=""
+</iframe>
+Ensures HTML entities are recognized in script blocks in a context where CDATA is allowed even with nested script blocks.
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (108550 => 108551)


--- trunk/Source/WebCore/ChangeLog	2012-02-22 22:09:54 UTC (rev 108550)
+++ trunk/Source/WebCore/ChangeLog	2012-02-22 22:21:14 UTC (rev 108551)
@@ -1,3 +1,42 @@
+2012-02-22  Tom Sepez  <[email protected]>
+
+        XSSAuditor bypass with <svg> tags and html-entities.
+        https://bugs.webkit.org/show_bug.cgi?id=78836
+
+        Reviewed by Adam Barth.
+
+        Tests: http/tests/security/xssAuditor/iframe-onload-in-svg-tag.html
+               http/tests/security/xssAuditor/script-tag-inside-svg-tag.html
+               http/tests/security/xssAuditor/script-tag-inside-svg-tag2.html
+               http/tests/security/xssAuditor/script-tag-inside-svg-tag3.html
+
+        * html/parser/XSSAuditor.cpp:
+        (WebCore::isNonCanonicalCharacter):
+        (WebCore::isTerminatingCharacter):
+        (WebCore):
+        (WebCore::startsHTMLCommentAt):
+        (WebCore::startsSingleLineCommentAt):
+        (WebCore::fullyDecodeString):
+        (WebCore::XSSAuditor::XSSAuditor):
+        (WebCore::XSSAuditor::init):
+        (WebCore::XSSAuditor::filterToken):
+        (WebCore::XSSAuditor::filterStartToken):
+        (WebCore::XSSAuditor::filterEndToken):
+        (WebCore::XSSAuditor::filterCharacterToken):
+        (WebCore::XSSAuditor::filterScriptToken):
+        (WebCore::XSSAuditor::filterObjectToken):
+        (WebCore::XSSAuditor::filterParamToken):
+        (WebCore::XSSAuditor::filterEmbedToken):
+        (WebCore::XSSAuditor::filterAppletToken):
+        (WebCore::XSSAuditor::filterIframeToken):
+        (WebCore::XSSAuditor::filterMetaToken):
+        (WebCore::XSSAuditor::filterBaseToken):
+        (WebCore::XSSAuditor::filterFormToken):
+        (WebCore::XSSAuditor::decodedSnippetForAttribute):
+        (WebCore::XSSAuditor::snippetForJavaScript):
+        * html/parser/XSSAuditor.h:
+        (XSSAuditor):
+
 2012-02-22  Anders Carlsson  <[email protected]>
 
         Crash when marking cached pages for full style recalc

Modified: trunk/Source/WebCore/html/parser/XSSAuditor.cpp (108550 => 108551)


--- trunk/Source/WebCore/html/parser/XSSAuditor.cpp	2012-02-22 22:09:54 UTC (rev 108550)
+++ trunk/Source/WebCore/html/parser/XSSAuditor.cpp	2012-02-22 22:21:14 UTC (rev 108551)
@@ -36,6 +36,7 @@
 #include "FrameLoaderClient.h"
 #include "HTMLDocumentParser.h"
 #include "HTMLNames.h"
+#include "HTMLTokenizer.h"
 #include "HTMLParamElement.h"
 #include "HTMLParserIdioms.h"
 #include "SecurityOrigin.h"
@@ -54,7 +55,7 @@
     // We remove all non-ASCII characters, including non-printable ASCII characters.
     //
     // Note, we don't remove backslashes like PHP stripslashes(), which among other things converts "\\0" to the \0 character.
-    // Instead, we remove backslashes and zeros (since the string "\\0" =(remove backslashes)=> "0"). However, this has the 
+    // Instead, we remove backslashes and zeros (since the string "\\0" =(remove backslashes)=> "0"). However, this has the
     // adverse effect that we remove any legitimate zeros from a string.
     //
     // For instance: new String("http://localhost:8000") => new String("http://localhost:8").
@@ -71,7 +72,7 @@
     return (c == '\'' || c == '"' || c == '<' || c == '>');
 }
 
-static bool isTerminatingCharacter(UChar c) 
+static bool isTerminatingCharacter(UChar c)
 {
     return (c == '&' || c == '/' || c == '"' || c == '\'' || c == '<');
 }
@@ -87,21 +88,15 @@
     return (c == '\n' || c == '\r' || c == 0x2028 || c == 0x2029);
 }
 
-static bool startsHTMLEndTagAt(const String& string, size_t start)
-{
-    return (start + 1 < string.length() && string[start] == '<' && string[start+1] == '/');
-}    
-
-
 static bool startsHTMLCommentAt(const String& string, size_t start)
 {
     return (start + 3 < string.length() && string[start] == '<' && string[start+1] == '!' && string[start+2] == '-' && string[start+3] == '-');
-}    
+}
 
 static bool startsSingleLineCommentAt(const String& string, size_t start)
 {
     return (start + 1 < string.length() && string[start] == '/' && string[start+1] == '/');
-}    
+}
 
 static bool startsMultiLineCommentAt(const String& string, size_t start)
 {
@@ -177,7 +172,6 @@
         oldWorkingStringLength = workingString.length();
         workingString = decode16BitUnicodeEscapeSequences(decodeStandardURLEscapeSequences(workingString, encoding));
     } while (workingString.length() < oldWorkingStringLength);
-    ASSERT(!workingString.isEmpty());
     workingString.replace('+', ' ');
     workingString = canonicalize(workingString);
     return workingString;
@@ -188,6 +182,8 @@
     , m_isEnabled(false)
     , m_xssProtection(XSSProtectionEnabled)
     , m_state(Uninitialized)
+    , m_shouldAllowCDATA(false)
+    , m_scriptTagNestingLevel(0)
     , m_notifiedClient(false)
 {
     ASSERT(m_parser);
@@ -205,7 +201,7 @@
     const int suffixTreeDepth = 5;
 
     ASSERT(m_state == Uninitialized);
-    m_state = Initial;
+    m_state = Initialized;
 
     if (!m_isEnabled)
         return;
@@ -258,28 +254,21 @@
 
 void XSSAuditor::filterToken(HTMLToken& token)
 {
-    if (m_state == Uninitialized) {
+    if (m_state == Uninitialized)
         init();
-        ASSERT(m_state == Initial);
-    }
-
+   
+    ASSERT(m_state == Initialized);
     if (!m_isEnabled || m_xssProtection == XSSProtectionDisabled)
         return;
 
     bool didBlockScript = false;
-
-    switch (m_state) {
-    case Uninitialized:
-        ASSERT_NOT_REACHED();
-        break;
-    case Initial:
-        didBlockScript = filterTokenInitial(token);
-        break;
-    case AfterScriptStartTag:
-        didBlockScript = filterTokenAfterScriptStartTag(token);
-        ASSERT(m_state == Initial);
-        m_cachedSnippet = String();
-        break;
+    if (token.type() == HTMLTokenTypes::StartTag)
+        didBlockScript = filterStartToken(token);
+    else if (m_scriptTagNestingLevel) {
+        if (token.type() == HTMLTokenTypes::Character)
+            didBlockScript = filterCharacterToken(token);
+        else if (token.type() == HTMLTokenTypes::EndTag)
+            filterEndToken(token);
     }
 
     if (didBlockScript) {
@@ -301,18 +290,15 @@
     }
 }
 
-bool XSSAuditor::filterTokenInitial(HTMLToken& token)
+bool XSSAuditor::filterStartToken(HTMLToken& token)
 {
-    ASSERT(m_state == Initial);
-
-    if (token.type() != HTMLTokenTypes::StartTag)
-        return false;
-
     bool didBlockScript = eraseDangerousAttributesIfInjected(token);
 
-    if (hasName(token, scriptTag))
+    if (hasName(token, scriptTag)) {
         didBlockScript |= filterScriptToken(token);
-    else if (hasName(token, objectTag))
+        ASSERT(m_shouldAllowCDATA || !m_scriptTagNestingLevel);
+        m_scriptTagNestingLevel++;
+    } else if (hasName(token, objectTag))
         didBlockScript |= filterObjectToken(token);
     else if (hasName(token, paramTag))
         didBlockScript |= filterParamToken(token);
@@ -332,16 +318,18 @@
     return didBlockScript;
 }
 
-bool XSSAuditor::filterTokenAfterScriptStartTag(HTMLToken& token)
+void XSSAuditor::filterEndToken(HTMLToken& token)
 {
-    ASSERT(m_state == AfterScriptStartTag);
-    m_state = Initial;
-
-    if (token.type() != HTMLTokenTypes::Character) {
-        ASSERT(token.type() == HTMLTokenTypes::EndTag || token.type() == HTMLTokenTypes::EndOfFile);
-        return false;
+    ASSERT(m_scriptTagNestingLevel);
+    if (hasName(token, scriptTag)) {
+        m_scriptTagNestingLevel--;
+        ASSERT(m_shouldAllowCDATA || !m_scriptTagNestingLevel);
     }
+}
 
+bool XSSAuditor::filterCharacterToken(HTMLToken& token)
+{
+    ASSERT(m_scriptTagNestingLevel);
     TextResourceDecoder* decoder = m_parser->document()->decoder();
     if (isContainedInRequest(fullyDecodeString(m_cachedSnippet, decoder))) {
         int start = 0;
@@ -358,21 +346,19 @@
 
 bool XSSAuditor::filterScriptToken(HTMLToken& token)
 {
-    ASSERT(m_state == Initial);
     ASSERT(token.type() == HTMLTokenTypes::StartTag);
     ASSERT(hasName(token, scriptTag));
 
     if (eraseAttributeIfInjected(token, srcAttr, blankURL().string(), SrcLikeAttribute))
         return true;
 
-    m_state = AfterScriptStartTag;
     m_cachedSnippet = m_parser->sourceForToken(token);
+    m_shouldAllowCDATA = m_parser->tokenizer()->shouldAllowCDATA();
     return false;
 }
 
 bool XSSAuditor::filterObjectToken(HTMLToken& token)
 {
-    ASSERT(m_state == Initial);
     ASSERT(token.type() == HTMLTokenTypes::StartTag);
     ASSERT(hasName(token, objectTag));
 
@@ -387,7 +373,6 @@
 
 bool XSSAuditor::filterParamToken(HTMLToken& token)
 {
-    ASSERT(m_state == Initial);
     ASSERT(token.type() == HTMLTokenTypes::StartTag);
     ASSERT(hasName(token, paramTag));
 
@@ -406,7 +391,6 @@
 
 bool XSSAuditor::filterEmbedToken(HTMLToken& token)
 {
-    ASSERT(m_state == Initial);
     ASSERT(token.type() == HTMLTokenTypes::StartTag);
     ASSERT(hasName(token, embedTag));
 
@@ -421,7 +405,6 @@
 
 bool XSSAuditor::filterAppletToken(HTMLToken& token)
 {
-    ASSERT(m_state == Initial);
     ASSERT(token.type() == HTMLTokenTypes::StartTag);
     ASSERT(hasName(token, appletTag));
 
@@ -435,7 +418,6 @@
 
 bool XSSAuditor::filterIframeToken(HTMLToken& token)
 {
-    ASSERT(m_state == Initial);
     ASSERT(token.type() == HTMLTokenTypes::StartTag);
     ASSERT(hasName(token, iframeTag));
 
@@ -444,7 +426,6 @@
 
 bool XSSAuditor::filterMetaToken(HTMLToken& token)
 {
-    ASSERT(m_state == Initial);
     ASSERT(token.type() == HTMLTokenTypes::StartTag);
     ASSERT(hasName(token, metaTag));
 
@@ -453,7 +434,6 @@
 
 bool XSSAuditor::filterBaseToken(HTMLToken& token)
 {
-    ASSERT(m_state == Initial);
     ASSERT(token.type() == HTMLTokenTypes::StartTag);
     ASSERT(hasName(token, baseTag));
 
@@ -462,7 +442,6 @@
 
 bool XSSAuditor::filterFormToken(HTMLToken& token)
 {
-    ASSERT(m_state == Initial);
     ASSERT(token.type() == HTMLTokenTypes::StartTag);
     ASSERT(hasName(token, formTag));
 
@@ -541,8 +520,6 @@
 
 String XSSAuditor::decodedSnippetForAttribute(const HTMLToken& token, const HTMLToken::Attribute& attribute, AttributeKind treatment)
 {
-    const size_t kMaximumSnippetLength = 100;
-
     // The range doesn't inlcude the character which terminates the value. So,
     // for an input of |name="value"|, the snippet is |name="value|. For an
     // unquoted input of |name=value |, the snippet is |name=value|.
@@ -550,7 +527,7 @@
     int start = attribute.m_nameRange.m_start - token.startIndex();
     int end = attribute.m_valueRange.m_end - token.startIndex();
     String decodedSnippet = fullyDecodeString(snippetForRange(token, start, end), m_parser->document()->decoder());
-    decodedSnippet.truncate(kMaximumSnippetLength);
+    decodedSnippet.truncate(kMaximumFragmentLengthTarget);
     if (treatment == SrcLikeAttribute) {
         int slashCount;
         size_t currentLength;
@@ -593,8 +570,6 @@
 
 String XSSAuditor::snippetForJavaScript(const String& string)
 {
-    const size_t kMaximumFragmentLengthTarget = 100;
-
     size_t startPosition = 0;
     size_t endPosition = string.length();
     size_t foundPosition = notFound;
@@ -603,6 +578,15 @@
     while (startPosition < endPosition) {
         while (startPosition < endPosition && isHTMLSpace(string[startPosition]))
             startPosition++;
+
+        // Under SVG/XML rules, only HTML comment syntax matters and the parser returns
+        // these as a separate comment tokens. Having consumed whitespace, we need not look
+        // further for these.
+        if (m_shouldAllowCDATA)
+            break;
+
+        // Under HTML rules, both the HTML and JS comment synatx matters, and the HTML
+        // comment ends at the end of the line, not with -->.
         if (startsHTMLCommentAt(string, startPosition) || startsSingleLineCommentAt(string, startPosition)) {
             while (startPosition < endPosition && !isJSNewline(string[startPosition]))
                 startPosition++;
@@ -615,29 +599,29 @@
             break;
     }
 
-    // Stop at next comment, or at a closing script tag (which may have been included with
-    // the code fragment because of buffering in the HTMLSourceTracker), or when we exceed
-    // the maximum length target. After hitting the length target, we can only stop at a
-    // point where we know we are not in the middle of a %-escape sequence. For the sake of
-    // simplicity, approximate stopping at a close script tag by stopping at any close tag,
-    // and approximate not stopping inside a (possibly multiply encoded) %-esacpe sequence
-    // by breaking on whitespace only. We should have enough text in these cases to avoid
-    // false positives.
+    // Stop at next comment (using the same rules as above for SVG/XML vs HTML), or when
+    // we exceed the maximum length target. After hitting the length target, we can only
+    // stop at a point where we know we are not in the middle of a %-escape sequence. For
+    // the sake of simplicity, approximate not stopping inside a (possibly multiply encoded)
+    // %-esacpe sequence by breaking on whitespace only. We should have enough text in
+    // these cases to avoid false positives.
     for (foundPosition = startPosition; foundPosition < endPosition; foundPosition++) {
-        if (startsSingleLineCommentAt(string, foundPosition) || startsMultiLineCommentAt(string, foundPosition) || startsHTMLEndTagAt(string, foundPosition)) {
-            endPosition = foundPosition + 2;
-            break;
+        if (!m_shouldAllowCDATA) {
+            if (startsSingleLineCommentAt(string, foundPosition) || startsMultiLineCommentAt(string, foundPosition)) {
+                endPosition = foundPosition + 2;
+                break;
+            }
+            if (startsHTMLCommentAt(string, foundPosition)) {
+                endPosition = foundPosition + 4;
+                break;
+            }
         }
-        if (startsHTMLCommentAt(string, foundPosition)) {
-            endPosition = foundPosition + 4;
-            break;
-        }
         if (foundPosition > startPosition + kMaximumFragmentLengthTarget && isHTMLSpace(string[foundPosition])) {
             endPosition = foundPosition;
             break;
         }
     }
-    
+
     return string.substring(startPosition, endPosition - startPosition);
 }
 

Modified: trunk/Source/WebCore/html/parser/XSSAuditor.h (108550 => 108551)


--- trunk/Source/WebCore/html/parser/XSSAuditor.h	2012-02-22 22:09:54 UTC (rev 108550)
+++ trunk/Source/WebCore/html/parser/XSSAuditor.h	2012-02-22 22:21:14 UTC (rev 108551)
@@ -42,10 +42,11 @@
     void filterToken(HTMLToken&);
 
 private:
+    static const size_t kMaximumFragmentLengthTarget = 100;
+
     enum State {
         Uninitialized,
-        Initial,
-        AfterScriptStartTag,
+        Initialized
     };
 
     enum AttributeKind {
@@ -55,9 +56,9 @@
 
     void init();
 
-    bool filterTokenInitial(HTMLToken&);
-    bool filterTokenAfterScriptStartTag(HTMLToken&);
-
+    bool filterStartToken(HTMLToken&);
+    void filterEndToken(HTMLToken&);
+    bool filterCharacterToken(HTMLToken&);
     bool filterScriptToken(HTMLToken&);
     bool filterObjectToken(HTMLToken&);
     bool filterParamToken(HTMLToken&);
@@ -88,6 +89,8 @@
 
     State m_state;
     String m_cachedSnippet;
+    bool m_shouldAllowCDATA;
+    unsigned m_scriptTagNestingLevel;
     bool m_notifiedClient;
 };
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to