diff --git a/dom/base/EventSource.cpp b/dom/base/EventSource.cpp index d39d3d996f..ac2095b51a 100644 --- a/dom/base/EventSource.cpp +++ b/dom/base/EventSource.cpp @@ -796,7 +796,7 @@ EventSource::InitChannelAndRequestEventSource() nsRefPtr listener = new nsCORSListenerProxy(this, mPrincipal, mWithCredentials); - rv = listener->Init(mHttpChannel); + rv = listener->Init(mHttpChannel, DataURIHandling::Allow); NS_ENSURE_SUCCESS(rv, rv); // Start reading from the channel diff --git a/dom/base/ImportManager.cpp b/dom/base/ImportManager.cpp index 9ccab96095..db4b432f6d 100644 --- a/dom/base/ImportManager.cpp +++ b/dom/base/ImportManager.cpp @@ -504,7 +504,7 @@ ImportLoader::Open() nsRefPtr corsListener = new nsCORSListenerProxy(this, principal, /* aWithCredentials */ false); - rv = corsListener->Init(channel, true); + rv = corsListener->Init(channel, DataURIHandling::Allow); NS_ENSURE_SUCCESS_VOID(rv); rv = channel->AsyncOpen(corsListener, nullptr); diff --git a/dom/base/Navigator.cpp b/dom/base/Navigator.cpp index c8ddcf72f9..142dfa40bd 100644 --- a/dom/base/Navigator.cpp +++ b/dom/base/Navigator.cpp @@ -1201,7 +1201,7 @@ Navigator::SendBeacon(const nsAString& aUrl, principal, true); - rv = cors->Init(channel, true); + rv = cors->Init(channel, DataURIHandling::Allow); NS_ENSURE_SUCCESS(rv, false); // Start a preflight if cross-origin and content type is not whitelisted diff --git a/dom/base/nsScriptLoader.cpp b/dom/base/nsScriptLoader.cpp index 7fd66a5ee0..6f6adc6d0e 100644 --- a/dom/base/nsScriptLoader.cpp +++ b/dom/base/nsScriptLoader.cpp @@ -367,7 +367,7 @@ nsScriptLoader::StartLoad(nsScriptLoadRequest *aRequest, const nsAString &aType, nsRefPtr corsListener = new nsCORSListenerProxy(listener, mDocument->NodePrincipal(), withCredentials); - rv = corsListener->Init(channel); + rv = corsListener->Init(channel, DataURIHandling::Allow); NS_ENSURE_SUCCESS(rv, rv); listener = corsListener; } diff --git a/dom/base/nsSyncLoadService.cpp b/dom/base/nsSyncLoadService.cpp index f1749a3a6d..9cd3a563df 100644 --- a/dom/base/nsSyncLoadService.cpp +++ b/dom/base/nsSyncLoadService.cpp @@ -189,7 +189,7 @@ nsSyncLoader::LoadDocument(nsIChannel* aChannel, if (aLoaderPrincipal) { nsRefPtr corsListener = new nsCORSListenerProxy(listener, aLoaderPrincipal, false); - rv = corsListener->Init(mChannel); + rv = corsListener->Init(mChannel, DataURIHandling::Disallow); NS_ENSURE_SUCCESS(rv, rv); listener = corsListener; } diff --git a/dom/base/nsXMLHttpRequest.cpp b/dom/base/nsXMLHttpRequest.cpp index a5df20d206..88cf6d908d 100644 --- a/dom/base/nsXMLHttpRequest.cpp +++ b/dom/base/nsXMLHttpRequest.cpp @@ -2932,7 +2932,7 @@ nsXMLHttpRequest::Send(nsIVariant* aVariant, const Nullable& aBody) // a same-origin request right now, since it could be redirected. nsRefPtr corsListener = new nsCORSListenerProxy(listener, mPrincipal, withCredentials); - rv = corsListener->Init(mChannel, true); + rv = corsListener->Init(mChannel, DataURIHandling::Allow); NS_ENSURE_SUCCESS(rv, rv); listener = corsListener; } diff --git a/dom/base/test/mochitest.ini b/dom/base/test/mochitest.ini index 19b14d07ef..97f591f3c8 100644 --- a/dom/base/test/mochitest.ini +++ b/dom/base/test/mochitest.ini @@ -778,3 +778,4 @@ skip-if = buildapp == 'mulet' || buildapp == 'b2g' [test_bug1118689.html] skip-if = buildapp == 'mulet' || buildapp == 'b2g' [test_getAttribute_after_createAttribute.html] +[test_script_loader_crossorigin_data_url.html] diff --git a/dom/base/test/test_script_loader_crossorigin_data_url.html b/dom/base/test/test_script_loader_crossorigin_data_url.html new file mode 100644 index 0000000000..cfbb90c8df --- /dev/null +++ b/dom/base/test/test_script_loader_crossorigin_data_url.html @@ -0,0 +1,38 @@ + + +Test for handling of 'crossorigin' attribute on script with data: URL + + +
+ + + + + + + + + diff --git a/dom/fetch/FetchDriver.cpp b/dom/fetch/FetchDriver.cpp index ad54daf320..39ffec518c 100644 --- a/dom/fetch/FetchDriver.cpp +++ b/dom/fetch/FetchDriver.cpp @@ -472,7 +472,7 @@ FetchDriver::HttpFetch(bool aCORSFlag, bool aCORSPreflightFlag, bool aAuthentica // directly. nsRefPtr corsListener = new nsCORSListenerProxy(this, mPrincipal, useCredentials); - rv = corsListener->Init(chan, true /* allow data uri */); + rv = corsListener->Init(chan, DataURIHandling::Allow); if (NS_WARN_IF(NS_FAILED(rv))) { return FailWithNetworkError(); } diff --git a/dom/html/HTMLMediaElement.cpp b/dom/html/HTMLMediaElement.cpp index 1fbb2af62c..111fb064e3 100644 --- a/dom/html/HTMLMediaElement.cpp +++ b/dom/html/HTMLMediaElement.cpp @@ -1254,7 +1254,7 @@ nsresult HTMLMediaElement::LoadResource() new nsCORSListenerProxy(loadListener, NodePrincipal(), GetCORSMode() == CORS_USE_CREDENTIALS); - rv = corsListener->Init(channel); + rv = corsListener->Init(channel, DataURIHandling::Allow); NS_ENSURE_SUCCESS(rv, rv); listener = corsListener; } else { diff --git a/dom/media/MediaResource.cpp b/dom/media/MediaResource.cpp index 956776c03a..48319f8872 100644 --- a/dom/media/MediaResource.cpp +++ b/dom/media/MediaResource.cpp @@ -619,7 +619,7 @@ nsresult ChannelMediaResource::OpenChannel(nsIStreamListener** aStreamListener) element->NodePrincipal(), false); NS_ENSURE_TRUE(crossSiteListener, NS_ERROR_OUT_OF_MEMORY); - rv = crossSiteListener->Init(mChannel); + rv = crossSiteListener->Init(mChannel, DataURIHandling::Allow); NS_ENSURE_SUCCESS(rv, rv); listener = crossSiteListener; } else { diff --git a/dom/security/nsCORSListenerProxy.cpp b/dom/security/nsCORSListenerProxy.cpp index 7af43f5df2..a533f5664e 100644 --- a/dom/security/nsCORSListenerProxy.cpp +++ b/dom/security/nsCORSListenerProxy.cpp @@ -467,7 +467,7 @@ nsCORSListenerProxy::~nsCORSListenerProxy() } nsresult -nsCORSListenerProxy::Init(nsIChannel* aChannel, bool aAllowDataURI) +nsCORSListenerProxy::Init(nsIChannel* aChannel, DataURIHandling aAllowDataURI) { aChannel->GetNotificationCallbacks(getter_AddRefs(mOuterNotificationCallbacks)); aChannel->SetNotificationCallbacks(this); @@ -780,7 +780,7 @@ nsCORSListenerProxy::OnRedirectVerifyCallback(nsresult result) NS_ASSERTION(mNewRedirectChannel, "mNewRedirectChannel not set in callback"); if (NS_SUCCEEDED(result)) { - nsresult rv = UpdateChannel(mNewRedirectChannel); + nsresult rv = UpdateChannel(mNewRedirectChannel, DataURIHandling::Disallow); if (NS_FAILED(rv)) { NS_WARNING("nsCORSListenerProxy::OnRedirectVerifyCallback: " "UpdateChannel() returned failure"); @@ -800,7 +800,8 @@ nsCORSListenerProxy::OnRedirectVerifyCallback(nsresult result) } nsresult -nsCORSListenerProxy::UpdateChannel(nsIChannel* aChannel, bool aAllowDataURI) +nsCORSListenerProxy::UpdateChannel(nsIChannel* aChannel, + DataURIHandling aAllowDataURI) { nsCOMPtr uri, originalURI; nsresult rv = NS_GetFinalChannelURI(aChannel, getter_AddRefs(uri)); @@ -809,7 +810,7 @@ nsCORSListenerProxy::UpdateChannel(nsIChannel* aChannel, bool aAllowDataURI) NS_ENSURE_SUCCESS(rv, rv); // exempt data URIs from the same origin check. - if (aAllowDataURI && originalURI == uri) { + if (aAllowDataURI == DataURIHandling::Allow && originalURI == uri) { bool dataScheme = false; rv = uri->SchemeIs("data", &dataScheme); NS_ENSURE_SUCCESS(rv, rv); @@ -1208,7 +1209,7 @@ NS_StartCORSPreflight(nsIChannel* aRequestChannel, new nsCORSListenerProxy(preflightListener, aPrincipal, aWithCredentials, method, aUnsafeHeaders); - rv = corsListener->Init(preflightChannel); + rv = corsListener->Init(preflightChannel, DataURIHandling::Disallow); NS_ENSURE_SUCCESS(rv, rv); preflightListener = corsListener; diff --git a/dom/security/nsCORSListenerProxy.h b/dom/security/nsCORSListenerProxy.h index c7aa804b9c..45cc9b13f7 100644 --- a/dom/security/nsCORSListenerProxy.h +++ b/dom/security/nsCORSListenerProxy.h @@ -29,6 +29,12 @@ NS_StartCORSPreflight(nsIChannel* aRequestChannel, nsTArray& aACUnsafeHeaders, nsIChannel** aPreflightChannel); +enum class DataURIHandling +{ + Allow, + Disallow +}; + class nsCORSListenerProxy final : public nsIStreamListener, public nsIInterfaceRequestor, public nsIChannelEventSink, @@ -56,12 +62,12 @@ public: static void Shutdown(); - nsresult Init(nsIChannel* aChannel, bool aAllowDataURI = false); + nsresult Init(nsIChannel* aChannel, DataURIHandling aAllowDataURI); private: ~nsCORSListenerProxy(); - nsresult UpdateChannel(nsIChannel* aChannel, bool aAllowDataURI = false); + nsresult UpdateChannel(nsIChannel* aChannel, DataURIHandling aAllowDataURI); nsresult CheckRequestApproved(nsIRequest* aRequest); nsCOMPtr mOuterListener; diff --git a/dom/xslt/xslt/txMozillaStylesheetCompiler.cpp b/dom/xslt/xslt/txMozillaStylesheetCompiler.cpp index 3ef40f9fb1..b65753e4c3 100644 --- a/dom/xslt/xslt/txMozillaStylesheetCompiler.cpp +++ b/dom/xslt/xslt/txMozillaStylesheetCompiler.cpp @@ -505,7 +505,7 @@ txCompileObserver::startLoad(nsIURI* aUri, txStylesheetCompiler* aCompiler, // Always install in case of redirects nsRefPtr listener = new nsCORSListenerProxy(sink, aReferrerPrincipal, false); - rv = listener->Init(channel); + rv = listener->Init(channel, DataURIHandling::Disallow); NS_ENSURE_SUCCESS(rv, rv); return channel->AsyncOpen(listener, parser); diff --git a/image/src/imgLoader.cpp b/image/src/imgLoader.cpp index c9d888f6eb..b6433a79da 100644 --- a/image/src/imgLoader.cpp +++ b/image/src/imgLoader.cpp @@ -1525,7 +1525,7 @@ bool imgLoader::ValidateRequestWithNewChannel(imgRequest *request, bool withCredentials = aCORSMode == imgIRequest::CORS_USE_CREDENTIALS; nsRefPtr corsproxy = new nsCORSListenerProxy(listener, aLoadingPrincipal, withCredentials); - rv = corsproxy->Init(newChannel); + rv = corsproxy->Init(newChannel, DataURIHandling::Allow); if (NS_FAILED(rv)) { return false; } @@ -2071,7 +2071,7 @@ nsresult imgLoader::LoadImage(nsIURI *aURI, nsRefPtr corsproxy = new nsCORSListenerProxy(pl, aLoadingPrincipal, withCredentials); - rv = corsproxy->Init(newChannel); + rv = corsproxy->Init(newChannel, DataURIHandling::Allow); if (NS_FAILED(rv)) { PR_LOG(GetImgLog(), PR_LOG_DEBUG, ("[this=%p] imgLoader::LoadImage -- nsCORSListenerProxy " diff --git a/image/test/mochitest/mochitest.ini b/image/test/mochitest/mochitest.ini index 561e6381e8..2df7690b7e 100644 --- a/image/test/mochitest/mochitest.ini +++ b/image/test/mochitest/mochitest.ini @@ -95,3 +95,4 @@ skip-if = toolkit == "gonk" #Bug 997034 - canvas.toDataURL() often causes lost c [test_image_buffer_limit.html] #run-if = toolkit == "gonk" #Image buffer limit is only set for Firefox OS currently. disabled = bug 1060869 +[test_image_crossorigin_data_url.html] diff --git a/image/test/mochitest/test_image_crossorigin_data_url.html b/image/test/mochitest/test_image_crossorigin_data_url.html new file mode 100644 index 0000000000..9facc00d42 --- /dev/null +++ b/image/test/mochitest/test_image_crossorigin_data_url.html @@ -0,0 +1,27 @@ + + +Test for handling of 'crossorigin' attribute on CSS link with data: URL + + +
+
+ + diff --git a/layout/style/FontFaceSet.cpp b/layout/style/FontFaceSet.cpp index 817c44492e..ac5ce946c8 100644 --- a/layout/style/FontFaceSet.cpp +++ b/layout/style/FontFaceSet.cpp @@ -462,7 +462,9 @@ FontFaceSet::StartLoad(gfxUserFontEntry* aUserFontEntry, } else { nsRefPtr listener = new nsCORSListenerProxy(streamLoader, aUserFontEntry->GetPrincipal(), false); - rv = listener->Init(channel); + // Doesn't matter what data: URI handling we use here, since we + // don't even use a CORS listener proxy for the data: case. + rv = listener->Init(channel, DataURIHandling::Disallow); if (NS_SUCCEEDED(rv)) { rv = channel->AsyncOpen(listener, nullptr); } diff --git a/layout/style/Loader.cpp b/layout/style/Loader.cpp index bb25e35631..4a70c32740 100644 --- a/layout/style/Loader.cpp +++ b/layout/style/Loader.cpp @@ -1670,7 +1670,7 @@ Loader::LoadSheet(SheetLoadData* aLoadData, StyleSheetState aSheetState) nsRefPtr corsListener = new nsCORSListenerProxy(streamLoader, aLoadData->mLoaderPrincipal, withCredentials); - rv = corsListener->Init(channel); + rv = corsListener->Init(channel, DataURIHandling::Allow); if (NS_FAILED(rv)) { #ifdef DEBUG mSyncCallback = false; diff --git a/layout/style/test/mochitest.ini b/layout/style/test/mochitest.ini index 133f9c4a24..96930b6da4 100644 --- a/layout/style/test/mochitest.ini +++ b/layout/style/test/mochitest.ini @@ -261,3 +261,4 @@ support-files = bug732209-css.sjs [test_animations_async_tests.html] support-files = ../../reftests/fonts/Ahem.ttf [test_setPropertyWithNull.html] +[test_css_loader_crossorigin_data_url.html] diff --git a/layout/style/test/test_css_loader_crossorigin_data_url.html b/layout/style/test/test_css_loader_crossorigin_data_url.html new file mode 100644 index 0000000000..67105d61f0 --- /dev/null +++ b/layout/style/test/test_css_loader_crossorigin_data_url.html @@ -0,0 +1,17 @@ + + +Test for handling of 'crossorigin' attribute on CSS link with data: URL + + + +
+
+