Title: [216195] trunk
Revision
216195
Author
[email protected]
Date
2017-05-04 11:25:39 -0700 (Thu, 04 May 2017)

Log Message

importScripts() should respect X-Content-Type-Options: nosniff
https://bugs.webkit.org/show_bug.cgi?id=171248
<rdar://problem/31819023>

Reviewed by Andy Estes.

LayoutTests/imported/w3c:

Update expected results for Web Platform Tests that now pass.

* web-platform-tests/fetch/nosniff/importscripts-expected.txt: Added.
* web-platform-tests/fetch/nosniff/worker-expected.txt:

Source/WebCore:

Do not load a worker script if it has the HTTP response header "X-Content-Type-Options: nosniff"
and its Content-type header is not an allowed _javascript_ script mime type. This behavior follows
from <https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-classic-worker-imported-script> (3 May 2017),
<https://fetch.spec.whatwg.org/#concept-fetch> (2 May 2017), and <https://fetch.spec.whatwg.org/#concept-main-fetch>.

* workers/WorkerScriptLoader.cpp:
(WebCore::mimeTypeAllowedByNosniff): Added.
(WebCore::WorkerScriptLoader::didReceiveResponse): Mark the load as failed if the response
is not allowed by X-Content-Type-Options: nosniff.

LayoutTests:

Unskip web-platform-tests/fetch/nosniff/importscripts as it now passes.

* TestExpectations:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (216194 => 216195)


--- trunk/LayoutTests/ChangeLog	2017-05-04 18:02:46 UTC (rev 216194)
+++ trunk/LayoutTests/ChangeLog	2017-05-04 18:25:39 UTC (rev 216195)
@@ -1,3 +1,15 @@
+2017-05-04  Daniel Bates  <[email protected]>
+
+        importScripts() should respect X-Content-Type-Options: nosniff
+        https://bugs.webkit.org/show_bug.cgi?id=171248
+        <rdar://problem/31819023>
+
+        Reviewed by Andy Estes.
+
+        Unskip web-platform-tests/fetch/nosniff/importscripts as it now passes.
+
+        * TestExpectations:
+
 2017-05-04  Said Abou-Hallawa  <[email protected]>
 
         Unreviewed: Replace Windows line ending (CRLF) by Unix line ending (CR).

Modified: trunk/LayoutTests/TestExpectations (216194 => 216195)


--- trunk/LayoutTests/TestExpectations	2017-05-04 18:02:46 UTC (rev 216194)
+++ trunk/LayoutTests/TestExpectations	2017-05-04 18:25:39 UTC (rev 216195)
@@ -1298,6 +1298,4 @@
 
 webkit.org/b/170701 webrtc/datachannel/bufferedAmountLowThreshold.html [ Pass Failure ]
 
-webkit.org/b/171248 imported/w3c/web-platform-tests/fetch/nosniff/importscripts.html
-
 webkit.org/b/170835 fast/mediacapturefromelement/CanvasCaptureMediaStream-2d-events.html [ Pass Failure ]

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (216194 => 216195)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2017-05-04 18:02:46 UTC (rev 216194)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2017-05-04 18:25:39 UTC (rev 216195)
@@ -1,3 +1,16 @@
+2017-05-04  Daniel Bates  <[email protected]>
+
+        importScripts() should respect X-Content-Type-Options: nosniff
+        https://bugs.webkit.org/show_bug.cgi?id=171248
+        <rdar://problem/31819023>
+
+        Reviewed by Andy Estes.
+
+        Update expected results for Web Platform Tests that now pass.
+
+        * web-platform-tests/fetch/nosniff/importscripts-expected.txt: Added.
+        * web-platform-tests/fetch/nosniff/worker-expected.txt:
+
 2017-05-02  Ben Kelly <[email protected]>
 
         Set Response.blob() type correctly when body is a ReadableStream.

Added: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/nosniff/importscripts-expected.txt (0 => 216195)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/nosniff/importscripts-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/nosniff/importscripts-expected.txt	2017-05-04 18:25:39 UTC (rev 216195)
@@ -0,0 +1,3 @@
+
+PASS Test importScripts() 
+

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/nosniff/worker-expected.txt (216194 => 216195)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/nosniff/worker-expected.txt	2017-05-04 18:02:46 UTC (rev 216194)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/nosniff/worker-expected.txt	2017-05-04 18:25:39 UTC (rev 216195)
@@ -1,8 +1,8 @@
 
-FAIL URL query:  assert_unreached: Unexpected message event Reached unreachable code
-FAIL URL query: ?type= assert_unreached: Unexpected message event Reached unreachable code
-FAIL URL query: ?type=x assert_unreached: Unexpected message event Reached unreachable code
-FAIL URL query: ?type=x/x assert_unreached: Unexpected message event Reached unreachable code
+PASS URL query:  
+PASS URL query: ?type= 
+PASS URL query: ?type=x 
+PASS URL query: ?type=x/x 
 PASS URL query: ?type=text/_javascript_ 
 PASS URL query: ?type=text/ecmascript 
 PASS URL query: ?type=text/ecmascript;yay 

Modified: trunk/Source/WebCore/ChangeLog (216194 => 216195)


--- trunk/Source/WebCore/ChangeLog	2017-05-04 18:02:46 UTC (rev 216194)
+++ trunk/Source/WebCore/ChangeLog	2017-05-04 18:25:39 UTC (rev 216195)
@@ -1,3 +1,21 @@
+2017-05-04  Daniel Bates  <[email protected]>
+
+        importScripts() should respect X-Content-Type-Options: nosniff
+        https://bugs.webkit.org/show_bug.cgi?id=171248
+        <rdar://problem/31819023>
+
+        Reviewed by Andy Estes.
+
+        Do not load a worker script if it has the HTTP response header "X-Content-Type-Options: nosniff"
+        and its Content-type header is not an allowed _javascript_ script mime type. This behavior follows
+        from <https://html.spec.whatwg.org/multipage/webappapis.html#fetch-a-classic-worker-imported-script> (3 May 2017),
+        <https://fetch.spec.whatwg.org/#concept-fetch> (2 May 2017), and <https://fetch.spec.whatwg.org/#concept-main-fetch>.
+
+        * workers/WorkerScriptLoader.cpp:
+        (WebCore::mimeTypeAllowedByNosniff): Added.
+        (WebCore::WorkerScriptLoader::didReceiveResponse): Mark the load as failed if the response
+        is not allowed by X-Content-Type-Options: nosniff.
+
 2017-05-04  Dave Hyatt  <[email protected]>
 
         REGRESSION(STP): rgb() with calc() containing variables doesn't work

Modified: trunk/Source/WebCore/workers/WorkerScriptLoader.cpp (216194 => 216195)


--- trunk/Source/WebCore/workers/WorkerScriptLoader.cpp	2017-05-04 18:02:46 UTC (rev 216194)
+++ trunk/Source/WebCore/workers/WorkerScriptLoader.cpp	2017-05-04 18:25:39 UTC (rev 216195)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 Apple Inc. All Rights Reserved.
+ * Copyright (C) 2009-2017 Apple Inc. All Rights Reserved.
  * Copyright (C) 2009, 2011 Google Inc. All Rights Reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -28,6 +28,8 @@
 #include "WorkerScriptLoader.h"
 
 #include "ContentSecurityPolicy.h"
+#include "HTTPParsers.h"
+#include "MIMETypeRegistry.h"
 #include "ResourceResponse.h"
 #include "ScriptExecutionContext.h"
 #include "TextResourceDecoder.h"
@@ -110,7 +112,15 @@
     request->setInitiatorIdentifier(initiatorIdentifier);
     return request;
 }
-    
+
+#if ENABLE(NOSNIFF)
+static bool mimeTypeAllowedByNosniff(const ResourceResponse& response)
+{
+    String mimeType = extractMIMETypeFromMediaType(response.httpHeaderField(HTTPHeaderName::ContentType));
+    return parseContentTypeOptionsHeader(response.httpHeaderField(HTTPHeaderName::XContentTypeOptions)) != ContentTypeOptionsNosniff || MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType);
+}
+#endif
+
 void WorkerScriptLoader::didReceiveResponse(unsigned long identifier, const ResourceResponse& response)
 {
     if (response.httpStatusCode() / 100 != 2 && response.httpStatusCode()) {
@@ -117,6 +127,14 @@
         m_failed = true;
         return;
     }
+
+#if ENABLE(NOSNIFF)
+    if (!mimeTypeAllowedByNosniff(response)) {
+        m_failed = true;
+        return;
+    }
+#endif
+
     m_responseURL = response.url();
     m_responseEncoding = response.textEncodingName();
     if (m_client)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to