Title: [226275] trunk
- Revision
- 226275
- Author
- [email protected]
- Date
- 2017-12-22 13:23:39 -0800 (Fri, 22 Dec 2017)
Log Message
importScripts() inside a service worker should ensure that the response has a _javascript_ MIME type
https://bugs.webkit.org/show_bug.cgi?id=181103
Reviewed by Youenn Fablet.
LayoutTests/imported/w3c:
Rebaseline WPT test now that it fails later. The test expects that the registration promise be
rejected with a SecurityError. However, we reject it with a TypeError instead, which is the
result of the Network error from importScripts().
The spec does say that importScripts() should report a network error when the MIME type is
invalid:
- https://w3c.github.io/ServiceWorker/#importscripts (step 6)
Later on, the spec says that if "an uncaught runtime script error occurs" when running the script,
we should resolve the registration with a TypeError:
- https://w3c.github.io/ServiceWorker/#update (step 9.6)
Therefore, our behavior seems correct and I cannot find in the spec a reason why the test would
expect a SecurityError here.
* web-platform-tests/service-workers/service-worker/registration-mime-types.https-expected.txt:
Source/WebCore:
importScripts() inside a service worker should ensure that the response has a _javascript_
MIME type, as per:
- https://w3c.github.io/ServiceWorker/#importscripts (step 6)
No new tests, rebaselined existing test.
* workers/WorkerGlobalScope.cpp:
(WebCore::WorkerGlobalScope::importScripts):
* workers/WorkerScriptLoader.cpp:
(WebCore::WorkerScriptLoader::didReceiveResponse):
* workers/WorkerScriptLoader.h:
(WebCore::WorkerScriptLoader::responseMIMEType const):
Modified Paths
Diff
Modified: trunk/LayoutTests/imported/w3c/ChangeLog (226274 => 226275)
--- trunk/LayoutTests/imported/w3c/ChangeLog 2017-12-22 21:17:46 UTC (rev 226274)
+++ trunk/LayoutTests/imported/w3c/ChangeLog 2017-12-22 21:23:39 UTC (rev 226275)
@@ -1,5 +1,29 @@
2017-12-22 Chris Dumez <[email protected]>
+ importScripts() inside a service worker should ensure that the response has a _javascript_ MIME type
+ https://bugs.webkit.org/show_bug.cgi?id=181103
+
+ Reviewed by Youenn Fablet.
+
+ Rebaseline WPT test now that it fails later. The test expects that the registration promise be
+ rejected with a SecurityError. However, we reject it with a TypeError instead, which is the
+ result of the Network error from importScripts().
+
+ The spec does say that importScripts() should report a network error when the MIME type is
+ invalid:
+ - https://w3c.github.io/ServiceWorker/#importscripts (step 6)
+
+ Later on, the spec says that if "an uncaught runtime script error occurs" when running the script,
+ we should resolve the registration with a TypeError:
+ - https://w3c.github.io/ServiceWorker/#update (step 9.6)
+
+ Therefore, our behavior seems correct and I cannot find in the spec a reason why the test would
+ expect a SecurityError here.
+
+ * web-platform-tests/service-workers/service-worker/registration-mime-types.https-expected.txt:
+
+2017-12-22 Chris Dumez <[email protected]>
+
[Service Workers] Implement "Soft Update" algorithm
https://bugs.webkit.org/show_bug.cgi?id=180702
<rdar://problem/36163461>
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/registration-mime-types.https-expected.txt (226274 => 226275)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/registration-mime-types.https-expected.txt 2017-12-22 21:17:46 UTC (rev 226274)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/service-workers/service-worker/registration-mime-types.https-expected.txt 2017-12-22 21:23:39 UTC (rev 226275)
@@ -1,8 +1,8 @@
PASS Registering script with no MIME type
PASS Registering script with bad MIME type
-FAIL Registering script that imports script with no MIME type assert_unreached: Should have rejected: Registration of no MIME type imported script should fail. Reached unreachable code
-FAIL Registering script that imports script with bad MIME type assert_unreached: Should have rejected: Registration of plain text imported script should fail. Reached unreachable code
+FAIL Registering script that imports script with no MIME type assert_throws: Registration of no MIME type imported script should fail. function "function () { throw e }" threw object "TypeError: NetworkError: A network error occurred." that is not a DOMException SecurityError: property "code" is equal to undefined, expected 18
+FAIL Registering script that imports script with bad MIME type assert_throws: Registration of plain text imported script should fail. function "function () { throw e }" threw object "TypeError: NetworkError: A network error occurred." that is not a DOMException SecurityError: property "code" is equal to undefined, expected 18
PASS Registering script with good MIME type application/ecmascript
PASS Registering script that imports script with good MIME type application/ecmascript
PASS Registering script with good MIME type application/_javascript_
Modified: trunk/Source/WebCore/ChangeLog (226274 => 226275)
--- trunk/Source/WebCore/ChangeLog 2017-12-22 21:17:46 UTC (rev 226274)
+++ trunk/Source/WebCore/ChangeLog 2017-12-22 21:23:39 UTC (rev 226275)
@@ -1,5 +1,25 @@
2017-12-22 Chris Dumez <[email protected]>
+ importScripts() inside a service worker should ensure that the response has a _javascript_ MIME type
+ https://bugs.webkit.org/show_bug.cgi?id=181103
+
+ Reviewed by Youenn Fablet.
+
+ importScripts() inside a service worker should ensure that the response has a _javascript_
+ MIME type, as per:
+ - https://w3c.github.io/ServiceWorker/#importscripts (step 6)
+
+ No new tests, rebaselined existing test.
+
+ * workers/WorkerGlobalScope.cpp:
+ (WebCore::WorkerGlobalScope::importScripts):
+ * workers/WorkerScriptLoader.cpp:
+ (WebCore::WorkerScriptLoader::didReceiveResponse):
+ * workers/WorkerScriptLoader.h:
+ (WebCore::WorkerScriptLoader::responseMIMEType const):
+
+2017-12-22 Chris Dumez <[email protected]>
+
[Service Workers] Implement "Soft Update" algorithm
https://bugs.webkit.org/show_bug.cgi?id=180702
<rdar://problem/36163461>
Modified: trunk/Source/WebCore/workers/WorkerGlobalScope.cpp (226274 => 226275)
--- trunk/Source/WebCore/workers/WorkerGlobalScope.cpp 2017-12-22 21:17:46 UTC (rev 226274)
+++ trunk/Source/WebCore/workers/WorkerGlobalScope.cpp 2017-12-22 21:23:39 UTC (rev 226275)
@@ -33,6 +33,7 @@
#include "IDBConnectionProxy.h"
#include "ImageBitmapOptions.h"
#include "InspectorInstrumentation.h"
+#include "MIMETypeRegistry.h"
#include "Performance.h"
#include "ScheduledAction.h"
#include "ScriptSourceCode.h"
@@ -265,8 +266,10 @@
FetchOptions::Cache cachePolicy = FetchOptions::Cache::Default;
#if ENABLE(SERVICE_WORKER)
- if (is<ServiceWorkerGlobalScope>(*this)) {
- // FIXME: Fully implement https://w3c.github.io/ServiceWorker/#importscripts.
+ bool isServiceWorkerGlobalScope = is<ServiceWorkerGlobalScope>(*this);
+ if (isServiceWorkerGlobalScope) {
+ // FIXME: We need to add support for the 'imported scripts updated' flag as per:
+ // https://w3c.github.io/ServiceWorker/#importscripts
auto& serviceWorkerGlobalScope = downcast<ServiceWorkerGlobalScope>(*this);
auto& registration = serviceWorkerGlobalScope.registration();
if (registration.updateViaCache() == ServiceWorkerUpdateViaCache::None || registration.needsUpdate())
@@ -287,6 +290,11 @@
if (scriptLoader->failed())
return Exception { NetworkError };
+#if ENABLE(SERVICE_WORKER)
+ if (isServiceWorkerGlobalScope && !MIMETypeRegistry::isSupportedJavaScriptMIMEType(scriptLoader->responseMIMEType()))
+ return Exception { NetworkError };
+#endif
+
InspectorInstrumentation::scriptImported(*this, scriptLoader->identifier(), scriptLoader->script());
NakedPtr<JSC::Exception> exception;
Modified: trunk/Source/WebCore/workers/WorkerScriptLoader.cpp (226274 => 226275)
--- trunk/Source/WebCore/workers/WorkerScriptLoader.cpp 2017-12-22 21:17:46 UTC (rev 226274)
+++ trunk/Source/WebCore/workers/WorkerScriptLoader.cpp 2017-12-22 21:23:39 UTC (rev 226275)
@@ -132,6 +132,7 @@
}
m_responseURL = response.url();
+ m_responseMIMEType = response.mimeType();
m_responseEncoding = response.textEncodingName();
if (m_client)
m_client->didReceiveResponse(identifier, response);
Modified: trunk/Source/WebCore/workers/WorkerScriptLoader.h (226274 => 226275)
--- trunk/Source/WebCore/workers/WorkerScriptLoader.h 2017-12-22 21:17:46 UTC (rev 226274)
+++ trunk/Source/WebCore/workers/WorkerScriptLoader.h 2017-12-22 21:23:39 UTC (rev 226275)
@@ -60,6 +60,7 @@
String script();
const URL& url() const { return m_url; }
const URL& responseURL() const;
+ const String& responseMIMEType() const { return m_responseMIMEType; }
bool failed() const { return m_failed; }
unsigned long identifier() const { return m_identifier; }
const ResourceError& error() const { return m_error; }
@@ -85,6 +86,7 @@
StringBuilder m_script;
URL m_url;
URL m_responseURL;
+ String m_responseMIMEType;
unsigned long m_identifier { 0 };
bool m_failed { false };
bool m_finishing { false };
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes