a9a6d94
diff -up qt-everywhere-opensource-src-4.6.2/src/3rdparty/webkit/WebCore/css/CSSGrammar.y.cve-2010-0051-lax-css-parsing-cross-domain-theft qt-everywhere-opensource-src-4.6.2/src/3rdparty/webkit/WebCore/css/CSSGrammar.y
a9a6d94
--- qt-everywhere-opensource-src-4.6.2/src/3rdparty/webkit/WebCore/css/CSSGrammar.y.cve-2010-0051-lax-css-parsing-cross-domain-theft	2010-02-11 16:55:20.000000000 +0100
a9a6d94
+++ qt-everywhere-opensource-src-4.6.2/src/3rdparty/webkit/WebCore/css/CSSGrammar.y	2010-02-25 17:07:29.114742034 +0100
a9a6d94
@@ -416,7 +416,9 @@ valid_rule:
a9a6d94
   ;
a9a6d94
 
a9a6d94
 rule:
a9a6d94
-    valid_rule
a9a6d94
+    valid_rule {
a9a6d94
+        static_cast<CSSParser*>(parser)->m_hadSyntacticallyValidCSSRule = true;
a9a6d94
+    }
a9a6d94
   | invalid_rule
a9a6d94
   | invalid_at
a9a6d94
   | invalid_import
a9a6d94
@@ -1517,8 +1519,12 @@ invalid_rule:
a9a6d94
     ;
a9a6d94
 
a9a6d94
 invalid_block:
a9a6d94
-    '{' error invalid_block_list error closing_brace
a9a6d94
-  | '{' error closing_brace
a9a6d94
+    '{' error invalid_block_list error closing_brace {
a9a6d94
+        static_cast<CSSParser*>(parser)->invalidBlockHit();
a9a6d94
+    }
a9a6d94
+  | '{' error closing_brace {
a9a6d94
+        static_cast<CSSParser*>(parser)->invalidBlockHit();
a9a6d94
+    }
a9a6d94
     ;
a9a6d94
 
a9a6d94
 invalid_block_list:
a9a6d94
diff -up qt-everywhere-opensource-src-4.6.2/src/3rdparty/webkit/WebCore/css/CSSImportRule.cpp.cve-2010-0051-lax-css-parsing-cross-domain-theft qt-everywhere-opensource-src-4.6.2/src/3rdparty/webkit/WebCore/css/CSSImportRule.cpp
a9a6d94
--- qt-everywhere-opensource-src-4.6.2/src/3rdparty/webkit/WebCore/css/CSSImportRule.cpp.cve-2010-0051-lax-css-parsing-cross-domain-theft	2010-02-11 16:55:20.000000000 +0100
a9a6d94
+++ qt-everywhere-opensource-src-4.6.2/src/3rdparty/webkit/WebCore/css/CSSImportRule.cpp	2010-02-25 17:13:34.292803953 +0100
a9a6d94
@@ -25,6 +25,7 @@
a9a6d94
 #include "CachedCSSStyleSheet.h"
a9a6d94
 #include "DocLoader.h"
a9a6d94
 #include "Document.h"
a9a6d94
+#include "SecurityOrigin.h"
a9a6d94
 #include "MediaList.h"
a9a6d94
 #include "Settings.h"
a9a6d94
 #include <wtf/StdLibExtras.h>
a9a6d94
@@ -60,11 +61,21 @@ void CSSImportRule::setCSSStyleSheet(con
a9a6d94
         m_styleSheet->setParent(0);
a9a6d94
     m_styleSheet = CSSStyleSheet::create(this, url, charset);
a9a6d94
 
a9a6d94
+    bool crossOriginCSS = false;
a9a6d94
+    bool validMIMEType = false;
a9a6d94
     CSSStyleSheet* parent = parentStyleSheet();
a9a6d94
     bool strict = !parent || parent->useStrictParsing();
a9a6d94
-    String sheetText = sheet->sheetText(strict);
a9a6d94
+    bool enforceMIMEType = strict;
a9a6d94
+
a9a6d94
+    String sheetText = sheet->sheetText(enforceMIMEType, &validMIMEType);
a9a6d94
     m_styleSheet->parseString(sheetText, strict);
a9a6d94
 
a9a6d94
+    if (!parent || !parent->doc() || !parent->doc()->securityOrigin()->canRequest(KURL(ParsedURLString, url)))
a9a6d94
+        crossOriginCSS = true;
a9a6d94
+
a9a6d94
+    if (crossOriginCSS && !validMIMEType && !m_styleSheet->hasSyntacticallyValidCSSHeader())
a9a6d94
+        m_styleSheet = CSSStyleSheet::create(this, url, charset);
a9a6d94
+
a9a6d94
     if (strict && parent && parent->doc() && parent->doc()->settings() && parent->doc()->settings()->needsSiteSpecificQuirks()) {
a9a6d94
         // Work around <https://bugs.webkit.org/show_bug.cgi?id=28350>.
a9a6d94
         DEFINE_STATIC_LOCAL(const String, slashKHTMLFixesDotCss, ("/KHTMLFixes.css"));
a9a6d94
diff -up qt-everywhere-opensource-src-4.6.2/src/3rdparty/webkit/WebCore/css/CSSParser.cpp.cve-2010-0051-lax-css-parsing-cross-domain-theft qt-everywhere-opensource-src-4.6.2/src/3rdparty/webkit/WebCore/css/CSSParser.cpp
a9a6d94
--- qt-everywhere-opensource-src-4.6.2/src/3rdparty/webkit/WebCore/css/CSSParser.cpp.cve-2010-0051-lax-css-parsing-cross-domain-theft	2010-02-25 17:07:29.101741771 +0100
a9a6d94
+++ qt-everywhere-opensource-src-4.6.2/src/3rdparty/webkit/WebCore/css/CSSParser.cpp	2010-02-25 17:07:29.117741744 +0100
a9a6d94
@@ -139,6 +139,7 @@ CSSParser::CSSParser(bool strictParsing)
a9a6d94
     , m_currentShorthand(0)
a9a6d94
     , m_implicitShorthand(false)
a9a6d94
     , m_hasFontFaceOnlyValues(false)
a9a6d94
+    , m_hadSyntacticallyValidCSSRule(false)
a9a6d94
     , m_defaultNamespace(starAtom)
a9a6d94
     , m_data(0)
a9a6d94
     , yy_start(1)
a9a6d94
@@ -5175,6 +5176,12 @@ WebKitCSSKeyframeRule* CSSParser::create
a9a6d94
     return keyframePtr;
a9a6d94
 }
a9a6d94
 
a9a6d94
+void CSSParser::invalidBlockHit()
a9a6d94
+{
a9a6d94
+    if (m_styleSheet && !m_hadSyntacticallyValidCSSRule)
a9a6d94
+        m_styleSheet->setHasSyntacticallyValidCSSHeader(false);
a9a6d94
+}
a9a6d94
+
a9a6d94
 static int cssPropertyID(const UChar* propertyName, unsigned length)
a9a6d94
 {
a9a6d94
     if (!length)
a9a6d94
diff -up qt-everywhere-opensource-src-4.6.2/src/3rdparty/webkit/WebCore/css/CSSParser.h.cve-2010-0051-lax-css-parsing-cross-domain-theft qt-everywhere-opensource-src-4.6.2/src/3rdparty/webkit/WebCore/css/CSSParser.h
a9a6d94
--- qt-everywhere-opensource-src-4.6.2/src/3rdparty/webkit/WebCore/css/CSSParser.h.cve-2010-0051-lax-css-parsing-cross-domain-theft	2010-02-11 16:55:20.000000000 +0100
a9a6d94
+++ qt-everywhere-opensource-src-4.6.2/src/3rdparty/webkit/WebCore/css/CSSParser.h	2010-02-25 17:07:29.117741744 +0100
a9a6d94
@@ -191,6 +191,7 @@ namespace WebCore {
a9a6d94
         bool addVariableDeclarationBlock(const CSSParserString&);
a9a6d94
         bool checkForVariables(CSSParserValueList*);
a9a6d94
         void addUnresolvedProperty(int propId, bool important);
a9a6d94
+        void invalidBlockHit();
a9a6d94
         
a9a6d94
         Vector<CSSSelector*>* reusableSelectorVector() { return &m_reusableSelectorVector; }
a9a6d94
         
a9a6d94
@@ -212,6 +213,7 @@ namespace WebCore {
a9a6d94
         bool m_implicitShorthand;
a9a6d94
 
a9a6d94
         bool m_hasFontFaceOnlyValues;
a9a6d94
+        bool m_hadSyntacticallyValidCSSRule;
a9a6d94
 
a9a6d94
         Vector<String> m_variableNames;
a9a6d94
         Vector<RefPtr<CSSValue> > m_variableValues;
a9a6d94
diff -up qt-everywhere-opensource-src-4.6.2/src/3rdparty/webkit/WebCore/css/CSSStyleSheet.cpp.cve-2010-0051-lax-css-parsing-cross-domain-theft qt-everywhere-opensource-src-4.6.2/src/3rdparty/webkit/WebCore/css/CSSStyleSheet.cpp
a9a6d94
--- qt-everywhere-opensource-src-4.6.2/src/3rdparty/webkit/WebCore/css/CSSStyleSheet.cpp.cve-2010-0051-lax-css-parsing-cross-domain-theft	2010-02-11 16:55:19.000000000 +0100
a9a6d94
+++ qt-everywhere-opensource-src-4.6.2/src/3rdparty/webkit/WebCore/css/CSSStyleSheet.cpp	2010-02-25 17:07:29.118741824 +0100
a9a6d94
@@ -41,6 +41,7 @@ CSSStyleSheet::CSSStyleSheet(CSSStyleShe
a9a6d94
     , m_loadCompleted(false)
a9a6d94
     , m_strictParsing(!parentSheet || parentSheet->useStrictParsing())
a9a6d94
     , m_isUserStyleSheet(parentSheet ? parentSheet->isUserStyleSheet() : false)
a9a6d94
+    , m_hasSyntacticallyValidCSSHeader(true)
a9a6d94
 {
a9a6d94
 }
a9a6d94
 
a9a6d94
@@ -52,6 +53,7 @@ CSSStyleSheet::CSSStyleSheet(Node* paren
a9a6d94
     , m_loadCompleted(false)
a9a6d94
     , m_strictParsing(false)
a9a6d94
     , m_isUserStyleSheet(false)
a9a6d94
+    , m_hasSyntacticallyValidCSSHeader(true)
a9a6d94
 {
a9a6d94
 }
a9a6d94
 
a9a6d94
@@ -61,6 +63,7 @@ CSSStyleSheet::CSSStyleSheet(CSSRule* ow
a9a6d94
     , m_charset(charset)
a9a6d94
     , m_loadCompleted(false)
a9a6d94
     , m_strictParsing(!ownerRule || ownerRule->useStrictParsing())
a9a6d94
+    , m_hasSyntacticallyValidCSSHeader(true)
a9a6d94
 {
a9a6d94
     CSSStyleSheet* parentSheet = ownerRule ? ownerRule->parentStyleSheet() : 0;
a9a6d94
     m_doc = parentSheet ? parentSheet->doc() : 0;
a9a6d94
diff -up qt-everywhere-opensource-src-4.6.2/src/3rdparty/webkit/WebCore/css/CSSStyleSheet.h.cve-2010-0051-lax-css-parsing-cross-domain-theft qt-everywhere-opensource-src-4.6.2/src/3rdparty/webkit/WebCore/css/CSSStyleSheet.h
a9a6d94
--- qt-everywhere-opensource-src-4.6.2/src/3rdparty/webkit/WebCore/css/CSSStyleSheet.h.cve-2010-0051-lax-css-parsing-cross-domain-theft	2010-02-11 16:55:20.000000000 +0100
a9a6d94
+++ qt-everywhere-opensource-src-4.6.2/src/3rdparty/webkit/WebCore/css/CSSStyleSheet.h	2010-02-25 17:07:29.118741824 +0100
a9a6d94
@@ -95,6 +95,8 @@ public:
a9a6d94
 
a9a6d94
     void setIsUserStyleSheet(bool b) { m_isUserStyleSheet = b; }
a9a6d94
     bool isUserStyleSheet() const { return m_isUserStyleSheet; }
a9a6d94
+    void setHasSyntacticallyValidCSSHeader(bool b) { m_hasSyntacticallyValidCSSHeader = b; }
a9a6d94
+    bool hasSyntacticallyValidCSSHeader() const { return m_hasSyntacticallyValidCSSHeader; }
a9a6d94
 
a9a6d94
 private:
a9a6d94
     CSSStyleSheet(Node* ownerNode, const String& href, const String& charset);
a9a6d94
@@ -110,6 +112,7 @@ private:
a9a6d94
     bool m_loadCompleted : 1;
a9a6d94
     bool m_strictParsing : 1;
a9a6d94
     bool m_isUserStyleSheet : 1;
a9a6d94
+    bool m_hasSyntacticallyValidCSSHeader : 1;
a9a6d94
 };
a9a6d94
 
a9a6d94
 } // namespace
a9a6d94
diff -up qt-everywhere-opensource-src-4.6.2/src/3rdparty/webkit/WebCore/dom/ProcessingInstruction.cpp.cve-2010-0051-lax-css-parsing-cross-domain-theft qt-everywhere-opensource-src-4.6.2/src/3rdparty/webkit/WebCore/dom/ProcessingInstruction.cpp
a9a6d94
--- qt-everywhere-opensource-src-4.6.2/src/3rdparty/webkit/WebCore/dom/ProcessingInstruction.cpp.cve-2010-0051-lax-css-parsing-cross-domain-theft	2010-02-11 16:55:19.000000000 +0100
a9a6d94
+++ qt-everywhere-opensource-src-4.6.2/src/3rdparty/webkit/WebCore/dom/ProcessingInstruction.cpp	2010-02-25 17:07:29.118741824 +0100
a9a6d94
@@ -203,7 +203,10 @@ void ProcessingInstruction::setCSSStyleS
a9a6d94
 #endif
a9a6d94
     RefPtr<CSSStyleSheet> newSheet = CSSStyleSheet::create(this, url, charset);
a9a6d94
     m_sheet = newSheet;
a9a6d94
-    parseStyleSheet(sheet->sheetText());
a9a6d94
+    // We don't need the cross-origin security check here because we are
a9a6d94
+    // getting the sheet text in "strict" mode. This enforces a valid CSS MIME
a9a6d94
+    // type.
a9a6d94
+    parseStyleSheet(sheet->sheetText(true));
a9a6d94
     newSheet->setTitle(m_title);
a9a6d94
     newSheet->setMedia(MediaList::create(newSheet.get(), m_media));
a9a6d94
     newSheet->setDisabled(m_alternate);
a9a6d94
diff -up qt-everywhere-opensource-src-4.6.2/src/3rdparty/webkit/WebCore/html/HTMLLinkElement.cpp.cve-2010-0051-lax-css-parsing-cross-domain-theft qt-everywhere-opensource-src-4.6.2/src/3rdparty/webkit/WebCore/html/HTMLLinkElement.cpp
a9a6d94
--- qt-everywhere-opensource-src-4.6.2/src/3rdparty/webkit/WebCore/html/HTMLLinkElement.cpp.cve-2010-0051-lax-css-parsing-cross-domain-theft	2010-02-11 16:55:17.000000000 +0100
a9a6d94
+++ qt-everywhere-opensource-src-4.6.2/src/3rdparty/webkit/WebCore/html/HTMLLinkElement.cpp	2010-02-25 17:07:29.119741915 +0100
a9a6d94
@@ -260,14 +260,27 @@ void HTMLLinkElement::setCSSStyleSheet(c
a9a6d94
     bool strictParsing = !document()->inCompatMode();
a9a6d94
     bool enforceMIMEType = strictParsing;
a9a6d94
 
a9a6d94
+    bool crossOriginCSS = false;
a9a6d94
+    bool validMIMEType = false;
a9a6d94
     // Check to see if we should enforce the MIME type of the CSS resource in strict mode.
a9a6d94
     // Running in iWeb 2 is one example of where we don't want to - <rdar://problem/6099748>
a9a6d94
     if (enforceMIMEType && document()->page() && !document()->page()->settings()->enforceCSSMIMETypeInStrictMode())
a9a6d94
         enforceMIMEType = false;
a9a6d94
 
a9a6d94
-    String sheetText = sheet->sheetText(enforceMIMEType);
a9a6d94
+    String sheetText = sheet->sheetText(enforceMIMEType, &validMIMEType);
a9a6d94
     m_sheet->parseString(sheetText, strictParsing);
a9a6d94
 
a9a6d94
+    // If we're loading a stylesheet cross-origin, and the MIME type is not
a9a6d94
+    // standard, require the CSS to at least start with a syntactically
a9a6d94
+    // valid CSS rule.
a9a6d94
+    // This prevents an attacker playing games by injecting CSS strings into
a9a6d94
+    // HTML, XML, JSON, etc. etc.
a9a6d94
+    if (!document()->securityOrigin()->canRequest(KURL(ParsedURLString, url)))
a9a6d94
+        crossOriginCSS = true;
a9a6d94
+
a9a6d94
+    if (crossOriginCSS && !validMIMEType && !m_sheet->hasSyntacticallyValidCSSHeader())
a9a6d94
+        m_sheet = CSSStyleSheet::create(this, url, charset);
a9a6d94
+
a9a6d94
     if (strictParsing && document()->settings() && document()->settings()->needsSiteSpecificQuirks()) {
a9a6d94
         // Work around <https://bugs.webkit.org/show_bug.cgi?id=28350>.
a9a6d94
         DEFINE_STATIC_LOCAL(const String, slashKHTMLFixesDotCss, ("/KHTMLFixes.css"));
a9a6d94
diff -up qt-everywhere-opensource-src-4.6.2/src/3rdparty/webkit/WebCore/loader/CachedCSSStyleSheet.cpp.cve-2010-0051-lax-css-parsing-cross-domain-theft qt-everywhere-opensource-src-4.6.2/src/3rdparty/webkit/WebCore/loader/CachedCSSStyleSheet.cpp
a9a6d94
--- qt-everywhere-opensource-src-4.6.2/src/3rdparty/webkit/WebCore/loader/CachedCSSStyleSheet.cpp.cve-2010-0051-lax-css-parsing-cross-domain-theft	2010-02-11 16:55:19.000000000 +0100
a9a6d94
+++ qt-everywhere-opensource-src-4.6.2/src/3rdparty/webkit/WebCore/loader/CachedCSSStyleSheet.cpp	2010-02-25 17:07:29.119741915 +0100
a9a6d94
@@ -71,11 +71,11 @@ String CachedCSSStyleSheet::encoding() c
a9a6d94
     return m_decoder->encoding().name();
a9a6d94
 }
a9a6d94
     
a9a6d94
-const String CachedCSSStyleSheet::sheetText(bool enforceMIMEType) const 
a9a6d94
+const String CachedCSSStyleSheet::sheetText(bool enforceMIMEType, bool* hasValidMIMEType) const 
a9a6d94
 { 
a9a6d94
     ASSERT(!isPurgeable());
a9a6d94
 
a9a6d94
-    if (!m_data || m_data->isEmpty() || !canUseSheet(enforceMIMEType))
a9a6d94
+    if (!m_data || m_data->isEmpty() || !canUseSheet(enforceMIMEType, hasValidMIMEType))
a9a6d94
         return String();
a9a6d94
     
a9a6d94
     if (!m_decodedSheetText.isNull())
a9a6d94
@@ -122,12 +122,12 @@ void CachedCSSStyleSheet::error()
a9a6d94
     checkNotify();
a9a6d94
 }
a9a6d94
 
a9a6d94
-bool CachedCSSStyleSheet::canUseSheet(bool enforceMIMEType) const
a9a6d94
+bool CachedCSSStyleSheet::canUseSheet(bool enforceMIMEType, bool* hasValidMIMEType) const
a9a6d94
 {
a9a6d94
     if (errorOccurred())
a9a6d94
         return false;
a9a6d94
         
a9a6d94
-    if (!enforceMIMEType)
a9a6d94
+    if (!enforceMIMEType && !hasValidMIMEType)
a9a6d94
         return true;
a9a6d94
 
a9a6d94
     // This check exactly matches Firefox.  Note that we grab the Content-Type
a9a6d94
@@ -138,7 +138,12 @@ bool CachedCSSStyleSheet::canUseSheet(bo
a9a6d94
     // This code defaults to allowing the stylesheet for non-HTTP protocols so
a9a6d94
     // folks can use standards mode for local HTML documents.
a9a6d94
     String mimeType = extractMIMETypeFromMediaType(response().httpHeaderField("Content-Type"));
a9a6d94
-    return mimeType.isEmpty() || equalIgnoringCase(mimeType, "text/css") || equalIgnoringCase(mimeType, "application/x-unknown-content-type");
a9a6d94
+    bool typeOK = mimeType.isEmpty() || equalIgnoringCase(mimeType, "text/css") || equalIgnoringCase(mimeType, "application/x-unknown-content-type");
a9a6d94
+    if (hasValidMIMEType)
a9a6d94
+        *hasValidMIMEType = typeOK;
a9a6d94
+    if (!enforceMIMEType)
a9a6d94
+        return true;
a9a6d94
+    return typeOK;
a9a6d94
 }
a9a6d94
  
a9a6d94
 }
a9a6d94
diff -up qt-everywhere-opensource-src-4.6.2/src/3rdparty/webkit/WebCore/loader/CachedCSSStyleSheet.h.cve-2010-0051-lax-css-parsing-cross-domain-theft qt-everywhere-opensource-src-4.6.2/src/3rdparty/webkit/WebCore/loader/CachedCSSStyleSheet.h
a9a6d94
--- qt-everywhere-opensource-src-4.6.2/src/3rdparty/webkit/WebCore/loader/CachedCSSStyleSheet.h.cve-2010-0051-lax-css-parsing-cross-domain-theft	2010-02-11 16:55:19.000000000 +0100
a9a6d94
+++ qt-everywhere-opensource-src-4.6.2/src/3rdparty/webkit/WebCore/loader/CachedCSSStyleSheet.h	2010-02-25 17:07:29.120741848 +0100
a9a6d94
@@ -40,7 +40,7 @@ namespace WebCore {
a9a6d94
         CachedCSSStyleSheet(const String& URL, const String& charset);
a9a6d94
         virtual ~CachedCSSStyleSheet();
a9a6d94
 
a9a6d94
-        const String sheetText(bool enforceMIMEType = true) const;
a9a6d94
+        const String sheetText(bool enforceMIMEType = true, bool* hasValidMIMEType = 0) const;
a9a6d94
 
a9a6d94
         virtual void didAddClient(CachedResourceClient*);
a9a6d94
         
a9a6d94
@@ -56,7 +56,7 @@ namespace WebCore {
a9a6d94
         void checkNotify();
a9a6d94
     
a9a6d94
     private:
a9a6d94
-        bool canUseSheet(bool enforceMIMEType) const;
a9a6d94
+        bool canUseSheet(bool enforceMIMEType, bool* hasValidMIMEType) const;
a9a6d94
 
a9a6d94
     protected:
a9a6d94
         RefPtr<TextResourceDecoder> m_decoder;