Skip to content

Commit

Permalink
Bug 1868387 - Part 2: add MOZ_DIAGNOSTIC_ASSERT in content process, r…
Browse files Browse the repository at this point in the history
…=smaug

Differential Revision: https://phabricator.services.mozilla.com/D196290
  • Loading branch information
aiunusov485 committed Dec 13, 2023
1 parent 41283b7 commit 99c69fd
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions dom/ipc/WindowGlobalChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "nsQueryObject.h"
#include "nsSerializationHelper.h"
#include "nsFrameLoader.h"
#include "nsIScriptSecurityManager.h"

#include "mozilla/dom/JSWindowActorBinding.h"
#include "mozilla/dom/JSWindowActorChild.h"
Expand Down Expand Up @@ -585,6 +586,34 @@ void WindowGlobalChild::SetDocumentURI(nsIURI* aDocumentURI) {
BrowsingContext()->BrowserId(), InnerWindowId(),
nsContentUtils::TruncatedURLForDisplay(aDocumentURI, 1024),
embedderInnerWindowID, BrowsingContext()->UsePrivateBrowsing());

if (StaticPrefs::dom_security_setdocumenturi()) {
auto isLoadableViaInternet = [](nsIURI* uri) {
return (uri && (net::SchemeIsHTTP(uri) || net::SchemeIsHTTPS(uri)));
};
if (isLoadableViaInternet(aDocumentURI)) {
nsCOMPtr<nsIURI> principalURI = mDocumentPrincipal->GetURI();
if (mDocumentPrincipal->GetIsNullPrincipal()) {
nsCOMPtr<nsIPrincipal> precursor =
mDocumentPrincipal->GetPrecursorPrincipal();
if (precursor) {
principalURI = precursor->GetURI();
}
}

if (isLoadableViaInternet(principalURI)) {
nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager();

if (!NS_SUCCEEDED(ssm->CheckSameOriginURI(principalURI, aDocumentURI,
false, false))) {
MOZ_DIAGNOSTIC_ASSERT(false,
"Setting DocumentURI with a different origin "
"than principal URI");
}
}
}
}

mDocumentURI = aDocumentURI;
SendUpdateDocumentURI(aDocumentURI);
}
Expand Down

0 comments on commit 99c69fd

Please sign in to comment.