Bug 1508654 - adding in assert for referrer implied codebase principal. r=ckerschb
authorJonathan Kingston <jkt@mozilla.com>
Mon, 17 Dec 2018 15:35:45 +0000
changeset 450963 b36b70ed2ed2c7cc9922adea880132923b351833
parent 450962 d8e9e4ca02a28114348aa579fabefe7895291e9b
child 450964 4b317b80ef5e14d992ce4b0e01833b8c7960008c
push id35222
push useraiakab@mozilla.com
push dateMon, 17 Dec 2018 22:01:00 +0000
treeherdermozilla-central@edf1f05e9d00 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersckerschb
bugs1508654
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1508654 - adding in assert for referrer implied codebase principal. r=ckerschb Differential Revision: https://phabricator.services.mozilla.com/D12436
docshell/base/nsDocShell.cpp
docshell/base/nsDocShellLoadState.cpp
--- a/docshell/base/nsDocShell.cpp
+++ b/docshell/base/nsDocShell.cpp
@@ -660,19 +660,23 @@ nsDocShell::GetInterface(const nsIID& aI
 NS_IMETHODIMP
 nsDocShell::LoadURI(nsDocShellLoadState* aLoadState) {
   MOZ_ASSERT(aLoadState, "Must have a valid load state!");
   MOZ_ASSERT(
       (aLoadState->LoadFlags() & INTERNAL_LOAD_FLAGS_LOADURI_SETUP_FLAGS) == 0,
       "Should not have these flags set");
   MOZ_ASSERT(aLoadState->URI(), "Should have a valid URI to load");
 
-  if (mUseStrictSecurityChecks && !aLoadState->TriggeringPrincipal()) {
+  if (!aLoadState->TriggeringPrincipal()) {
+#ifndef ANDROID
     MOZ_ASSERT(false, "LoadURI must have a triggering principal");
-    return NS_ERROR_FAILURE;
+#endif
+    if (mUseStrictSecurityChecks) {
+      return NS_ERROR_FAILURE;
+    }
   }
 
   // Note: we allow loads to get through here even if mFiredUnloadEvent is
   // true; that case will get handled in LoadInternal or LoadHistoryEntry,
   // so we pass false as the second parameter to IsNavigationAllowed.
   // However, we don't allow the page to change location *in the middle of*
   // firing beforeunload, so we do need to check if *beforeunload* is currently
   // firing, so we call IsNavigationAllowed rather than just IsPrintingOrPP.
@@ -3858,19 +3862,16 @@ nsDocShell::GotoIndex(int32_t aIndex) {
   return rootSH->LegacySHistory()->GotoIndex(aIndex);
 }
 
 NS_IMETHODIMP
 nsDocShell::LoadURI(const nsAString& aURI, uint32_t aLoadFlags,
                     nsIURI* aReferringURI, nsIInputStream* aPostStream,
                     nsIInputStream* aHeaderStream,
                     nsIPrincipal* aTriggeringPrincipal) {
-#ifndef ANDROID
-  MOZ_ASSERT(aTriggeringPrincipal, "LoadURI: Need a valid triggeringPrincipal");
-#endif
   if (mUseStrictSecurityChecks && !aTriggeringPrincipal) {
     return NS_ERROR_FAILURE;
   }
   return LoadURIWithOptions(aURI, aLoadFlags, aReferringURI, RP_Unset,
                             aPostStream, aHeaderStream, nullptr,
                             aTriggeringPrincipal);
 }
 
@@ -3896,21 +3897,16 @@ nsDocShell::LoadURIWithOptions(const nsA
 
   NS_ConvertUTF16toUTF8 uriString(aURI);
   // Cleanup the empty spaces that might be on each end.
   uriString.Trim(" ");
   // Eliminate embedded newlines, which single-line text fields now allow:
   uriString.StripCRLF();
   NS_ENSURE_TRUE(!uriString.IsEmpty(), NS_ERROR_FAILURE);
 
-#ifndef ANDROID
-  MOZ_ASSERT(aTriggeringPrincipal,
-             "LoadURIWithOptions: Need a valid triggeringPrincipal");
-#endif
-
   if (mUseStrictSecurityChecks && !aTriggeringPrincipal) {
     return NS_ERROR_FAILURE;
   }
 
   rv = NS_NewURI(getter_AddRefs(uri), uriString);
   if (uri) {
     aLoadFlags &= ~LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP;
   }
--- a/docshell/base/nsDocShellLoadState.cpp
+++ b/docshell/base/nsDocShellLoadState.cpp
@@ -328,19 +328,16 @@ nsresult nsDocShellLoadState::SetupTrigg
     if (mReferrer) {
       mTriggeringPrincipal =
           BasePrincipal::CreateCodebasePrincipal(mReferrer, aOriginAttributes);
 
       if (!mTriggeringPrincipal) {
         return NS_ERROR_FAILURE;
       }
     } else {
-#ifndef ANDROID
-      MOZ_ASSERT(false, "LoadURI: System principal required.");
-#endif
       mTriggeringPrincipal = nsContentUtils::GetSystemPrincipal();
     }
   }
   return NS_OK;
 }
 
 void nsDocShellLoadState::CalculateDocShellInternalLoadFlags() {
   MOZ_ASSERT(mDocShellInternalLoadFlags == 0,