Bug 1655716 - Introduce TYPE_INTERNAL_FETCH_PRELOAD and use in HTMLLinkElement::AsValueToContentPolicy() - r=emilio,mayhemer,ckerschb

Differential Revision: https://phabricator.services.mozilla.com/D85980
This commit is contained in:
Frederik Braun 2020-08-11 12:33:14 +00:00
Родитель c35198fb73
Коммит 6c85c74f16
12 изменённых файлов: 32 добавлений и 8 удалений

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

@ -143,6 +143,7 @@ inline const char* NS_CP_ContentTypeName(uint32_t contentType) {
CASE_RETURN(TYPE_INTERNAL_FONT_PRELOAD);
CASE_RETURN(TYPE_INTERNAL_CHROMEUTILS_COMPILED_SCRIPT);
CASE_RETURN(TYPE_INTERNAL_FRAME_MESSAGEMANAGER_SCRIPT);
CASE_RETURN(TYPE_INTERNAL_FETCH_PRELOAD);
default:
return "<Unknown Type>";
}

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

@ -7971,7 +7971,8 @@ bool nsContentUtils::IsPreloadType(nsContentPolicyType aType) {
aType == nsIContentPolicy::TYPE_INTERNAL_MODULE_PRELOAD ||
aType == nsIContentPolicy::TYPE_INTERNAL_IMAGE_PRELOAD ||
aType == nsIContentPolicy::TYPE_INTERNAL_STYLESHEET_PRELOAD ||
aType == nsIContentPolicy::TYPE_INTERNAL_FONT_PRELOAD);
aType == nsIContentPolicy::TYPE_INTERNAL_FONT_PRELOAD ||
aType == nsIContentPolicy::TYPE_INTERNAL_FETCH_PRELOAD);
}
/* static */

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

@ -3440,6 +3440,9 @@ nsContentUtils::InternalContentPolicyTypeToExternal(nsContentPolicyType aType) {
case nsIContentPolicy::TYPE_INTERNAL_FONT_PRELOAD:
return nsIContentPolicy::TYPE_FONT;
case nsIContentPolicy::TYPE_INTERNAL_FETCH_PRELOAD:
return nsIContentPolicy::TYPE_FETCH;
default:
return aType;
}

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

@ -406,14 +406,23 @@ interface nsIContentPolicy : nsISupports
*/
const nsContentPolicyType TYPE_INTERNAL_CHROMEUTILS_COMPILED_SCRIPT = 52;
/**
* Indicates the load of a script through FrameMessageManager
/**
* Indicates the load of a script through FrameMessageManager
*
* This will be mapped to TYPE_SCRIPT before being passed to content policy
* implementations.
*/
const nsContentPolicyType TYPE_INTERNAL_FRAME_MESSAGEMANAGER_SCRIPT = 53;
/**
* Indicates an internal constant for *preloaded* fetch
* loaded through link elements.
*
* This will be mapped to TYPE_FETCH before being passed
* to content policy implementations.
*/
const nsContentPolicyType TYPE_INTERNAL_FETCH_PRELOAD = 54;
/* When adding new content types, please update
* NS_CP_ContentTypeName, nsCSPContext, CSP_ContentTypeToDirective,
* DoContentSecurityChecks, all nsIContentPolicy implementations, the

3
dom/cache/DBSchema.cpp поставляемый
Просмотреть файл

@ -340,7 +340,8 @@ static_assert(
nsIContentPolicy::TYPE_INTERNAL_PAINTWORKLET == 50 &&
nsIContentPolicy::TYPE_INTERNAL_FONT_PRELOAD == 51 &&
nsIContentPolicy::TYPE_INTERNAL_CHROMEUTILS_COMPILED_SCRIPT == 52 &&
nsIContentPolicy::TYPE_INTERNAL_FRAME_MESSAGEMANAGER_SCRIPT == 53,
nsIContentPolicy::TYPE_INTERNAL_FRAME_MESSAGEMANAGER_SCRIPT == 53 &&
nsIContentPolicy::TYPE_INTERNAL_FETCH_PRELOAD == 54,
"nsContentPolicyType values are as expected");
namespace {

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

@ -290,6 +290,7 @@ RequestDestination InternalRequest::MapContentPolicyTypeToRequestDestination(
destination = RequestDestination::_empty;
break;
case nsIContentPolicy::TYPE_FETCH:
case nsIContentPolicy::TYPE_INTERNAL_FETCH_PRELOAD:
destination = RequestDestination::_empty;
break;
case nsIContentPolicy::TYPE_WEB_MANIFEST:

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

@ -534,7 +534,7 @@ nsContentPolicyType HTMLLinkElement::AsValueToContentPolicy(
case DESTINATION_STYLE:
return nsIContentPolicy::TYPE_STYLESHEET;
case DESTINATION_FETCH:
return nsIContentPolicy::TYPE_OTHER;
return nsIContentPolicy::TYPE_INTERNAL_FETCH_PRELOAD;
}
return nsIContentPolicy::TYPE_INVALID;
}
@ -811,7 +811,7 @@ bool HTMLLinkElement::CheckPreloadAttrs(const nsAttrValue& aAs,
nsString type = nsString(aType);
ToLowerCase(type);
if (policyType == nsIContentPolicy::TYPE_OTHER) {
if (policyType == nsIContentPolicy::TYPE_INTERNAL_FETCH_PRELOAD) {
return true;
}
if (policyType == nsIContentPolicy::TYPE_MEDIA) {

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

@ -94,6 +94,7 @@ nsCString MapInternalContentPolicyTypeToDest(nsContentPolicyType aType) {
case nsIContentPolicy::TYPE_BEACON:
return "empty"_ns;
case nsIContentPolicy::TYPE_FETCH:
case nsIContentPolicy::TYPE_INTERNAL_FETCH_PRELOAD:
return "empty"_ns;
case nsIContentPolicy::TYPE_WEB_MANIFEST:
return "manifest"_ns;

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

@ -295,6 +295,8 @@ CSPDirective CSP_ContentTypeToDirective(nsContentPolicyType aType) {
case nsIContentPolicy::TYPE_BEACON:
case nsIContentPolicy::TYPE_PING:
case nsIContentPolicy::TYPE_FETCH:
case nsIContentPolicy::TYPE_INTERNAL_XMLHTTPREQUEST:
case nsIContentPolicy::TYPE_INTERNAL_FETCH_PRELOAD:
return nsIContentSecurityPolicy::CONNECT_SRC_DIRECTIVE;
case nsIContentPolicy::TYPE_OBJECT:

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

@ -7,6 +7,8 @@
<link rel="preload" as="script" href="fakeServer?script"></link>
<link rel="preload" as="style" href="fakeServer?style"></link>
<link rel="preload" as="image" href="fakeServer?image"></link>
<link rel="preload" as="fetch" href="fakeServer?fetch"></link>
<link rel="preload" as="font" href="fakeServer?font"></link>
<link rel="stylesheet" href="fakeServer?style">
</head>

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

@ -27,9 +27,10 @@ examiner.prototype = {
let asciiSpec = SpecialPowers.getPrivilegedProps(
SpecialPowers.do_QueryInterface(subject, "nsIURI"),
"asciiSpec");
if (asciiSpec.includes("fakeServer?script") ||
asciiSpec.includes("fakeServer?style") ||
asciiSpec.includes("fakeServer?fetch") ||
asciiSpec.includes("fakeServer?font") ||
asciiSpec.includes("fakeServer?image")) {
let type = asciiSpec.substring(asciiSpec.indexOf("?") + 1);
ok (true, type + " should be blocked by CSP");
@ -40,6 +41,8 @@ examiner.prototype = {
if (topic === "specialpowers-http-notify-request") {
if (data.includes("fakeServer?script") ||
data.includes("fakeServer?style") ||
data.includes("fakeServer?fetch") ||
data.includes("fakeServer?font") ||
data.includes("fakeServer?image")) {
let type = data.substring(data.indexOf("?") + 1);
ok (false, type + " should not be loaded");

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

@ -27,7 +27,7 @@ namespace mozilla {
NS_IMPL_ISUPPORTS(FetchPreloader, nsIStreamListener, nsIRequestObserver)
FetchPreloader::FetchPreloader()
: FetchPreloader(nsIContentPolicy::TYPE_INTERNAL_XMLHTTPREQUEST) {}
: FetchPreloader(nsIContentPolicy::TYPE_INTERNAL_FETCH_PRELOAD) {}
FetchPreloader::FetchPreloader(nsContentPolicyType aContentPolicyType)
: mContentPolicyType(aContentPolicyType) {}