Index: Source/core/fetch/ResourceFetcher.cpp |
diff --git a/Source/core/fetch/ResourceFetcher.cpp b/Source/core/fetch/ResourceFetcher.cpp |
index 3bd9550a71935ed145041bc6ca7088ad3d98d5df..a26fc5e1c3c340886b4d31ba3092c2c4bc34d1c6 100644 |
--- a/Source/core/fetch/ResourceFetcher.cpp |
+++ b/Source/core/fetch/ResourceFetcher.cpp |
@@ -1336,7 +1336,14 @@ void ResourceFetcher::willSendRequest(unsigned long identifier, ResourceRequest& |
void ResourceFetcher::didReceiveResponse(const Resource* resource, const ResourceResponse& response) |
{ |
- // FIXME: When response.wasFetchedViaServiceWorker() is true, we need to check the URL of the responce for CSP and CORS. |
+ // If the response is fetched via ServiceWorker, the original URL of the response could be different from the URL of the request. |
+ if (response.wasFetchedViaServiceWorker()) { |
+ if (!canRequest(resource->type(), response.url(), resource->options(), false, FetchRequest::UseDefaultOriginRestrictionForType)) { |
+ resource->loader()->cancel(); |
+ context().dispatchDidFail(m_documentLoader, resource->identifier(), ResourceError(errorDomainBlinkInternal, 0, response.url().string(), "Unsafe attempt to load URL " + response.url().elidedString() + " fetched by a ServiceWorker.")); |
+ return; |
+ } |
+ } |
context().dispatchDidReceiveResponse(m_documentLoader, resource->identifier(), response, resource->loader()); |
} |