Bug 1499000 - Don't do CORS checks on CSS images with the resource:// scheme. r=bzbarsky
authorEmilio Cobos Álvarez <emilio@crisal.io>
Fri, 09 Aug 2019 18:09:55 +0000
changeset 550971 ebfc262470877db1b992ea55032d550dec4f5642
parent 550970 b60857a1f7a9f9f79dcdb246f5629f8119ba209d
child 550972 f2f738d7b414c2338155c73fa46ac3c25b6aea1e
push id2165
push userffxbld-merge
push dateMon, 14 Oct 2019 16:30:58 +0000
treeherdermozilla-release@0eae18af659f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs1499000, 1565509
milestone70.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1499000 - Don't do CORS checks on CSS images with the resource:// scheme. r=bzbarsky CORS only works on http channels, so anything else that tries to do a CORS-enabled request fails catastrophically. resource:// images are useful for extension developers, so don't perform CORS checks on them. We may want to also do file:// and fix bug 1565509, while at it, if we consider it's causing developer pain. Differential Revision: https://phabricator.services.mozilla.com/D40651
layout/reftests/svg/mask-resource-ref.html
layout/reftests/svg/mask-resource.html
layout/reftests/svg/reftest.list
layout/style/ImageLoader.cpp
layout/style/ServoStyleConstsInlines.h
servo/ports/geckolib/cbindgen.toml
new file mode 100644
--- /dev/null
+++ b/layout/reftests/svg/mask-resource-ref.html
@@ -0,0 +1,11 @@
+<!doctype html>
+<style>
+  div {
+    width: 100px;
+    height: 100px;
+    background-image: url(resource://usercontext-content/fingerprint.svg);
+    background-size: 100px 100px;
+    background-color: white;
+  }
+</style>
+<div></div>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/svg/mask-resource.html
@@ -0,0 +1,11 @@
+<!doctype html>
+<style>
+  div {
+    width: 100px;
+    height: 100px;
+    mask-image: url(resource://usercontext-content/fingerprint.svg);
+    mask-size: 100px 100px;
+    background-color: black;
+  }
+</style>
+<div></div>
--- a/layout/reftests/svg/reftest.list
+++ b/layout/reftests/svg/reftest.list
@@ -580,8 +580,11 @@ random-if(/^Windows\x20NT\x206\.1/.test(
 random-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)) skip-if(geckoview&&webrender) == fragid-shadow-3.html fragid-shadow-ref.html # Bug 1392106, bug 1560367 for GV+WR
 random-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)) skip-if(geckoview&&webrender) == fragid-shadow-4.html fragid-shadow-ref.html # Bug 1392106, bug 1560367 for GV+WR
 random-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)) skip-if(geckoview&&webrender) == fragid-shadow-5.html fragid-shadow-ref.html # Bug 1392106, bug 1560367 for GV+WR
 random-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)) skip-if(geckoview&&webrender) == fragid-shadow-6.html fragid-shadow-ref.html # Bug 1392106, bug 1560367 for GV+WR
 random-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)) skip-if(geckoview&&webrender) == fragid-shadow-7.html fragid-shadow-ref.html # Bug 1392106, bug 1560367 for GV+WR
 random-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)) skip-if(geckoview&&webrender) == fragid-shadow-8.html fragid-shadow-ref.html # Bug 1392106, bug 1560367 for GV+WR
 random-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)) skip-if(geckoview&&webrender) == fragid-shadow-9.html fragid-shadow-ref.html # Bug 1392106, bug 1560367 for GV+WR
 random-if(/^Windows\x20NT\x206\.1/.test(http.oscpu)) skip-if(geckoview&&webrender) == fragid-shadow-10.html fragid-shadow-ref.html # Bug 1392106, bug 1560367 for GV+WR
+
+== mask-resource.html mask-resource-ref.html
+!= mask-resource.html about:blank
--- a/layout/style/ImageLoader.cpp
+++ b/layout/style/ImageLoader.cpp
@@ -414,16 +414,30 @@ void ImageLoader::ClearFrames(nsPresCont
       nsLayoutUtils::DeregisterImageRequest(aPresContext, request, nullptr);
     }
   }
 
   mRequestToFrameMap.Clear();
   mFrameToRequestMap.Clear();
 }
 
+static CORSMode EffectiveCorsMode(nsIURI* aURI,
+                                  const StyleComputedImageUrl& aImage) {
+  MOZ_ASSERT(aURI);
+  StyleCorsMode mode = aImage.CorsMode();
+  if (mode == StyleCorsMode::None) {
+    return CORSMode::CORS_NONE;
+  }
+  MOZ_ASSERT(mode == StyleCorsMode::Anonymous);
+  if (aURI->SchemeIs("resource")) {
+    return CORSMode::CORS_NONE;
+  }
+  return CORSMode::CORS_ANONYMOUS;
+}
+
 /* static */
 void ImageLoader::LoadImage(const StyleComputedImageUrl& aImage,
                             Document& aLoadingDoc) {
   MOZ_ASSERT(NS_IsMainThread());
   uint64_t loadId = aImage.LoadData().load_id;
   if (loadId == 0) {
     MOZ_ASSERT_UNREACHABLE("Image should have a valid LoadID");
     return;
@@ -442,17 +456,17 @@ void ImageLoader::LoadImage(const StyleC
 
   nsIURI* uri = aImage.GetURI();
   if (!uri) {
     return;
   }
 
   int32_t loadFlags =
       nsIRequest::LOAD_NORMAL |
-      nsContentUtils::CORSModeToLoadImageFlags(aImage.CorsMode());
+      nsContentUtils::CORSModeToLoadImageFlags(EffectiveCorsMode(uri, aImage));
 
   const URLExtraData& data = aImage.ExtraData();
 
   RefPtr<imgRequestProxy> request;
   nsresult rv = nsContentUtils::LoadImage(
       uri, &aLoadingDoc, &aLoadingDoc, data.Principal(), 0, data.ReferrerInfo(),
       nullptr, loadFlags, NS_LITERAL_STRING("css"), getter_AddRefs(request));
 
--- a/layout/style/ServoStyleConstsInlines.h
+++ b/layout/style/ServoStyleConstsInlines.h
@@ -348,26 +348,18 @@ inline nsDependentCSubstring StyleComput
   return _0.SpecifiedSerialization();
 }
 inline const URLExtraData& StyleComputedUrl::ExtraData() const {
   return _0.ExtraData();
 }
 inline StyleLoadData& StyleComputedUrl::LoadData() const {
   return _0.LoadData();
 }
-inline CORSMode StyleComputedUrl::CorsMode() const {
-  switch (_0._0->cors_mode) {
-    case StyleCorsMode::Anonymous:
-      return CORSMode::CORS_ANONYMOUS;
-    case StyleCorsMode::None:
-      return CORSMode::CORS_NONE;
-    default:
-      MOZ_ASSERT_UNREACHABLE("Unknown cors-mode from style?");
-      return CORSMode::CORS_NONE;
-  }
+inline StyleCorsMode StyleComputedUrl::CorsMode() const {
+  return _0._0->cors_mode;
 }
 inline nsIURI* StyleComputedUrl::GetURI() const { return _0.GetURI(); }
 
 inline bool StyleComputedUrl::IsLocalRef() const {
   return Servo_CssUrl_IsLocalRef(&_0);
 }
 
 inline bool StyleComputedUrl::HasRef() const {
--- a/servo/ports/geckolib/cbindgen.toml
+++ b/servo/ports/geckolib/cbindgen.toml
@@ -596,17 +596,17 @@ renaming_overrides_prefixing = true
   // Forwarded from CssUrl.
   inline nsDependentCSubstring SpecifiedSerialization() const;
   inline const URLExtraData& ExtraData() const;
   inline nsIURI* GetURI() const;
   inline StyleLoadData& LoadData() const;
 
   inline bool IsLocalRef() const;
   inline bool HasRef() const;
-  inline CORSMode CorsMode() const;
+  inline StyleCorsMode CorsMode() const;
   already_AddRefed<nsIURI> ResolveLocalRef(nsIURI* aBase) const;
   already_AddRefed<nsIURI> ResolveLocalRef(const nsIContent* aContent) const;
   imgRequestProxy* LoadImage(mozilla::dom::Document&);
 """
 
 "GenericGradient" = """
   bool IsOpaque() const;
 """