diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index 26b5c1e4b67e..f4d8843e2df6 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -8743,9 +8743,7 @@ bool nsDocShell::IsSameDocumentNavigation(nsDocShellLoadState* aLoadState, } nsresult nsDocShell::HandleSameDocumentNavigation( - nsDocShellLoadState* aLoadState, SameDocumentNavigationState& aState, - bool& aSameDocument) { - aSameDocument = true; + nsDocShellLoadState* aLoadState, SameDocumentNavigationState& aState) { #ifdef DEBUG SameDocumentNavigationState state; MOZ_ASSERT(IsSameDocumentNavigation(aLoadState, state)); @@ -8770,37 +8768,6 @@ nsresult nsDocShell::HandleSameDocumentNavigation( ("Upgraded URI to %s", newURI->GetSpecOrDefault().get())); } - // check if aLoadState->URI(), principalURI, mCurrentURI are same origin - // skip handling otherwise - nsCOMPtr origPrincipal = doc->NodePrincipal(); - nsCOMPtr principalURI = origPrincipal->GetURI(); - if (origPrincipal->GetIsNullPrincipal()) { - nsCOMPtr precursor = origPrincipal->GetPrecursorPrincipal(); - if (precursor) { - principalURI = precursor->GetURI(); - } - - auto isLoadableViaInternet = [](nsIURI* uri) { - return (uri && (net::SchemeIsHTTP(uri) || net::SchemeIsHTTPS(uri))); - }; - - if (isLoadableViaInternet(principalURI) && - isLoadableViaInternet(mCurrentURI) && isLoadableViaInternet(newURI)) { - nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager(); - if (!NS_SUCCEEDED( - ssm->CheckSameOriginURI(newURI, principalURI, false, false)) || - !NS_SUCCEEDED(ssm->CheckSameOriginURI(mCurrentURI, principalURI, - false, false))) { - MOZ_LOG(gSHLog, LogLevel::Debug, - ("nsDocShell[%p]: possible violation of the same origin policy " - "during same document navigation", - this)); - aSameDocument = false; - return NS_OK; - } - } - } - #ifdef DEBUG if (aState.mSameExceptHashes) { bool sameExceptHashes = false; @@ -9397,15 +9364,13 @@ nsresult nsDocShell::InternalLoad(nsDocShellLoadState* aLoadState, // document. If the process fails, or if we successfully navigate within the // same document, return. if (sameDocument) { - nsresult rv = HandleSameDocumentNavigation( - aLoadState, sameDocumentNavigationState, sameDocument); + nsresult rv = + HandleSameDocumentNavigation(aLoadState, sameDocumentNavigationState); NS_ENSURE_SUCCESS(rv, rv); if (shouldTakeFocus) { mBrowsingContext->Focus(CallerType::System, IgnoreErrors()); } - if (sameDocument) { - return rv; - } + return rv; } // mContentViewer->PermitUnload can destroy |this| docShell, which diff --git a/docshell/base/nsDocShell.h b/docshell/base/nsDocShell.h index b8a3b4b2f4e1..237cf8dc1a54 100644 --- a/docshell/base/nsDocShell.h +++ b/docshell/base/nsDocShell.h @@ -1060,8 +1060,7 @@ class nsDocShell final : public nsDocLoader, // continuing with new document navigation. MOZ_CAN_RUN_SCRIPT nsresult HandleSameDocumentNavigation(nsDocShellLoadState* aLoadState, - SameDocumentNavigationState& aState, - bool& aSameDocument); + SameDocumentNavigationState& aState); uint32_t GetSameDocumentNavigationFlags(nsIURI* aNewURI); diff --git a/dom/ipc/WindowGlobalParent.cpp b/dom/ipc/WindowGlobalParent.cpp index dc0afc8ec697..bb2d301d5443 100644 --- a/dom/ipc/WindowGlobalParent.cpp +++ b/dom/ipc/WindowGlobalParent.cpp @@ -58,8 +58,6 @@ #include "nsISharePicker.h" #include "nsIURIMutator.h" #include "nsIWebProgressListener.h" -#include "nsScriptSecurityManager.h" -#include "nsIOService.h" #include "mozilla/dom/DOMException.h" #include "mozilla/dom/DOMExceptionBinding.h" @@ -92,6 +90,7 @@ WindowGlobalParent::WindowGlobalParent( uint64_t aOuterWindowId, FieldValues&& aInit) : WindowContext(aBrowsingContext, aInnerWindowId, aOuterWindowId, std::move(aInit)), + mIsInitialDocument(false), mSandboxFlags(0), mDocumentHasLoaded(false), mDocumentHasUserInteracted(false), @@ -118,7 +117,7 @@ already_AddRefed WindowGlobalParent::CreateDisconnected( aInit.context().mOuterWindowId, std::move(fields)); wgp->mDocumentPrincipal = aInit.principal(); wgp->mDocumentURI = aInit.documentURI(); - wgp->mIsInitialDocument = Some(aInit.isInitialDocument()); + wgp->mIsInitialDocument = aInit.isInitialDocument(); wgp->mBlockAllMixedContent = aInit.blockAllMixedContent(); wgp->mUpgradeInsecureRequests = aInit.upgradeInsecureRequests(); wgp->mSandboxFlags = aInit.sandboxFlags(); @@ -381,44 +380,7 @@ mozilla::ipc::IPCResult WindowGlobalParent::RecvInternalLoad( IPCResult WindowGlobalParent::RecvUpdateDocumentURI(nsIURI* aURI) { // XXX(nika): Assert that the URI change was one which makes sense (either - // about:blank -> a real URI, or a legal push/popstate URI change): - nsAutoCString scheme; - if (NS_FAILED(aURI->GetScheme(scheme))) { - return IPC_FAIL(this, "Setting DocumentURI without scheme."); - } - - nsCOMPtr ios = do_GetIOService(); - if (!ios) { - return IPC_FAIL(this, "Cannot get IOService"); - } - nsCOMPtr handler; - ios->GetProtocolHandler(scheme.get(), getter_AddRefs(handler)); - if (!handler) { - return IPC_FAIL(this, "Setting DocumentURI with unknown protocol."); - } - - auto isLoadableViaInternet = [](nsIURI* uri) { - return (uri && (net::SchemeIsHTTP(uri) || net::SchemeIsHTTPS(uri))); - }; - - if (isLoadableViaInternet(aURI)) { - nsCOMPtr principalURI = mDocumentPrincipal->GetURI(); - if (mDocumentPrincipal->GetIsNullPrincipal()) { - nsCOMPtr precursor = - mDocumentPrincipal->GetPrecursorPrincipal(); - if (precursor) { - principalURI = precursor->GetURI(); - } - } - - if (isLoadableViaInternet(principalURI) && - !nsScriptSecurityManager::SecurityCompareURIs(principalURI, aURI)) { - return IPC_FAIL(this, - "Setting DocumentURI with a different Origin than " - "principal URI"); - } - } - + // about:blank -> a real URI, or a legal push/popstate URI change?) mDocumentURI = aURI; return IPC_OK(); } diff --git a/dom/ipc/WindowGlobalParent.h b/dom/ipc/WindowGlobalParent.h index e0f8091a7837..f908ffac10be 100644 --- a/dom/ipc/WindowGlobalParent.h +++ b/dom/ipc/WindowGlobalParent.h @@ -151,9 +151,7 @@ class WindowGlobalParent final : public WindowContext, void GetContentBlockingLog(nsAString& aLog); - bool IsInitialDocument() { - return mIsInitialDocument.isSome() && mIsInitialDocument.value(); - } + bool IsInitialDocument() { return mIsInitialDocument; } already_AddRefed PermitUnload( PermitUnloadAction aAction, uint32_t aTimeout, mozilla::ErrorResult& aRv); @@ -257,12 +255,7 @@ class WindowGlobalParent final : public WindowContext, mozilla::ipc::IPCResult RecvUpdateDocumentTitle(const nsString& aTitle); mozilla::ipc::IPCResult RecvUpdateHttpsOnlyStatus(uint32_t aHttpsOnlyStatus); mozilla::ipc::IPCResult RecvSetIsInitialDocument(bool aIsInitialDocument) { - if (aIsInitialDocument && mIsInitialDocument.isSome() && - (mIsInitialDocument.value() != aIsInitialDocument)) { - return IPC_FAIL_NO_REASON(this); - } - - mIsInitialDocument = Some(aIsInitialDocument); + mIsInitialDocument = aIsInitialDocument; return IPC_OK(); } mozilla::ipc::IPCResult RecvUpdateDocumentSecurityInfo( @@ -354,7 +347,7 @@ class WindowGlobalParent final : public WindowContext, nsCOMPtr mDocumentURI; Maybe mDocumentTitle; - Maybe mIsInitialDocument; + bool mIsInitialDocument; // True if this window has a "beforeunload" event listener. bool mHasBeforeUnload;