tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit 20fc2fb4038cea52057f8b36961246d3f70f1f8d
parent be7982bf6cbd14b90f07783f9a68ceec4603f095
Author: Adam Vandolder <avandolder@mozilla.com>
Date:   Thu, 11 Dec 2025 23:37:57 +0000

Bug 1998761 - Copy the Navigation API Key from the old to the new entry for same-origin cross-document replace navigations. r=farre,dom-core

Differential Revision: https://phabricator.services.mozilla.com/D275908

Diffstat:
Mdocshell/base/CanonicalBrowsingContext.cpp | 19+++++++++++++++++++
Mdocshell/base/nsDocShell.cpp | 24++++++++++++++++++++++++
Mtesting/web-platform/meta/html/browsers/browsing-the-web/history-traversal/pageswap/pageswap-replace-with-cross-origin-redirect.sub.html.ini | 3---
Dtesting/web-platform/meta/navigation-api/navigation-history-entry/key-id-location-replace.html.ini | 3---
Dtesting/web-platform/meta/navigation-api/navigation-methods/navigate-replace-cross-document.html.ini | 3---
5 files changed, 43 insertions(+), 9 deletions(-)

diff --git a/docshell/base/CanonicalBrowsingContext.cpp b/docshell/base/CanonicalBrowsingContext.cpp @@ -634,6 +634,25 @@ CanonicalBrowsingContext::CreateLoadingSessionHistoryEntryForLoad( } MOZ_DIAGNOSTIC_ASSERT(entry); + // https://html.spec.whatwg.org/#finalize-a-cross-document-navigation + // 9. If entryToReplace is null, then: ... + // Otherwise: ... + // 4. If historyEntry's document state's origin is same origin with + // entryToReplace's document state's origin, then set + // historyEntry's navigation API key to entryToReplace's + // navigation API key. + if (mActiveEntry && + aLoadState->GetNavigationType() == NavigationType::Replace) { + nsCOMPtr<nsIURI> uri = mActiveEntry->GetURIOrInheritedForAboutBlank(); + nsCOMPtr<nsIURI> targetURI = entry->GetURIOrInheritedForAboutBlank(); + bool sameOrigin = + NS_SUCCEEDED(nsContentUtils::GetSecurityManager()->CheckSameOriginURI( + targetURI, uri, false, false)); + if (sameOrigin) { + entry->SetNavigationKey(mActiveEntry->Info().NavigationKey()); + } + } + UniquePtr<LoadingSessionHistoryInfo> loadingInfo; if (existingLoadingInfo) { loadingInfo = MakeUnique<LoadingSessionHistoryInfo>(*existingLoadingInfo); diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp @@ -7896,6 +7896,30 @@ nsresult nsDocShell::CreateDocumentViewer(const nsACString& aContentType, nsCOMPtr<nsIChannel> failedChannel = mFailedChannel; nsCOMPtr<nsIURI> failedURI; + // https://html.spec.whatwg.org/#finalize-a-cross-document-navigation + // 9. If entryToReplace is null, then: ... + // Otherwise: ... + // 4. If historyEntry's document state's origin is same origin with + // entryToReplace's document state's origin, then set + // historyEntry's navigation API key to entryToReplace's + // navigation API key. + bool isReplace = + mActiveEntry && mLoadingEntry && IsValidLoadType(mLoadType) && + NavigationUtils::NavigationTypeFromLoadType(mLoadType) + .map([](auto type) { return type == NavigationType::Replace; }) + .valueOr(false); + if (isReplace) { + nsCOMPtr<nsIURI> uri = mActiveEntry->GetURIOrInheritedForAboutBlank(); + nsCOMPtr<nsIURI> targetURI = + mLoadingEntry->mInfo.GetURIOrInheritedForAboutBlank(); + bool sameOrigin = + NS_SUCCEEDED(nsContentUtils::GetSecurityManager()->CheckSameOriginURI( + targetURI, uri, false, false)); + if (sameOrigin) { + mLoadingEntry->mInfo.NavigationKey() = mActiveEntry->NavigationKey(); + } + } + if (mLoadType == LOAD_ERROR_PAGE) { // We need to set the SH entry and our current URI here and not // at the moment we load the page. We want the same behavior diff --git a/testing/web-platform/meta/html/browsers/browsing-the-web/history-traversal/pageswap/pageswap-replace-with-cross-origin-redirect.sub.html.ini b/testing/web-platform/meta/html/browsers/browsing-the-web/history-traversal/pageswap/pageswap-replace-with-cross-origin-redirect.sub.html.ini @@ -1,8 +1,5 @@ [pageswap-replace-with-cross-origin-redirect.sub.html] expected: - if (os == "win") and not debug: ERROR - if (os == "mac") and not debug: ERROR - if os == "android": [ERROR, TIMEOUT] [ERROR, TIMEOUT] [pageswap on navigation with same-origin redirect] expected: TIMEOUT diff --git a/testing/web-platform/meta/navigation-api/navigation-history-entry/key-id-location-replace.html.ini b/testing/web-platform/meta/navigation-api/navigation-history-entry/key-id-location-replace.html.ini @@ -1,3 +0,0 @@ -[key-id-location-replace.html] - [NavigationHistoryEntry's key and id after location.replace()] - expected: FAIL diff --git a/testing/web-platform/meta/navigation-api/navigation-methods/navigate-replace-cross-document.html.ini b/testing/web-platform/meta/navigation-api/navigation-methods/navigate-replace-cross-document.html.ini @@ -1,3 +0,0 @@ -[navigate-replace-cross-document.html] - [navigate() with history: 'replace' option] - expected: FAIL