Changeset 18843 in webkit


Ignore:
Timestamp:
Jan 14, 2007 2:04:21 AM (17 years ago)
Author:
aroben
Message:

LayoutTests:

Reviewed by Maciej.

  • editing/deleting/4845371.html: Removed bogus "Javascript" type.
  • editing/selection/4397952.html: Ditto.
  • fast/html/script-allowed-types-languages-expected.txt: Added.
  • fast/html/script-allowed-types-languages.html: Added. Tests type/language whitelisting.

WebCore:

Reviewed by Maciej.

Make sure our whitelisting of the type and language attributes of the
<script> element is enforced in all HTMLTokenizer/HTMLScriptElement
code paths.

All layout tests pass.

  • html/HTMLScriptElement.cpp: (WebCore::HTMLScriptElement::shouldExecuteAsJavaScript): New method to determine whether the script should be executed, given its type and language attributes. (WebCore::HTMLScriptElement::evaluateScript): Check type/language before executing.
  • html/HTMLScriptElement.h: Added new declarations.
  • html/HTMLTokenizer.cpp: (WebCore::HTMLTokenizer::begin): Made scriptSrc a String. (WebCore::HTMLTokenizer::scriptHandler): Check shouldExecuteAsJavaScript before executing. (WebCore::HTMLTokenizer::notifyFinished): Ditto. (WebCore::HTMLTokenizer::parseTag): Moved type/language checking from here to HTMLScriptElement::shouldExecuteAsJavaScript.
  • html/HTMLTokenizer.h: Made scriptSrc a String, and removed the javascript member.
Location:
trunk
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r18837 r18843  
     12007-01-14  Adam Roben  <aroben@apple.com>
     2
     3        Reviewed by Maciej.
     4
     5        * editing/deleting/4845371.html: Removed bogus "Javascript" type.
     6        * editing/selection/4397952.html: Ditto.
     7        * fast/html/script-allowed-types-languages-expected.txt: Added.
     8        * fast/html/script-allowed-types-languages.html: Added. Tests
     9        type/language whitelisting.
     10
    1112007-01-14  Mark Rowe  <mrowe@apple.com>
    212
  • trunk/LayoutTests/editing/deleting/4845371.html

    r17936 r18843  
    22<div id="div" contenteditable="true"><table><tr><td>foo <a href="http://www.google.com/">bar</a></td><td>baz</td></tr></table></div>
    33
    4 <script type="Javascript" src="../editing.js"></script>
     4<script src="../editing.js"></script>
    55<script>
    66runEditingTest();
  • trunk/LayoutTests/editing/selection/4397952.html

    r17907 r18843  
    44</div>
    55
    6 <script type="Javascript" src="../editing.js"></script>
     6<script src="../editing.js"></script>
    77<script>
    88runEditingTest();
  • trunk/WebCore/ChangeLog

    r18840 r18843  
     12007-01-14  Adam Roben  <aroben@apple.com>
     2
     3        Reviewed by Maciej.
     4
     5        Make sure our whitelisting of the type and language attributes of the
     6        <script> element is enforced in all HTMLTokenizer/HTMLScriptElement
     7        code paths.
     8
     9        All layout tests pass.
     10
     11        * html/HTMLScriptElement.cpp:
     12        (WebCore::HTMLScriptElement::shouldExecuteAsJavaScript): New method to
     13        determine whether the script should be executed, given its type and
     14        language attributes.
     15        (WebCore::HTMLScriptElement::evaluateScript): Check type/language
     16        before executing.
     17        * html/HTMLScriptElement.h: Added new declarations.
     18        * html/HTMLTokenizer.cpp:
     19        (WebCore::HTMLTokenizer::begin): Made scriptSrc a String.
     20        (WebCore::HTMLTokenizer::scriptHandler): Check
     21        shouldExecuteAsJavaScript before executing.
     22        (WebCore::HTMLTokenizer::notifyFinished): Ditto.
     23        (WebCore::HTMLTokenizer::parseTag): Moved type/language checking from
     24        here to HTMLScriptElement::shouldExecuteAsJavaScript.
     25        * html/HTMLTokenizer.h: Made scriptSrc a String, and removed the
     26        javascript member.
     27
    1282007-01-14  David Hyatt  <hyatt@apple.com>
    229
  • trunk/WebCore/html/HTMLScriptElement.cpp

    r18428 r18843  
    55 *           (C) 1999 Antti Koivisto (koivisto@kde.org)
    66 *           (C) 2001 Dirk Mueller (mueller@kde.org)
    7  * Copyright (C) 2003 Apple Computer, Inc.
     7 * Copyright (C) 2003, 2004, 2005, 2006, 2007 Apple Inc.
    88 *
    99 * This library is free software; you can redistribute it and/or
     
    160160}
    161161
     162bool HTMLScriptElement::shouldExecuteAsJavaScript()
     163{
     164    /*
     165        Mozilla 1.8 and WinIE 7 both accept text/javascript and text/ecmascript.
     166        Mozilla 1.8 accepts application/javascript, application/ecmascript, and application/x-javascript, but WinIE 7 doesn't.
     167        WinIE 7 accepts text/javascript1.1 - text/javascript1.3, text/jscript, and text/livescript, but Mozilla 1.8 doesn't.
     168        Mozilla 1.8 allows leading and trailing whitespace, but WinIE 7 doesn't.
     169        Mozilla 1.8 and WinIE 7 both accept the empty string, but neither accept a whitespace-only string.
     170        We want to accept all the values that either of these browsers accept, but not other values.
     171     */
     172    static const AtomicString validTypes[] = {
     173        "text/javascript",
     174        "text/ecmascript",
     175        "application/javascript",
     176        "application/ecmascript",
     177        "application/x-javascript",
     178        "text/javascript1.1",
     179        "text/javascript1.2",
     180        "text/javascript1.3",
     181        "text/jscript",
     182        "text/livescript",
     183    };
     184    static const unsigned validTypesCount = sizeof(validTypes) / sizeof(validTypes[0]);
     185
     186    /*
     187         Mozilla 1.8 accepts javascript1.0 - javascript1.7, but WinIE 7 accepts only javascript1.1 - javascript1.3.
     188         Mozilla 1.8 and WinIE 7
     189         WinIE 7 accepts ecmascript and jscript, but Mozilla 1.8 doesn't.
     190         Neither Mozilla 1.8 nor WinIE 7 accept leading or trailing whitespace.
     191         We want to accept all the values that either of these browsers accept, but not other values.
     192     */
     193    static const AtomicString validLanguages[] = {
     194        "javascript",
     195        "javascript1.0",
     196        "javascript1.1",
     197        "javascript1.2",
     198        "javascript1.3",
     199        "javascript1.4",
     200        "javascript1.5",
     201        "javascript1.6",
     202        "javascript1.7",
     203        "livescript",
     204        "ecmascript",
     205        "jscript"
     206    };
     207    static const unsigned validLanguagesCount = sizeof(validLanguages) / sizeof(validLanguages[0]);
     208
     209    const AtomicString& type = getAttribute(typeAttr);
     210    if (!type.isEmpty()) {
     211        String lowerType = type.domString().stripWhiteSpace().lower();
     212        for (unsigned i = 0; i < validTypesCount; ++i)
     213            if (lowerType == validTypes[i])
     214                return true;
     215
     216        return false;
     217    }
     218   
     219    const AtomicString& language = getAttribute(languageAttr);
     220    if (!language.isEmpty()) {
     221        String lowerLanguage = language.domString().lower();
     222        for (unsigned i = 0; i < validLanguagesCount; ++i)
     223            if (lowerLanguage == validLanguages[i])
     224                return true;
     225
     226        return false;
     227    }
     228
     229    // No type or language is specified, so we assume the script to be JavaScript
     230    return true;
     231}
     232
    162233void HTMLScriptElement::evaluateScript(const String& URL, const String& script)
    163234{
    164235    if (m_evaluated)
     236        return;
     237   
     238    if (!shouldExecuteAsJavaScript())
    165239        return;
    166240   
  • trunk/WebCore/html/HTMLScriptElement.h

    r15269 r18843  
    44 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
    55 *           (C) 1999 Antti Koivisto (koivisto@kde.org)
    6  * Copyright (C) 2003 Apple Computer, Inc.
     6 * Copyright (C) 2003, 2004, 2005, 2006, 2007 Apple Inc.
    77 *
    88 * This library is free software; you can redistribute it and/or
     
    5454    virtual void closeRenderer();
    5555
     56    bool shouldExecuteAsJavaScript();
    5657    void evaluateScript(const String &URL, const String &script);
    5758
  • trunk/WebCore/html/HTMLTokenizer.cpp

    r18417 r18843  
    88              (C) 1999 Antti Koivisto (koivisto@kde.org)
    99              (C) 2001 Dirk Mueller (mueller@kde.org)
    10     Copyright (C) 2004, 2005, 2006 Apple Computer, Inc.
     10    Copyright (C) 2004, 2005, 2006, 2007 Apple Inc.
    1111    Copyright (C) 2005, 2006 Alexey Proskuryakov (ap@nypop.com)
    1212
     
    3737#include "FrameLoader.h"
    3838#include "FrameView.h"
     39#include "HTMLElement.h"
     40#include "HTMLNames.h"
     41#include "HTMLParser.h"
     42#include "HTMLScriptElement.h"
    3943#include "HTMLViewSourceDocument.h"
    40 #include "HTMLElement.h"
    4144#include "SystemTime.h"
    4245#include "csshelper.h"
    43 #include "HTMLNames.h"
    44 #include "HTMLParser.h"
    4546#include "kjs_proxy.h"
    4647
     
    227228    searchCount = 0;
    228229    m_state.setEntityState(NoEntity);
    229     scriptSrc = DeprecatedString::null;
     230    scriptSrc = String();
    230231    pendingSrc.clear();
    231232    currentPrependingSrc = 0;
     
    392393            } else
    393394                scriptNode = 0;
    394             scriptSrc=DeprecatedString::null;
     395            scriptSrc = String();
    395396        } else {
    396397#ifdef TOKEN_DEBUG
     
    399400            kdDebug( 6036 ) << "---END SCRIPT---" << endl;
    400401#endif
     402            // Parse scriptCode containing <script> info
     403            doScriptExec = static_cast<HTMLScriptElement*>(scriptNode.get())->shouldExecuteAsJavaScript();
    401404            scriptNode = 0;
    402             // Parse scriptCode containing <script> info
    403             doScriptExec = true;
    404405        }
    405406    }
     
    442443            if (!pendingScripts.isEmpty())
    443444                state.setLoadingExtScript(true);
    444         }
    445         else if (!m_fragment && doScriptExec && javascript ) {
     445        } else if (!m_fragment && doScriptExec) {
    446446            if (!m_executingScript)
    447447                pendingSrc.prepend(src);
     
    11481148            if (currToken.beginTag && currToken.tagName == scriptTag) {
    11491149                Attribute* a = 0;
    1150                 bool foundTypeAttribute = false;
    1151                 scriptSrc = DeprecatedString::null;
     1150                scriptSrc = String();
    11521151                scriptSrcCharset = String();
    11531152                if (currToken.attrs && !m_fragment && m_doc->frame() && m_doc->frame()->settings()->isJavaScriptEnabled()) {
    11541153                    if ((a = currToken.attrs->getAttributeItem(srcAttr)))
    1155                         scriptSrc = m_doc->completeURL(parseURL(a->value()).deprecatedString());
     1154                        scriptSrc = m_doc->completeURL(parseURL(a->value()));
    11561155                    if ((a = currToken.attrs->getAttributeItem(charsetAttr)))
    11571156                        scriptSrcCharset = a->value().domString().stripWhiteSpace();
    11581157                    if (scriptSrcCharset.isEmpty())
    11591158                        scriptSrcCharset = m_doc->frame()->loader()->encoding();
    1160                     /* Check type before language, since language is deprecated */
    1161                     if ((a = currToken.attrs->getAttributeItem(typeAttr)) != 0 && !a->value().isEmpty())
    1162                         foundTypeAttribute = true;
    1163                     else
    1164                         a = currToken.attrs->getAttributeItem(languageAttr);
    1165                 }
    1166                 javascript = true;
    1167 
    1168                 if( foundTypeAttribute ) {
    1169                     /*
    1170                         Mozilla 1.5 accepts application/x-javascript, and some web references claim it is the only
    1171                         correct variation, but WinIE 6 doesn't accept it.
    1172                         Neither Mozilla 1.5 nor WinIE 6 accept application/javascript, application/ecmascript, or
    1173                         application/x-ecmascript.
    1174                         Mozilla 1.5 doesn't accept the text/javascript1.x formats, but WinIE 6 does.
    1175                         Mozilla 1.5 doesn't accept text/jscript, text/ecmascript, and text/livescript, but WinIE 6 does.
    1176                         Mozilla 1.5 allows leading and trailing whitespace, but WinIE 6 doesn't.
    1177                         Mozilla 1.5 and WinIE 6 both accept the empty string, but neither accept a whitespace-only string.
    1178                         We want to accept all the values that either of these browsers accept, but not other values.
    1179                      */
    1180                     DeprecatedString type = a->value().domString().stripWhiteSpace().lower().deprecatedString();
    1181                     if( type.compare("application/x-javascript") != 0 &&
    1182                         type.compare("text/javascript") != 0 &&
    1183                         type.compare("text/javascript1.0") != 0 &&
    1184                         type.compare("text/javascript1.1") != 0 &&
    1185                         type.compare("text/javascript1.2") != 0 &&
    1186                         type.compare("text/javascript1.3") != 0 &&
    1187                         type.compare("text/javascript1.4") != 0 &&
    1188                         type.compare("text/javascript1.5") != 0 &&
    1189                         type.compare("text/jscript") != 0 &&
    1190                         type.compare("text/ecmascript") != 0 &&
    1191                         type.compare("text/livescript") )
    1192                         javascript = false;
    1193                 } else if( a ) {
    1194                     /*
    1195                      Mozilla 1.5 doesn't accept jscript or ecmascript, but WinIE 6 does.
    1196                      Mozilla 1.5 accepts javascript1.0, javascript1.4, and javascript1.5, but WinIE 6 accepts only 1.1 - 1.3.
    1197                      Neither Mozilla 1.5 nor WinIE 6 accept leading or trailing whitespace.
    1198                      We want to accept all the values that either of these browsers accept, but not other values.
    1199                      */
    1200                     String lang = a->value().domString().lower();
    1201                     if( lang != "" &&
    1202                         lang != "javascript" &&
    1203                         lang != "javascript1.0" &&
    1204                         lang != "javascript1.1" &&
    1205                         lang != "javascript1.2" &&
    1206                         lang != "javascript1.3" &&
    1207                         lang != "javascript1.4" &&
    1208                         lang != "javascript1.5" &&
    1209                         lang != "ecmascript" &&
    1210                         lang != "livescript" &&
    1211                         lang != "jscript")
    1212                         javascript = false;
    12131159                }
    12141160            }
     
    17011647        bool errorOccurred = cs->errorOccurred();
    17021648        cs->deref(this);
    1703         RefPtr<Node> n = scriptNode;
    1704         scriptNode = 0;
     1649        RefPtr<Node> n = scriptNode.release();
    17051650
    17061651#ifdef INSTRUMENT_LAYOUT_SCHEDULING
     
    17121657            EventTargetNodeCast(n.get())->dispatchHTMLEvent(errorEvent, true, false);
    17131658        else {
    1714             m_state = scriptExecution(scriptSource.deprecatedString(), m_state, cachedScriptUrl);
     1659            if (static_cast<HTMLScriptElement*>(n.get())->shouldExecuteAsJavaScript())
     1660                m_state = scriptExecution(scriptSource.deprecatedString(), m_state, cachedScriptUrl);
    17151661            EventTargetNodeCast(n.get())->dispatchHTMLEvent(loadEvent, false, false);
    17161662        }
  • trunk/WebCore/html/HTMLTokenizer.h

    r18669 r18843  
    297297    bool noMoreData;
    298298    // URL to get source code of script from
    299     DeprecatedString scriptSrc;
     299    String scriptSrc;
    300300    String scriptSrcCharset;
    301     bool javascript;
    302301    // the HTML code we will parse after the external script we are waiting for has loaded
    303302    SegmentedString pendingSrc;
Note: See TracChangeset for help on using the changeset viewer.