Changeset 96231 in webkit


Ignore:
Timestamp:
Sep 28, 2011 10:19:08 AM (13 years ago)
Author:
commit-queue@webkit.org
Message:

Revert change which broke displaying end script tags in view-source, instead
deal with any trailing </script> tag included by mistake in the XSSAuditor
itself. Correct tests to detect the missing close tags.
https://bugs.webkit.org/show_bug.cgi?id=68898

Patch by Tom Sepez <tsepez@chromium.org> on 2011-09-28
Reviewed by Adam Barth.

Source/WebCore:

  • html/parser/HTMLSourceTracker.cpp:

(WebCore::HTMLSourceTracker::end):

  • html/parser/HTMLTokenizer.cpp:

(WebCore::HTMLTokenizer::nextToken):

  • html/parser/XSSAuditor.cpp:

(WebCore::startsHTMLEndTagAt):
(WebCore::XSSAuditor::snippetForJavaScript):

LayoutTests:

  • fast/frames/resources/viewsource-frame-2.html:
  • fast/frames/viewsource-plain-text-tags-expected.txt:
  • fast/frames/viewsource-plain-text-tags.html:
Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r96224 r96231  
     12011-09-28  Tom Sepez  <tsepez@chromium.org>
     2
     3        Revert change which broke displaying end script tags in view-source, instead
     4        deal with any trailing </script> tag included by mistake in the XSSAuditor
     5        itself.  Correct tests to detect the missing close tags.
     6        https://bugs.webkit.org/show_bug.cgi?id=68898
     7
     8        Reviewed by Adam Barth.
     9
     10        * fast/frames/resources/viewsource-frame-2.html:
     11        * fast/frames/viewsource-plain-text-tags-expected.txt:
     12        * fast/frames/viewsource-plain-text-tags.html:
     13
    1142011-09-28  Antaryami Pandia  <antaryami.pandia@motorola.com>
    215
  • trunk/LayoutTests/fast/frames/resources/viewsource-frame-2.html

    r33509 r96231  
    11<script>
    2 <test>
     2<testscript>
    33</script>
    44
    55<style>
    6 <test>
     6<teststyle>
    77</style>
    88
    99<xmp>
    10 <test>
     10<testxmp>
    1111</xmp>
    1212
    1313<textarea>
    14 <test>
     14<testtextarea>
    1515</textarea>
  • trunk/LayoutTests/fast/frames/viewsource-plain-text-tags-expected.txt

    r33509 r96231  
    1 PASS
     1script: PASS PASS PASS style: PASS PASS PASS xmp: PASS PASS PASS textarea: PASS PASS PASS
  • trunk/LayoutTests/fast/frames/viewsource-plain-text-tags.html

    r80456 r96231  
    77    }
    88
    9     function report(frame) {
     9    function found(text, regexString)
     10    {
     11        var matches = text.match(new RegExp(regexString, 'g'));
     12        if (matches && matches.length === 1)
     13            return 'PASS';
     14        else
     15            return 'FAIL';
     16    }
     17   
     18    function testSection(text, name) {
     19        // Closing tags are not correctly formated, so don't check their markup.
     20        return name + ': ' +
     21             found(text, '<span class="webkit-html-tag">&lt;' + name + '&gt') + ' ' +
     22             found(text, '<td class="webkit-line-content">&lt;test' + name + '&gt;') + ' ' +
     23             found(text, '&lt;/' + name + '&gt;') + '\n';
     24    }
     25
     26    function report(frame)
     27    {
    1028        var result = frame.contentDocument.documentElement.innerHTML;
    11         var regex = new RegExp("<td class=\"webkit-line-content\">&lt;test&gt;</td>", "g");
    12         matches = result.match(regex);
     29        var resultText = '';
    1330
    14         if (matches && matches.length === 4)
    15             var resultText = "PASS";
    16         else
    17             var resultText = "FAIL";
     31        resultText += testSection(result, 'script');
     32        resultText += testSection(result, 'style');
     33        resultText += testSection(result, 'xmp');
     34        resultText += testSection(result, 'textarea');
    1835
    1936        if (window.layoutTestController) {
     
    2138            document.write(resultText);
    2239            document.close();
    23 
    2440            layoutTestController.notifyDone();
    2541        } else {
     
    3147<body>
    3248<p>You should see a frame in 'view source' mode below.</p>
    33 <p>None of the "&lt;test&gt;" strings shown below should be colorized like HTML.</p>
     49<p>None of the "&lt;testxxx&gt;" strings shown below should be colorized like HTML.</p>
    3450<hr>
    3551<div id="result"></div>
  • trunk/Source/WebCore/ChangeLog

    r96229 r96231  
     12011-09-28  Tom Sepez  <tsepez@chromium.org>
     2
     3        Revert change which broke displaying end script tags in view-source, instead
     4        deal with any trailing </script> tag included by mistake in the XSSAuditor
     5        itself.  Correct tests to detect the missing close tags.
     6        https://bugs.webkit.org/show_bug.cgi?id=68898
     7
     8        Reviewed by Adam Barth.
     9
     10        * html/parser/HTMLSourceTracker.cpp:
     11        (WebCore::HTMLSourceTracker::end):
     12        * html/parser/HTMLTokenizer.cpp:
     13        (WebCore::HTMLTokenizer::nextToken):
     14        * html/parser/XSSAuditor.cpp:
     15        (WebCore::startsHTMLEndTagAt):
     16        (WebCore::XSSAuditor::snippetForJavaScript):
     17
    1182011-09-28  Adam Barth  <abarth@webkit.org>
    219
  • trunk/Source/WebCore/html/parser/HTMLSourceTracker.cpp

    r95901 r96231  
    4545    m_cachedSourceForToken = String();
    4646
    47     // FIXME: This work should really be done by the HTMLTokenizer in all cases,
    48     // instead of the few cases where it explicitly steps in to correct values
    49     // known to be wrong in face of its internal buffering.
    50     if (!token.endIndex())
    51         token.end(input.current().numberOfCharactersConsumed());
     47    // FIXME: This work should really be done by the HTMLTokenizer.
     48    token.end(input.current().numberOfCharactersConsumed());
    5249}
    5350
  • trunk/Source/WebCore/html/parser/HTMLTokenizer.cpp

    r95901 r96231  
    298298
    299299    HTML_BEGIN_STATE(ScriptDataState) {
    300         if (cc == '<') {
    301             // Token might end here. If not, we'll come through here again
    302             // and update the end location again.
    303             m_token->end(source.numberOfCharactersConsumed());
     300        if (cc == '<')
    304301            HTML_ADVANCE_TO(ScriptDataLessThanSignState);
    305         }
    306302        else if (cc == InputStreamPreprocessor::endOfFileMarker)
    307303            return emitEndOfFile(source);
  • trunk/Source/WebCore/html/parser/XSSAuditor.cpp

    r95901 r96231  
    8585    return (c == '\n' || c == '\r');
    8686}
     87
     88static bool startsHTMLEndTagAt(const String& string, size_t start)
     89{
     90    return (start + 1 < string.length() && string[start] == '<' && string[start+1] == '/');
     91}   
     92
    8793
    8894static bool startsHTMLCommentAt(const String& string, size_t start)
     
    584590    }
    585591
    586     // Stop at next comment or when we exceed the maximum length target. After hitting the
    587     // length target, we can only stop at a point where we know we are not in the middle of
    588     // a %-escape sequence. A simple way to do this is to break on whitespace only.               
     592    // Stop at next comment, or at a closing script tag (which may have been included with
     593    // the code fragment because of buffering in the HTMLSourceTracker), or when we exceed
     594    // the maximum length target. After hitting the length target, we can only stop at a
     595    // point where we know we are not in the middle of a %-escape sequence. For the sake of
     596    // simplicity, approximate stopping at a close script tag by stopping at any close tag,
     597    // and approximate not stopping inside a (possibly multiply encoded) %-esacpe sequence
     598    // by breaking on whitespace only. We should have enough text in these cases to avoid
     599    // false positives.
    589600    for (foundPosition = startPosition; foundPosition < endPosition; foundPosition++) {
    590         if (startsSingleLineCommentAt(string, foundPosition) || startsMultiLineCommentAt(string, foundPosition)) {
     601        if (startsSingleLineCommentAt(string, foundPosition) || startsMultiLineCommentAt(string, foundPosition) || startsHTMLEndTagAt(string, foundPosition)) {
    591602            endPosition = foundPosition + 2;
    592603            break;
Note: See TracChangeset for help on using the changeset viewer.