Bug 1558394 - Pass the TriggeringSandboxFlags to nsILoadinfo r=ckerschb,smaug,necko-reviewers,valentin

Add triggering Sandbox flags to loadinfo
***
Pass triggering Flags into Loadinfo

***
Fix triggeringSandboxflags passing

Differential Revision: https://phabricator.services.mozilla.com/D69588
This commit is contained in:
Sebastian Streich 2020-07-29 11:43:23 +00:00
Родитель 66fbd11f99
Коммит fb1d1dc1df
16 изменённых файлов: 100 добавлений и 7 удалений

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

@ -1510,7 +1510,6 @@ function _loadURI(browser, uri, params = {}) {
params.loadFlags || params.flags || Ci.nsIWebNavigation.LOAD_FLAGS_NONE;
let hasValidUserGestureActivation =
document.hasValidTransientUserGestureActivation;
if (!triggeringPrincipal) {
throw new Error("Must load with a triggering Principal");
}

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

@ -3792,13 +3792,15 @@ nsresult nsDocShell::LoadErrorPage(nsIURI* aErrorURI, nsIURI* aFailedURI,
RefPtr<nsDocShellLoadState> loadState = new nsDocShellLoadState(aErrorURI);
loadState->SetTriggeringPrincipal(nsContentUtils::GetSystemPrincipal());
if (mBrowsingContext) {
loadState->SetTriggeringSandboxFlags(mBrowsingContext->GetSandboxFlags());
}
loadState->SetLoadType(LOAD_ERROR_PAGE);
loadState->SetFirstParty(true);
loadState->SetSourceBrowsingContext(mBrowsingContext);
loadState->SetHasValidUserGestureActivation(
mBrowsingContext &&
mBrowsingContext->HasValidTransientUserGestureActivation());
return InternalLoad(loadState);
}
@ -3893,6 +3895,7 @@ nsresult nsDocShell::ReloadDocument(nsDocShell* aDocShell, Document* aDocument,
nsIPrincipal* triggeringPrincipal = aDocument->NodePrincipal();
nsCOMPtr<nsIContentSecurityPolicy> csp = aDocument->GetCsp();
uint32_t triggeringSandboxFlags = aDocument->GetSandboxFlags();
nsAutoString contentTypeHint;
aDocument->GetContentType(contentTypeHint);
@ -3937,6 +3940,7 @@ nsresult nsDocShell::ReloadDocument(nsDocShell* aDocShell, Document* aDocument,
loadState->SetMaybeResultPrincipalURI(emplacedResultPrincipalURI);
loadState->SetLoadReplace(loadReplace);
loadState->SetTriggeringPrincipal(triggeringPrincipal);
loadState->SetTriggeringSandboxFlags(triggeringSandboxFlags);
loadState->SetPrincipalToInherit(triggeringPrincipal);
loadState->SetCsp(csp);
loadState->SetLoadFlags(flags);
@ -4914,6 +4918,7 @@ nsDocShell::ForceRefreshURI(nsIURI* aURI, nsIPrincipal* aPrincipal,
loadState->SetCsp(doc->GetCsp());
loadState->SetHasValidUserGestureActivation(
doc->HasValidTransientUserGestureActivation());
loadState->SetTriggeringSandboxFlags(doc->GetSandboxFlags());
}
loadState->SetPrincipalIsExplicit(true);
@ -8271,6 +8276,8 @@ nsresult nsDocShell::PerformRetargeting(nsDocShellLoadState* aLoadState) {
// LoadReplace will always be false due to asserts above, skip setting
// it.
loadState->SetTriggeringPrincipal(aLoadState->TriggeringPrincipal());
loadState->SetTriggeringSandboxFlags(
aLoadState->TriggeringSandboxFlags());
loadState->SetCsp(aLoadState->Csp());
loadState->SetInheritPrincipal(
aLoadState->HasLoadFlags(INTERNAL_LOAD_FLAGS_INHERIT_PRINCIPAL));
@ -9744,6 +9751,7 @@ nsresult nsDocShell::DoURILoad(nsDocShellLoadState* aLoadState,
aLoadState->HasLoadFlags(LOAD_FLAGS_FROM_EXTERNAL)) {
loadInfo->SetHasValidUserGestureActivation(true);
}
loadInfo->SetTriggeringSandboxFlags(aLoadState->TriggeringSandboxFlags());
/* Get the cache Key from SH */
uint32_t cacheKey = 0;
@ -12048,6 +12056,10 @@ nsresult nsDocShell::OnLinkClickSync(nsIContent* aContent,
}
}
}
uint32_t triggeringSandboxFlags = 0;
if (mBrowsingContext) {
triggeringSandboxFlags = mBrowsingContext->GetSandboxFlags();
}
uint32_t flags = INTERNAL_LOAD_FLAGS_NONE;
bool isElementAnchorOrArea = IsElementAnchorOrArea(aContent);
@ -12141,6 +12153,7 @@ nsresult nsDocShell::OnLinkClickSync(nsIContent* aContent,
isElementAnchorOrArea ? new ReferrerInfo(*aContent->AsElement())
: new ReferrerInfo(*referrerDoc);
aLoadState->SetTriggeringSandboxFlags(triggeringSandboxFlags);
aLoadState->SetReferrerInfo(referrerInfo);
aLoadState->SetLoadFlags(flags);
aLoadState->SetTypeHint(NS_ConvertUTF16toUTF8(typeHint));

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

@ -68,6 +68,7 @@ nsDocShellLoadState::nsDocShellLoadState(
mTriggeringPrincipal = aLoadState.TriggeringPrincipal();
mPrincipalToInherit = aLoadState.PrincipalToInherit();
mPartitionedPrincipalToInherit = aLoadState.PartitionedPrincipalToInherit();
mTriggeringSandboxFlags = aLoadState.TriggeringSandboxFlags();
mCsp = aLoadState.Csp();
mOriginalURIString = aLoadState.OriginalURIString();
mCancelContentJSEpoch = aLoadState.CancelContentJSEpoch();
@ -84,6 +85,7 @@ nsDocShellLoadState::nsDocShellLoadState(const nsDocShellLoadState& aOther)
mResultPrincipalURI(aOther.mResultPrincipalURI),
mResultPrincipalURIIsSome(aOther.mResultPrincipalURIIsSome),
mTriggeringPrincipal(aOther.mTriggeringPrincipal),
mTriggeringSandboxFlags(aOther.mTriggeringSandboxFlags),
mCsp(aOther.mCsp),
mKeepResultPrincipalURIIfSet(aOther.mKeepResultPrincipalURIIfSet),
mLoadReplace(aOther.mLoadReplace),
@ -118,6 +120,7 @@ nsDocShellLoadState::nsDocShellLoadState(const nsDocShellLoadState& aOther)
nsDocShellLoadState::nsDocShellLoadState(nsIURI* aURI, uint64_t aLoadIdentifier)
: mURI(aURI),
mResultPrincipalURIIsSome(false),
mTriggeringSandboxFlags(0),
mKeepResultPrincipalURIIfSet(false),
mLoadReplace(false),
mInheritPrincipal(false),
@ -348,6 +351,7 @@ nsresult nsDocShellLoadState::CreateFromLoadURIOptions(
loadState->SetFirstParty(true);
loadState->SetHasValidUserGestureActivation(
aLoadURIOptions.mHasValidUserGestureActivation);
loadState->SetTriggeringSandboxFlags(aLoadURIOptions.mTriggeringSandboxFlags);
loadState->SetPostDataStream(postData);
loadState->SetHeadersStream(aLoadURIOptions.mHeaders);
loadState->SetBaseURI(aLoadURIOptions.mBaseURI);
@ -448,6 +452,14 @@ void nsDocShellLoadState::SetCsp(nsIContentSecurityPolicy* aCsp) {
nsIContentSecurityPolicy* nsDocShellLoadState::Csp() const { return mCsp; }
void nsDocShellLoadState::SetTriggeringSandboxFlags(uint32_t flags) {
mTriggeringSandboxFlags = flags;
}
uint32_t nsDocShellLoadState::TriggeringSandboxFlags() const {
return mTriggeringSandboxFlags;
}
bool nsDocShellLoadState::InheritPrincipal() const { return mInheritPrincipal; }
void nsDocShellLoadState::SetInheritPrincipal(bool aInheritPrincipal) {
@ -882,6 +894,7 @@ DocShellLoadStateInit nsDocShellLoadState::Serialize() {
loadState.TriggeringPrincipal() = mTriggeringPrincipal;
loadState.PrincipalToInherit() = mPrincipalToInherit;
loadState.PartitionedPrincipalToInherit() = mPartitionedPrincipalToInherit;
loadState.TriggeringSandboxFlags() = mTriggeringSandboxFlags;
loadState.Csp() = mCsp;
loadState.OriginalURIString() = mOriginalURIString;
loadState.CancelContentJSEpoch() = mCancelContentJSEpoch;

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

@ -102,6 +102,10 @@ class nsDocShellLoadState final {
void SetTriggeringPrincipal(nsIPrincipal* aTriggeringPrincipal);
uint32_t TriggeringSandboxFlags() const;
void SetTriggeringSandboxFlags(uint32_t aTriggeringSandboxFlags);
nsIContentSecurityPolicy* Csp() const;
void SetCsp(nsIContentSecurityPolicy* aCsp);
@ -307,6 +311,11 @@ class nsDocShellLoadState final {
// SystemPrincipal as the triggeringPrincipal.
nsCOMPtr<nsIPrincipal> mTriggeringPrincipal;
// The SandboxFlags of the load, that are, the SandboxFlags of the entity
// responsible for causing the load to occur. Most likely this are the
// SandboxFlags of the document that started the load.
uint32_t mTriggeringSandboxFlags;
// The CSP of the load, that is, the CSP of the entity responsible for causing
// the load to occur. Most likely this is the CSP of the document that started
// the load. In case the entity starting the load did not use a CSP, then mCsp

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

@ -99,6 +99,7 @@ already_AddRefed<nsDocShellLoadState> LocationBase::CheckURL(
principal->CreateReferrerInfo(referrerPolicy, getter_AddRefs(referrerInfo));
}
loadState->SetTriggeringPrincipal(triggeringPrincipal);
loadState->SetTriggeringSandboxFlags(doc->GetSandboxFlags());
loadState->SetCsp(doc->GetCsp());
if (referrerInfo) {
loadState->SetReferrerInfo(referrerInfo);

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

@ -248,7 +248,7 @@ RefPtr<ClientOpPromise> ClientNavigateOpChild::DoNavigate(
RefPtr<nsDocShellLoadState> loadState = new nsDocShellLoadState(url);
loadState->SetTriggeringPrincipal(principal);
loadState->SetTriggeringSandboxFlags(doc->GetSandboxFlags());
loadState->SetCsp(doc->GetCsp());
auto referrerInfo = MakeRefPtr<ReferrerInfo>(*doc);

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

@ -265,6 +265,10 @@ struct DocShellLoadStateInit
MaybeDiscardedBrowsingContext SourceBrowsingContext;
MaybeDiscardedBrowsingContext TargetBrowsingContext;
// The TriggineringSandboxFlags are the SandboxFlags of the entity
// responsible for causing the load to occur.
uint32_t TriggeringSandboxFlags;
nsCString? OriginalURIString;
int32_t? CancelContentJSEpoch;

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

@ -68,6 +68,12 @@ dictionary LoadURIOptions {
*/
boolean hasValidUserGestureActivation = false;
/**
* The SandboxFlags of the entity thats
* responsible for causing the load.
*/
unsigned long triggeringSandboxFlags = 0;
/**
* If non-0, a value to pass to nsIDocShell::setCancelContentJSEpoch
* when initiating the load.

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

@ -506,6 +506,7 @@ nsresult LoadInfoToLoadInfoArgs(nsILoadInfo* aLoadInfo,
sandboxedLoadingPrincipalInfo, topLevelPrincipalInfo,
topLevelStorageAreaPrincipalInfo, optionalResultPrincipalURI,
aLoadInfo->GetSecurityFlags(), aLoadInfo->GetSandboxFlags(),
aLoadInfo->GetTriggeringSandboxFlags(),
aLoadInfo->InternalContentPolicyType(),
static_cast<uint32_t>(aLoadInfo->GetTainting()),
aLoadInfo->GetBlockAllMixedContent(),
@ -735,7 +736,7 @@ nsresult LoadInfoArgsToLoadInfo(
topLevelStorageAreaPrincipal, resultPrincipalURI, cookieJarSettings,
cspToInherit, clientInfo, reservedClientInfo, initialClientInfo,
controller, loadInfoArgs.securityFlags(), loadInfoArgs.sandboxFlags(),
loadInfoArgs.contentPolicyType(),
loadInfoArgs.triggeringSandboxFlags(), loadInfoArgs.contentPolicyType(),
static_cast<LoadTainting>(loadInfoArgs.tainting()),
loadInfoArgs.blockAllMixedContent(),
loadInfoArgs.upgradeInsecureRequests(),
@ -806,6 +807,7 @@ void LoadInfoToParentLoadInfoForwarder(
aLoadInfo->GetHasValidUserGestureActivation(),
aLoadInfo->GetAllowDeprecatedSystemRequests(),
aLoadInfo->GetIsInDevToolsContext(), aLoadInfo->GetParserCreatedScript(),
aLoadInfo->GetTriggeringSandboxFlags(),
aLoadInfo->GetServiceWorkerTaintingSynthesized(),
aLoadInfo->GetDocumentHasUserInteracted(),
aLoadInfo->GetDocumentHasLoaded(),
@ -846,6 +848,10 @@ nsresult MergeParentLoadInfoForwarder(
rv = aLoadInfo->SetHttpsOnlyStatus(aForwarderArgs.httpsOnlyStatus());
NS_ENSURE_SUCCESS(rv, rv);
rv = aLoadInfo->SetTriggeringSandboxFlags(
aForwarderArgs.triggeringSandboxFlags());
NS_ENSURE_SUCCESS(rv, rv);
rv = aLoadInfo->SetHasValidUserGestureActivation(
aForwarderArgs.hasValidUserGestureActivation());
NS_ENSURE_SUCCESS(rv, rv);

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

@ -103,6 +103,7 @@ LoadInfo::LoadInfo(
mLoadingContext(do_GetWeakReference(aLoadingContext)),
mSecurityFlags(aSecurityFlags),
mSandboxFlags(aSandboxFlags),
mTriggeringSandboxFlags(0),
mInternalContentPolicyType(aContentPolicyType) {
MOZ_ASSERT(mLoadingPrincipal);
MOZ_ASSERT(mTriggeringPrincipal);
@ -338,6 +339,7 @@ LoadInfo::LoadInfo(nsPIDOMWindowOuter* aOuterWindow,
mContextForTopLevelLoad(do_GetWeakReference(aContextForTopLevelLoad)),
mSecurityFlags(aSecurityFlags),
mSandboxFlags(aSandboxFlags),
mTriggeringSandboxFlags(0),
mInternalContentPolicyType(nsIContentPolicy::TYPE_DOCUMENT) {
// Top-level loads are never third-party
// Grab the information we can out of the window.
@ -394,6 +396,7 @@ LoadInfo::LoadInfo(dom::CanonicalBrowsingContext* aBrowsingContext,
: mTriggeringPrincipal(aTriggeringPrincipal),
mSecurityFlags(aSecurityFlags),
mSandboxFlags(aSandboxFlags),
mTriggeringSandboxFlags(0),
mInternalContentPolicyType(nsIContentPolicy::TYPE_DOCUMENT) {
// Top-level loads are never third-party
// Grab the information we can out of the window.
@ -562,6 +565,7 @@ LoadInfo::LoadInfo(const LoadInfo& rhs)
mContextForTopLevelLoad(rhs.mContextForTopLevelLoad),
mSecurityFlags(rhs.mSecurityFlags),
mSandboxFlags(rhs.mSandboxFlags),
mTriggeringSandboxFlags(rhs.mTriggeringSandboxFlags),
mInternalContentPolicyType(rhs.mInternalContentPolicyType),
mTainting(rhs.mTainting),
mBlockAllMixedContent(rhs.mBlockAllMixedContent),
@ -625,9 +629,9 @@ LoadInfo::LoadInfo(
const Maybe<ClientInfo>& aInitialClientInfo,
const Maybe<ServiceWorkerDescriptor>& aController,
nsSecurityFlags aSecurityFlags, uint32_t aSandboxFlags,
nsContentPolicyType aContentPolicyType, LoadTainting aTainting,
bool aBlockAllMixedContent, bool aUpgradeInsecureRequests,
bool aBrowserUpgradeInsecureRequests,
uint32_t aTriggeringSandboxFlags, nsContentPolicyType aContentPolicyType,
LoadTainting aTainting, bool aBlockAllMixedContent,
bool aUpgradeInsecureRequests, bool aBrowserUpgradeInsecureRequests,
bool aBrowserWouldUpgradeInsecureRequests, bool aForceAllowDataURI,
bool aAllowInsecureRedirectToDataURI, bool aBypassCORSChecks,
bool aSkipContentPolicyCheckForWebRequest,
@ -666,6 +670,7 @@ LoadInfo::LoadInfo(
mLoadingContext(do_GetWeakReference(aLoadingContext)),
mSecurityFlags(aSecurityFlags),
mSandboxFlags(aSandboxFlags),
mTriggeringSandboxFlags(aTriggeringSandboxFlags),
mInternalContentPolicyType(aContentPolicyType),
mTainting(aTainting),
mBlockAllMixedContent(aBlockAllMixedContent),
@ -922,6 +927,18 @@ LoadInfo::GetSandboxFlags(uint32_t* aResult) {
return NS_OK;
}
NS_IMETHODIMP
LoadInfo::GetTriggeringSandboxFlags(uint32_t* aResult) {
*aResult = mTriggeringSandboxFlags;
return NS_OK;
}
NS_IMETHODIMP
LoadInfo::SetTriggeringSandboxFlags(uint32_t aFlags) {
mTriggeringSandboxFlags = aFlags;
return NS_OK;
}
NS_IMETHODIMP
LoadInfo::GetSecurityMode(uint32_t* aFlags) {
*aFlags = (mSecurityFlags &

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

@ -195,6 +195,7 @@ class LoadInfo final : public nsILoadInfo {
const Maybe<mozilla::dom::ClientInfo>& aInitialClientInfo,
const Maybe<mozilla::dom::ServiceWorkerDescriptor>& aController,
nsSecurityFlags aSecurityFlags, uint32_t aSandboxFlags,
uint32_t aTriggeringSandboxFlags,
nsContentPolicyType aContentPolicyType, LoadTainting aTainting,
bool aBlockAllMixedContent, bool aUpgradeInsecureRequests,
bool aBrowserUpgradeInsecureRequests,
@ -278,6 +279,7 @@ class LoadInfo final : public nsILoadInfo {
nsWeakPtr mContextForTopLevelLoad;
nsSecurityFlags mSecurityFlags;
uint32_t mSandboxFlags;
uint32_t mTriggeringSandboxFlags;
nsContentPolicyType mInternalContentPolicyType;
LoadTainting mTainting = LoadTainting::Basic;
bool mBlockAllMixedContent = false;

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

@ -93,6 +93,14 @@ NS_IMETHODIMP
TRRLoadInfo::GetSandboxFlags(uint32_t* aResult) {
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
TRRLoadInfo::GetTriggeringSandboxFlags(uint32_t* aResult) {
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
TRRLoadInfo::SetTriggeringSandboxFlags(uint32_t aResult) {
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
TRRLoadInfo::GetSecurityMode(uint32_t* aFlags) {

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

@ -410,6 +410,12 @@ interface nsILoadInfo : nsISupports
*/
[infallible] readonly attribute unsigned long sandboxFlags;
/**
* The TriggingSandboxFlags are the SandboxFlags of the entity
* responsible for causing the load to occur.
*/
[infallible] attribute unsigned long triggeringSandboxFlags;
/**
* Allows to query only the security mode bits from above.
*/

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

@ -130,6 +130,7 @@ static auto CreateDocumentLoadInfo(CanonicalBrowsingContext* aBrowsingContext,
attrs, securityFlags, sandboxFlags);
}
loadInfo->SetTriggeringSandboxFlags(aLoadState->TriggeringSandboxFlags());
loadInfo->SetHasValidUserGestureActivation(
aLoadState->HasValidUserGestureActivation());
@ -155,6 +156,7 @@ static auto CreateObjectLoadInfo(nsDocShellLoadState* aLoadState,
loadInfo->SetHasValidUserGestureActivation(
aLoadState->HasValidUserGestureActivation());
loadInfo->SetTriggeringSandboxFlags(aLoadState->TriggeringSandboxFlags());
return loadInfo.forget();
}

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

@ -83,6 +83,7 @@ struct LoadInfoArgs
URIParams? resultPrincipalURI;
uint32_t securityFlags;
uint32_t sandboxFlags;
uint32_t triggeringSandboxFlags;
uint32_t contentPolicyType;
uint32_t tainting;
bool blockAllMixedContent;
@ -203,6 +204,9 @@ struct ParentLoadInfoForwarderArgs
// the script was created by the HTML parser.
bool parserCreatedScript;
// Sandbox Flags of the Document that triggered the load
uint32_t triggeringSandboxFlags;
// We must also note that the tainting value was explicitly set
// by the service worker.
bool serviceWorkerTaintingSynthesized;

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

@ -1149,6 +1149,9 @@ nsresult nsWindowWatcher::OpenWindowInternal(
loadState->SetSourceBrowsingContext(parentBC);
loadState->SetHasValidUserGestureActivation(
parentBC && parentBC->HasValidTransientUserGestureActivation());
if (parentBC) {
loadState->SetTriggeringSandboxFlags(parentBC->GetSandboxFlags());
}
if (subjectPrincipal) {
loadState->SetTriggeringPrincipal(subjectPrincipal);