Bug 1429127 - Workers should allow the loading of file URLs if they are on the same directory of the loader, r=smaug

This commit is contained in:
Andrea Marchesini 2018-05-03 17:42:58 +02:00
Родитель bc69449ac5
Коммит 34a52976b2
3 изменённых файлов: 31 добавлений и 8 удалений

Просмотреть файл

@ -15,6 +15,7 @@
#include "nsIHttpChannelInternal.h"
#include "nsIInputStreamPump.h"
#include "nsIIOService.h"
#include "nsIOService.h"
#include "nsIProtocolHandler.h"
#include "nsIScriptError.h"
#include "nsIScriptSecurityManager.h"
@ -154,6 +155,18 @@ ChannelFromScriptURL(nsIPrincipal* principal,
uint32_t secFlags = aIsMainScript ? nsILoadInfo::SEC_REQUIRE_SAME_ORIGIN_DATA_IS_BLOCKED
: nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_INHERITS;
bool inheritAttrs = nsContentUtils::ChannelShouldInheritPrincipal(
principal, uri, true /* aInheritForAboutBlank */, false /* aForceInherit */);
bool isData = false;
rv = uri->SchemeIs("data", &isData);
NS_ENSURE_SUCCESS(rv, rv);
bool isURIUniqueOrigin = nsIOService::IsDataURIUniqueOpaqueOrigin() && isData;
if (inheritAttrs && !isURIUniqueOrigin) {
secFlags |= nsILoadInfo::SEC_FORCE_INHERIT_PRINCIPAL;
}
if (aWorkerScriptType == DebuggerScript) {
// A DebuggerScript needs to be a local resource like chrome: or resource:
bool isUIResource = false;
@ -172,8 +185,7 @@ ChannelFromScriptURL(nsIPrincipal* principal,
// Note: this is for backwards compatibility and goes against spec.
// We should find a better solution.
bool isData = false;
if (aIsMainScript && NS_SUCCEEDED(uri->SchemeIs("data", &isData)) && isData) {
if (aIsMainScript && isData) {
secFlags = nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL;
}

Просмотреть файл

@ -16,6 +16,7 @@
#include "nsINetworkInterceptController.h"
#include "nsIProtocolHandler.h"
#include "nsITabChild.h"
#include "nsScriptSecurityManager.h"
#include "nsNetUtil.h"
namespace mozilla {
@ -379,11 +380,20 @@ WorkerLoadInfo::PrincipalURIMatchesScriptURL()
NS_ENSURE_SUCCESS(rv, false);
NS_ENSURE_TRUE(principalURI, false);
bool equal = false;
rv = principalURI->Equals(mBaseURI, &equal);
NS_ENSURE_SUCCESS(rv, false);
if (nsScriptSecurityManager::SecurityCompareURIs(mBaseURI, principalURI)) {
return true;
}
return equal;
// If strict file origin policy is in effect, local files will always fail
// SecurityCompareURIs unless they are identical. Explicitly check file origin
// policy, in that case.
if (nsScriptSecurityManager::GetStrictFileOriginPolicy() &&
NS_URIIsLocalFile(mBaseURI) &&
NS_RelaxStrictFileOriginPolicy(mBaseURI, principalURI)) {
return true;
}
return false;
}
#endif // MOZ_DIAGNOSTIC_ASSERT_ENABLED

Просмотреть файл

@ -67,11 +67,12 @@ UNIFIED_SOURCES += [
]
LOCAL_INCLUDES += [
'../base',
'../system',
'/caps',
'/dom/base',
'/dom/bindings',
'/dom/system',
'/js/xpconnect/loader',
'/netwerk/base',
'/xpcom/build',
'/xpcom/threads',
]