Commit c2342f81 authored by Arthur Edelstein's avatar Arthur Edelstein Committed by Georg Koppen
Browse files

Bug 21569: Add first-party domain to Permissions key

parent 167f4e46
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -70,3 +70,4 @@ support-files =
[browser_clientAuth.js]
[browser_cacheAPI.js]
[browser_permissions.js]
[browser_permissions_isolation.js]
+46 −0
Original line number Diff line number Diff line
/**
 * Tor Bug 21569 - A test case for permissions isolation.
 */

const TEST_PAGE = "http://mochi.test:8888/browser/browser/components/" +
                  "originattributes/test/browser/file_firstPartyBasic.html";

function* init() {
  let permPromise = TestUtils.topicObserved("perm-changed");
  Services.perms.removeAll();
  info("called removeAll");
  yield permPromise;
  info("cleared permissions for new test");
}

// Define the testing function
function* doTest(aBrowser) {
  // Promise will result when permissions popup appears:
  let popupShowPromise = BrowserTestUtils.waitForEvent(PopupNotifications.panel, "popupshown");
  let originalStatus = yield ContentTask.spawn(aBrowser, null, function* (key) {
    let status = (yield content.navigator.permissions.query({name: "notifications"})).state;
    content.Notification.requestPermission();
    return status;
  });
  info(`originalStatus: '${originalStatus}'`);
  if (originalStatus === "prompt") {
    // Wait for the popup requesting permission to show notifications:
    yield popupShowPromise;
    let popupHidePromise = BrowserTestUtils.waitForEvent(PopupNotifications.panel, "popuphidden");
    let popupNotification = PopupNotifications.panel.childNodes[0];
    // Click to grant permission:
    popupNotification.button.click();
    // Wait for popup to hide again.
    yield popupHidePromise;
  }
  return originalStatus;
}

add_task(function* () {
    yield SpecialPowers.pushPrefEnv({
      set: [["dom.webnotifications.enabled", true]]
    });
    IsolationTestTools.runTests(TEST_PAGE, doTest,
                                (isolated, val1, val2) => (isolated === ( val2 === "prompt")),
                                init, true);
});
+0 −24
Original line number Diff line number Diff line
@@ -60,13 +60,6 @@ PrincipalOriginAttributes::InheritFromNecko(const NeckoOriginAttributes& aAttrs)
  mFirstPartyDomain = aAttrs.mFirstPartyDomain;
}

void
PrincipalOriginAttributes::StripUserContextIdAndFirstPartyDomain()
{
  mUserContextId = nsIScriptSecurityManager::DEFAULT_USER_CONTEXT_ID;
  mFirstPartyDomain.Truncate();
}

void
DocShellOriginAttributes::InheritFromDocToChildDocShell(const PrincipalOriginAttributes& aAttrs)
{
@@ -727,23 +720,6 @@ BasePrincipal::CreateCodebasePrincipal(const nsACString& aOrigin)
  return BasePrincipal::CreateCodebasePrincipal(uri, attrs);
}

already_AddRefed<BasePrincipal>
BasePrincipal::CloneStrippingUserContextIdAndFirstPartyDomain()
{
  PrincipalOriginAttributes attrs = OriginAttributesRef();
  attrs.StripUserContextIdAndFirstPartyDomain();

  nsAutoCString originNoSuffix;
  nsresult rv = GetOriginNoSuffix(originNoSuffix);
  NS_ENSURE_SUCCESS(rv, nullptr);

  nsCOMPtr<nsIURI> uri;
  rv = NS_NewURI(getter_AddRefs(uri), originNoSuffix);
  NS_ENSURE_SUCCESS(rv, nullptr);

  return BasePrincipal::CreateCodebasePrincipal(uri, attrs);
}

bool
BasePrincipal::AddonAllowsLoad(nsIURI* aURI)
{
+0 −4
Original line number Diff line number Diff line
@@ -107,8 +107,6 @@ public:

  // Inherit OriginAttributes from Necko.
  void InheritFromNecko(const NeckoOriginAttributes& aAttrs);

  void StripUserContextIdAndFirstPartyDomain();
};

// For OriginAttributes stored on docshells / loadcontexts / browsing contexts.
@@ -311,8 +309,6 @@ public:

  virtual PrincipalKind Kind() = 0;

  already_AddRefed<BasePrincipal> CloneStrippingUserContextIdAndFirstPartyDomain();

protected:
  virtual ~BasePrincipal();

+1 −1
Original line number Diff line number Diff line
@@ -107,7 +107,7 @@ PermissionStatus::GetPrincipal() const
  }

  nsCOMPtr<nsIPrincipal> principal =
    mozilla::BasePrincipal::Cast(doc->NodePrincipal())->CloneStrippingUserContextIdAndFirstPartyDomain();
    mozilla::BasePrincipal::Cast(doc->NodePrincipal());
  NS_ENSURE_TRUE(principal, nullptr);

  return principal.forget();
Loading