mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1139297 - Implement CSP upgrade-insecure-requests directive - document changes (r=smaug)
This commit is contained in:
parent
12f19dc2be
commit
9cf312cbbb
@ -1552,6 +1552,7 @@ nsIDocument::nsIDocument()
|
||||
: nsINode(nullNodeInfo),
|
||||
mReferrerPolicySet(false),
|
||||
mReferrerPolicy(mozilla::net::RP_Default),
|
||||
mUpgradeInsecureRequests(false),
|
||||
mCharacterSet(NS_LITERAL_CSTRING("ISO-8859-1")),
|
||||
mNodeInfoManager(nullptr),
|
||||
mCompatMode(eCompatibility_FullStandards),
|
||||
@ -2706,6 +2707,19 @@ nsDocument::StartDocumentLoad(const char* aCommand, nsIChannel* aChannel,
|
||||
WarnIfSandboxIneffective(docShell, mSandboxFlags, GetChannel());
|
||||
}
|
||||
|
||||
// The CSP directive upgrade-insecure-requests not only applies to the
|
||||
// toplevel document, but also to nested documents. Let's propagate that
|
||||
// flag from the parent to the nested document.
|
||||
nsCOMPtr<nsIDocShellTreeItem> treeItem = this->GetDocShell();
|
||||
if (treeItem) {
|
||||
nsCOMPtr<nsIDocShellTreeItem> sameTypeParent;
|
||||
treeItem->GetSameTypeParent(getter_AddRefs(sameTypeParent));
|
||||
if (sameTypeParent) {
|
||||
mUpgradeInsecureRequests =
|
||||
sameTypeParent->GetDocument()->GetUpgradeInsecureRequests();
|
||||
}
|
||||
}
|
||||
|
||||
// If this is not a data document, set CSP.
|
||||
if (!mLoadedAsData) {
|
||||
nsresult rv = InitCSP(aChannel);
|
||||
@ -2978,6 +2992,13 @@ nsDocument::InitCSP(nsIChannel* aChannel)
|
||||
// speculative loads.
|
||||
}
|
||||
|
||||
// ------ Set flag for 'upgrade-insecure-requests' if not already
|
||||
// inherited from the parent context.
|
||||
if (!mUpgradeInsecureRequests) {
|
||||
rv = csp->GetUpgradeInsecureRequests(&mUpgradeInsecureRequests);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
rv = principal->SetCsp(csp);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
MOZ_LOG(gCspPRLog, LogLevel::Debug,
|
||||
|
@ -308,6 +308,18 @@ public:
|
||||
return GetReferrerPolicy();
|
||||
}
|
||||
|
||||
/**
|
||||
* If true, this flag indicates that all subresource loads for this
|
||||
* document need to be upgraded from http to https.
|
||||
* This flag becomes true if the CSP of the document itself, or any
|
||||
* of the document's ancestors up to the toplevel document makes use
|
||||
* of the CSP directive 'upgrade-insecure-requests'.
|
||||
*/
|
||||
bool GetUpgradeInsecureRequests() const
|
||||
{
|
||||
return mUpgradeInsecureRequests;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the principal responsible for this document.
|
||||
*/
|
||||
@ -2631,6 +2643,8 @@ protected:
|
||||
bool mReferrerPolicySet;
|
||||
ReferrerPolicyEnum mReferrerPolicy;
|
||||
|
||||
bool mUpgradeInsecureRequests;
|
||||
|
||||
mozilla::WeakPtr<nsDocShell> mDocumentContainer;
|
||||
|
||||
nsCString mCharacterSet;
|
||||
|
Loading…
Reference in New Issue
Block a user