$OpenBSD$ index 741e815..46848ec 100644 --- dom/base/nsGlobalWindow.cpp.orig Fri Feb 20 15:40:37 2015 +++ dom/base/nsGlobalWindow.cpp Fri Feb 20 15:40:37 2015 @@ -2671,6 +2671,11 @@ nsGlobalWindow::PreloadLocalStorage() } nsresult rv; + nsCOMPtr firstPartyIsolationURI; + rv = GetFirstPartyIsolationURI(getter_AddRefs(firstPartyIsolationURI)); + if (NS_FAILED(rv)) { + return; + } nsCOMPtr storageManager = do_GetService("@mozilla.org/dom/localStorage-manager;1", &rv); @@ -2678,7 +2683,7 @@ nsGlobalWindow::PreloadLocalStorage() return; } - storageManager->PrecacheStorage(principal); + storageManager->PrecacheStorageForFirstParty(firstPartyIsolationURI, principal); } void @@ -4861,6 +4866,12 @@ nsGlobalWindow::GetOuterSize(ErrorResult& aError) { MOZ_ASSERT(IsOuterWindow()); + if (!IsChrome()) { + CSSIntSize size; + aError = GetInnerSize(size); + return nsIntSize(size.width, size.height); + } + nsCOMPtr treeOwnerAsWin = GetTreeOwnerWindow(); if (!treeOwnerAsWin) { aError.Throw(NS_ERROR_FAILURE); @@ -4992,6 +5003,11 @@ nsGlobalWindow::GetScreenXY(ErrorResult& aError) { MOZ_ASSERT(IsOuterWindow()); + // For non-chrome callers, always return (0,0) to prevent fingerprinting. + if (!IsChrome()) { + return nsIntPoint(0, 0); + } + nsCOMPtr treeOwnerAsWin = GetTreeOwnerWindow(); if (!treeOwnerAsWin) { aError.Throw(NS_ERROR_FAILURE); @@ -5056,6 +5072,9 @@ nsGlobalWindow::GetMozInnerScreenX(ErrorResult& aError) { FORWARD_TO_OUTER_OR_THROW(GetMozInnerScreenX, (aError), aError, 0); + // For non-chrome callers, always return 0 to prevent fingerprinting. + if (!IsChrome()) return 0.0; + nsRect r = GetInnerScreenRect(); return nsPresContext::AppUnitsToFloatCSSPixels(r.x); } @@ -5074,6 +5093,9 @@ nsGlobalWindow::GetMozInnerScreenY(ErrorResult& aError) { FORWARD_TO_OUTER_OR_THROW(GetMozInnerScreenY, (aError), aError, 0); + // For non-chrome callers, always return 0 to prevent fingerprinting. + if (!IsChrome()) return 0.0; + nsRect r = GetInnerScreenRect(); return nsPresContext::AppUnitsToFloatCSSPixels(r.y); } @@ -5412,6 +5434,20 @@ nsGlobalWindow::SetScreenY(int32_t aScreenY) return rv.ErrorCode(); } +bool +nsGlobalWindow::IsChrome() const +{ + bool isChrome = false; + + if (mDocShell) { + nsRefPtr presContext; + mDocShell->GetPresContext(getter_AddRefs(presContext)); + isChrome = (presContext && presContext->IsChrome()); + } + + return isChrome; +} + // NOTE: Arguments to this function should have values scaled to // CSS pixels, not device pixels. void @@ -7675,6 +7711,19 @@ nsGlobalWindow::CallerInnerWindow() return static_cast(win.get()); } +nsresult +nsGlobalWindow::GetFirstPartyIsolationURI(nsIURI** aFirstPartyIsolationURI) +{ + nsCOMPtr thirdPartyUtil = + do_GetService(THIRDPARTYUTIL_CONTRACTID); + if (!thirdPartyUtil) + return NS_ERROR_FAILURE; + + nsCOMPtr doc = do_QueryInterface(mDoc); + return thirdPartyUtil->GetFirstPartyIsolationURI(NULL, doc, aFirstPartyIsolationURI); +} + + /** * Class used to represent events generated by calls to Window.postMessage, * which asynchronously creates and dispatches events. @@ -10240,7 +10289,14 @@ nsGlobalWindow::GetSessionStorage(ErrorResult& aError) nsCOMPtr loadContext = do_QueryInterface(docShell); - aError = storageManager->CreateStorage(principal, + nsCOMPtr firstPartyIsolationURI; + rv = GetFirstPartyIsolationURI(getter_AddRefs(firstPartyIsolationURI)); + if (NS_FAILED(rv)) { + aError.Throw(rv); + return nullptr; + } + + aError = storageManager->CreateStorageForFirstParty(firstPartyIsolationURI, principal, documentURI, loadContext && loadContext->UsePrivateBrowsing(), getter_AddRefs(mSessionStorage)); @@ -10319,10 +10375,17 @@ nsGlobalWindow::GetLocalStorage(ErrorResult& aError) mDoc->GetDocumentURI(documentURI); } + nsCOMPtr firstPartyIsolationURI; + rv = GetFirstPartyIsolationURI(getter_AddRefs(firstPartyIsolationURI)); + if (NS_FAILED(rv)) { + aError.Throw(rv); + return nullptr; + } + nsIDocShell* docShell = GetDocShell(); nsCOMPtr loadContext = do_QueryInterface(docShell); - aError = storageManager->CreateStorage(principal, + aError = storageManager->CreateStorageForFirstParty(firstPartyIsolationURI, principal, documentURI, loadContext && loadContext->UsePrivateBrowsing(), getter_AddRefs(mLocalStorage)); @@ -11134,7 +11197,13 @@ nsGlobalWindow::Observe(nsISupports* aSubject, const char* aTopic, nsCOMPtr storageManager = do_QueryInterface(GetDocShell()); if (storageManager) { - rv = storageManager->CheckStorage(principal, changingStorage, &check); + nsresult rv; + nsCOMPtr firstPartyIsolationURI; + rv = GetFirstPartyIsolationURI(getter_AddRefs(firstPartyIsolationURI)); + NS_ENSURE_SUCCESS(rv, rv); + + rv = storageManager->CheckStorageForFirstParty(firstPartyIsolationURI, + principal, changingStorage, &check); if (NS_FAILED(rv)) { return rv; } @@ -12521,8 +12590,18 @@ nsGlobalWindow::SecurityCheckURL(const char *aURL) nsCOMPtr sourceWindow; JSContext* topCx = nsContentUtils::GetCurrentJSContext(); if (topCx) { - sourceWindow = do_QueryInterface(nsJSUtils::GetDynamicScriptGlobal(topCx)); + nsCOMPtr entryWindow = + do_QueryInterface(nsJSUtils::GetDynamicScriptGlobal(topCx)); + if (entryWindow) { + nsIPrincipal* entryPrin = + static_cast(entryWindow.get())->GetPrincipal(); + nsIPrincipal* subjectPrin = nsContentUtils::GetSubjectPrincipal(); + if (subjectPrin->SubsumesConsideringDomain(entryPrin)) { + sourceWindow = entryWindow; + } + } } + if (!sourceWindow) { sourceWindow = this; }