From 8574d2db426889903c3ce0f647f4b9940de7e1c0 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Wed, 12 Dec 2012 10:40:33 -0500 Subject: [PATCH] Bug 782542 - Secure necko IPDL usage. r=ted,jduell a=blocking-b2g --- .../test_child_process_shutdown_message.html | 8 + .../templates/src/crashtests/crashtests.list | 2 +- docshell/base/LoadContext.cpp | 12 +- docshell/base/LoadContext.h | 17 +- .../mochitest/browserElementTestHelpers.js | 15 ++ dom/devicestorage/ipc/test_ipc.html | 3 + dom/indexedDB/ipc/test_ipc.html | 3 + dom/indexedDB/test/file_app_isolation.js | 7 +- dom/ipc/PBrowser.ipdl | 3 - dom/ipc/TabChild.cpp | 2 - dom/ipc/TabChild.h | 2 - dom/ipc/TabParent.cpp | 8 +- dom/ipc/TabParent.h | 2 - netwerk/cookie/CookieServiceChild.cpp | 26 ++- netwerk/cookie/CookieServiceParent.cpp | 65 +++++--- netwerk/cookie/CookieServiceParent.h | 7 +- netwerk/cookie/PCookieService.ipdl | 7 +- netwerk/ipc/NeckoChild.cpp | 6 +- netwerk/ipc/NeckoChild.h | 5 +- netwerk/ipc/NeckoParent.cpp | 149 ++++++++++++++++-- netwerk/ipc/NeckoParent.h | 35 +++- netwerk/ipc/PNecko.ipdl | 4 +- netwerk/protocol/ftp/FTPChannelChild.cpp | 31 +++- netwerk/protocol/ftp/FTPChannelParent.cpp | 21 ++- netwerk/protocol/ftp/FTPChannelParent.h | 8 +- netwerk/protocol/ftp/PFTPChannel.ipdl | 4 +- netwerk/protocol/http/HttpChannelParent.cpp | 18 +-- netwerk/protocol/http/HttpChannelParent.h | 10 +- netwerk/protocol/websocket/PWebSocket.ipdl | 3 +- .../websocket/WebSocketChannelChild.cpp | 6 +- .../websocket/WebSocketChannelParent.cpp | 19 +-- .../websocket/WebSocketChannelParent.h | 8 +- netwerk/protocol/wyciwyg/PWyciwygChannel.ipdl | 4 +- .../protocol/wyciwyg/WyciwygChannelChild.cpp | 12 +- .../protocol/wyciwyg/WyciwygChannelParent.cpp | 17 +- .../protocol/wyciwyg/WyciwygChannelParent.h | 7 +- .../prefetch/OfflineCacheUpdateChild.cpp | 1 - .../prefetch/OfflineCacheUpdateParent.cpp | 13 +- uriloader/prefetch/OfflineCacheUpdateParent.h | 8 +- 39 files changed, 416 insertions(+), 162 deletions(-) diff --git a/content/base/test/test_child_process_shutdown_message.html b/content/base/test/test_child_process_shutdown_message.html index 40d5c7f6bea2..dfebea910c74 100644 --- a/content/base/test/test_child_process_shutdown_message.html +++ b/content/base/test/test_child_process_shutdown_message.html @@ -112,6 +112,10 @@ function setUp() { SpecialPowers.setBoolPref("dom.ipc.browser_frames.oop_by_default", true); SpecialPowers.addPermission("browser", true, window.document); SpecialPowers.addPermission("embed-apps", true, window.document); + + // TODO: remove in bug 820712 + SpecialPowers.setBoolPref("network.disable.ipc.security", true); + runNextTest(); } @@ -136,6 +140,10 @@ function makeKillTest(isApp) function testKill() { function tearDown() { SpecialPowers.clearUserPref("dom.mozBrowserFramesEnabled"); SpecialPowers.clearUserPref("dom.ipc.browser_frames.oop_by_default"); + + // TODO: remove in bug 820712 + SpecialPowers.clearUserPref("network.disable.ipc.security"); + SimpleTest.finish(); } diff --git a/content/xul/templates/src/crashtests/crashtests.list b/content/xul/templates/src/crashtests/crashtests.list index 6ffd2e9ec7c8..fbc33ba1675c 100644 --- a/content/xul/templates/src/crashtests/crashtests.list +++ b/content/xul/templates/src/crashtests/crashtests.list @@ -1,7 +1,7 @@ load 257752-1-recursion.xul load 329335-1.xul load 329884-1.xul -skip-if(winWidget) HTTP load 330010-1.xul # bug 742455 +skip-if(winWidget||browserIsRemote) HTTP load 330010-1.xul # bugs 742455 and 823470 skip-if(winWidget) load 330012-1.xul # bug 742455 skip-if(winWidget) load 397148-1.xul # bug 742455 load 404346-1.xul diff --git a/docshell/base/LoadContext.cpp b/docshell/base/LoadContext.cpp index 6861ecac3d61..7bf55a466590 100644 --- a/docshell/base/LoadContext.cpp +++ b/docshell/base/LoadContext.cpp @@ -8,22 +8,12 @@ #include "nsIScriptSecurityManager.h" #include "nsServiceManagerUtils.h" #include "nsContentUtils.h" +#include "mozIApplication.h" namespace mozilla { NS_IMPL_ISUPPORTS1(LoadContext, nsILoadContext); -LoadContext::LoadContext(const IPC::SerializedLoadContext& aToCopy, - nsIDOMElement* aTopFrameElemenet) - : mIsNotNull(aToCopy.mIsNotNull) - , mIsContent(aToCopy.mIsContent) - , mUsePrivateBrowsing(aToCopy.mUsePrivateBrowsing) - , mIsInBrowserElement(aToCopy.mIsInBrowserElement) - , mAppId(aToCopy.mAppId) - , mTopFrameElement(do_GetWeakReference(aTopFrameElemenet)) -{} - - //----------------------------------------------------------------------------- // LoadContext::nsILoadContext //----------------------------------------------------------------------------- diff --git a/docshell/base/LoadContext.h b/docshell/base/LoadContext.h index 29961ca44ac7..c1ba521b9bbd 100644 --- a/docshell/base/LoadContext.h +++ b/docshell/base/LoadContext.h @@ -10,6 +10,9 @@ #include "SerializedLoadContext.h" #include "mozilla/Attributes.h" #include "nsWeakReference.h" +#include "nsIDOMElement.h" + +class mozIApplication; namespace mozilla { @@ -29,17 +32,19 @@ public: NS_DECL_ISUPPORTS NS_DECL_NSILOADCONTEXT - LoadContext(const IPC::SerializedLoadContext& aToCopy) + // AppId/inBrowser arguments override those in SerializedLoadContext provided + // by child process. + LoadContext(const IPC::SerializedLoadContext& aToCopy, + nsIDOMElement* aTopFrameElement, + uint32_t aAppId, bool aInBrowser) : mIsNotNull(aToCopy.mIsNotNull) , mIsContent(aToCopy.mIsContent) , mUsePrivateBrowsing(aToCopy.mUsePrivateBrowsing) - , mIsInBrowserElement(aToCopy.mIsInBrowserElement) - , mAppId(aToCopy.mAppId) + , mIsInBrowserElement(aInBrowser) + , mAppId(aAppId) + , mTopFrameElement(do_GetWeakReference(aTopFrameElement)) {} - LoadContext(const IPC::SerializedLoadContext& aToCopy, - nsIDOMElement* aTopFrameElemenet); - private: bool mIsNotNull; bool mIsContent; diff --git a/dom/browser-element/mochitest/browserElementTestHelpers.js b/dom/browser-element/mochitest/browserElementTestHelpers.js index 356e8f0f92ff..4d9b1e56d461 100644 --- a/dom/browser-element/mochitest/browserElementTestHelpers.js +++ b/dom/browser-element/mochitest/browserElementTestHelpers.js @@ -65,6 +65,14 @@ const browserElementTestHelpers = { return this._setBoolPref("dom.ipc.browser_frames.oop_by_default", value); }, + getIPCSecurityDisabledPref: function() { + return this._getBoolPref("network.disable.ipc.security"); + }, + + setIPCSecurityDisabledPref: function(value) { + return this._setBoolPref("network.disable.ipc.security", value); + }, + getPageThumbsEnabledPref: function() { return this._getBoolPref('browser.pageThumbs.enabled'); }, @@ -94,6 +102,7 @@ const browserElementTestHelpers = { this.setOOPDisabledPref(this.origOOPDisabledPref); this.setOOPByDefaultPref(this.origOOPByDefaultPref); this.setPageThumbsEnabledPref(this.origPageThumbsEnabledPref); + this.setIPCSecurityDisabledPref(this.origIPCSecurityPref); this.removeAllTempPermissions(); }, @@ -101,6 +110,7 @@ const browserElementTestHelpers = { 'origOOPDisabledPref': null, 'origOOPByDefaultPref': null, 'origPageThumbsEnabledPref': null, + 'origIPCSecurityPref': null, 'tempPermissions': [], // Some basically-empty pages from different domains you can load. @@ -122,6 +132,7 @@ browserElementTestHelpers.origEnabledPref = browserElementTestHelpers.getEnabled browserElementTestHelpers.origOOPDisabledPref = browserElementTestHelpers.getOOPDisabledPref(); browserElementTestHelpers.origOOPByDefaultPref = browserElementTestHelpers.getOOPByDefaultPref(); browserElementTestHelpers.origPageThumbsEnabledPref = browserElementTestHelpers.getPageThumbsEnabledPref(); +browserElementTestHelpers.origIPCSecurityPref = browserElementTestHelpers.getIPCSecurityDisabledPref(); // Disable tab view; it seriously messes us up. browserElementTestHelpers.setPageThumbsEnabledPref(false); @@ -133,6 +144,10 @@ var oop = location.pathname.indexOf('_inproc_') == -1; browserElementTestHelpers.setOOPByDefaultPref(oop); browserElementTestHelpers.setOOPDisabledPref(false); +// Disable the networking security checks; our test harness just tests browser elements +// without sticking them in apps, and the security checks dislike that. +browserElementTestHelpers.setIPCSecurityDisabledPref(true); + addEventListener('unload', function() { browserElementTestHelpers.restoreOriginalPrefs(); }); diff --git a/dom/devicestorage/ipc/test_ipc.html b/dom/devicestorage/ipc/test_ipc.html index f0836eacd35a..1366f54dd27b 100644 --- a/dom/devicestorage/ipc/test_ipc.html +++ b/dom/devicestorage/ipc/test_ipc.html @@ -153,6 +153,9 @@ ["device.storage.testing", true], ["device.storage.prompt.testing", true], + // TODO: remove this as part of bug 820712 + ["network.disable.ipc.security", true], + ["dom.ipc.browser_frames.oop_by_default", true], ["dom.mozBrowserFramesEnabled", true], ["browser.pageThumbs.enabled", false] diff --git a/dom/indexedDB/ipc/test_ipc.html b/dom/indexedDB/ipc/test_ipc.html index 7cb1971aaf72..fe4e0c722640 100644 --- a/dom/indexedDB/ipc/test_ipc.html +++ b/dom/indexedDB/ipc/test_ipc.html @@ -168,6 +168,9 @@ SpecialPowers.addPermission("browser", true, document); SpecialPowers.pushPrefEnv({ "set": [ + // TODO: remove this as part of bug 820712 + ["network.disable.ipc.security", true], + ["dom.ipc.browser_frames.oop_by_default", true], ["dom.mozBrowserFramesEnabled", true] ] diff --git a/dom/indexedDB/test/file_app_isolation.js b/dom/indexedDB/test/file_app_isolation.js index 514fb5824b65..704288f7b260 100644 --- a/dom/indexedDB/test/file_app_isolation.js +++ b/dom/indexedDB/test/file_app_isolation.js @@ -159,5 +159,10 @@ if (!SpecialPowers.isMainProcess()) { todo(false, "We should make this work on content process"); SimpleTest.finish(); } else { - startTest(); + // TODO: remove unsetting network.disable.ipc.security as part of bug 820712 + SpecialPowers.pushPrefEnv({ + "set": [ + ["network.disable.ipc.security", true], + ] + }, startTest); } diff --git a/dom/ipc/PBrowser.ipdl b/dom/ipc/PBrowser.ipdl index 7ccc34c952b6..a7270b93d557 100644 --- a/dom/ipc/PBrowser.ipdl +++ b/dom/ipc/PBrowser.ipdl @@ -216,8 +216,6 @@ parent: * URI of the manifest to fetch, the application cache group ID * @param documentURI * URI of the document that referred the manifest - * @param clientID - * The group cache version identifier to use * @param stickDocument * True if the update was initiated by a document load that referred * a manifest. @@ -235,7 +233,6 @@ parent: * has already been cached (stickDocument=false). */ POfflineCacheUpdate(URIParams manifestURI, URIParams documentURI, - bool isInBrowserElement, uint32_t appId, bool stickDocument); sync PIndexedDB(nsCString asciiOrigin) diff --git a/dom/ipc/TabChild.cpp b/dom/ipc/TabChild.cpp index 03fe4aa97ecc..eb480234d384 100644 --- a/dom/ipc/TabChild.cpp +++ b/dom/ipc/TabChild.cpp @@ -1576,8 +1576,6 @@ TabChild::RecvActivateFrameEvent(const nsString& aType, const bool& capture) POfflineCacheUpdateChild* TabChild::AllocPOfflineCacheUpdate(const URIParams& manifestURI, const URIParams& documentURI, - const bool& isInBrowserElement, - const uint32_t& appId, const bool& stickDocument) { NS_RUNTIMEABORT("unused"); diff --git a/dom/ipc/TabChild.h b/dom/ipc/TabChild.h index 3e76ee766aaa..e565c1f1ceb8 100644 --- a/dom/ipc/TabChild.h +++ b/dom/ipc/TabChild.h @@ -277,8 +277,6 @@ public: virtual POfflineCacheUpdateChild* AllocPOfflineCacheUpdate( const URIParams& manifestURI, const URIParams& documentURI, - const bool& isInBrowserElement, - const uint32_t& appId, const bool& stickDocument); virtual bool DeallocPOfflineCacheUpdate(POfflineCacheUpdateChild* offlineCacheUpdate); diff --git a/dom/ipc/TabParent.cpp b/dom/ipc/TabParent.cpp index e252345fe792..70a607aa7081 100644 --- a/dom/ipc/TabParent.cpp +++ b/dom/ipc/TabParent.cpp @@ -1132,15 +1132,13 @@ TabParent::DeallocPRenderFrame(PRenderFrameParent* aFrame) mozilla::docshell::POfflineCacheUpdateParent* TabParent::AllocPOfflineCacheUpdate(const URIParams& aManifestURI, const URIParams& aDocumentURI, - const bool& isInBrowserElement, - const uint32_t& appId, const bool& stickDocument) { nsRefPtr update = - new mozilla::docshell::OfflineCacheUpdateParent(); + new mozilla::docshell::OfflineCacheUpdateParent(OwnOrContainingAppId(), + IsBrowserElement()); - nsresult rv = update->Schedule(aManifestURI, aDocumentURI, - isInBrowserElement, appId, stickDocument); + nsresult rv = update->Schedule(aManifestURI, aDocumentURI, stickDocument); if (NS_FAILED(rv)) return nullptr; diff --git a/dom/ipc/TabParent.h b/dom/ipc/TabParent.h index c44528fc8f70..bd640e3c9b7d 100644 --- a/dom/ipc/TabParent.h +++ b/dom/ipc/TabParent.h @@ -191,8 +191,6 @@ public: virtual POfflineCacheUpdateParent* AllocPOfflineCacheUpdate( const URIParams& aManifestURI, const URIParams& aDocumentURI, - const bool& isInBrowserElement, - const uint32_t& appId, const bool& stickDocument); virtual bool DeallocPOfflineCacheUpdate(POfflineCacheUpdateParent* actor); diff --git a/netwerk/cookie/CookieServiceChild.cpp b/netwerk/cookie/CookieServiceChild.cpp index a20b33bff158..d0e88c578103 100644 --- a/netwerk/cookie/CookieServiceChild.cpp +++ b/netwerk/cookie/CookieServiceChild.cpp @@ -4,12 +4,14 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "mozilla/net/CookieServiceChild.h" - +#include "mozilla/dom/TabChild.h" #include "mozilla/ipc/URIUtils.h" #include "mozilla/net/NeckoChild.h" #include "nsIURI.h" #include "nsIPrefService.h" #include "nsIPrefBranch.h" +#include "nsITabChild.h" +#include "nsNetUtil.h" using namespace mozilla::ipc; @@ -115,10 +117,19 @@ CookieServiceChild::GetCookieStringInternal(nsIURI *aHostURI, URIParams uriParams; SerializeURI(aHostURI, uriParams); + nsCOMPtr iTabChild; + mozilla::dom::TabChild* tabChild = nullptr; + if (aChannel) { + NS_QueryNotificationCallbacks(aChannel, iTabChild); + if (iTabChild) { + tabChild = static_cast(iTabChild.get()); + } + } + // Synchronously call the parent. nsAutoCString result; SendGetCookieString(uriParams, !!isForeign, aFromHttp, - IPC::SerializedLoadContext(aChannel), &result); + IPC::SerializedLoadContext(aChannel), tabChild, &result); if (!result.IsEmpty()) *aCookieString = ToNewCString(result); @@ -148,9 +159,18 @@ CookieServiceChild::SetCookieStringInternal(nsIURI *aHostURI, URIParams uriParams; SerializeURI(aHostURI, uriParams); + nsCOMPtr iTabChild; + mozilla::dom::TabChild* tabChild = nullptr; + if (aChannel) { + NS_QueryNotificationCallbacks(aChannel, iTabChild); + if (iTabChild) { + tabChild = static_cast(iTabChild.get()); + } + } + // Synchronously call the parent. SendSetCookieString(uriParams, !!isForeign, cookieString, serverTime, - aFromHttp, IPC::SerializedLoadContext(aChannel)); + aFromHttp, IPC::SerializedLoadContext(aChannel), tabChild); return NS_OK; } diff --git a/netwerk/cookie/CookieServiceParent.cpp b/netwerk/cookie/CookieServiceParent.cpp index 90cb528574f6..7cc0c57a12bb 100644 --- a/netwerk/cookie/CookieServiceParent.cpp +++ b/netwerk/cookie/CookieServiceParent.cpp @@ -4,37 +4,44 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "mozilla/net/CookieServiceParent.h" +#include "mozilla/dom/PBrowserParent.h" +#include "mozilla/net/NeckoParent.h" #include "mozilla/ipc/URIUtils.h" #include "nsCookieService.h" #include "nsNetUtil.h" +#include "nsPrintfCString.h" using namespace mozilla::ipc; - -static void -GetAppInfoFromLoadContext(const IPC::SerializedLoadContext &aLoadContext, - uint32_t& aAppId, - bool& aIsInBrowserElement, - bool& aIsPrivate) -{ - // TODO: bug 782542: what to do when we get null loadContext? For now assume - // NECKO_NO_APP_ID. - aAppId = NECKO_NO_APP_ID; - aIsInBrowserElement = false; - aIsPrivate = false; - - if (aLoadContext.IsNotNull()) { - aAppId = aLoadContext.mAppId; - aIsInBrowserElement = aLoadContext.mIsInBrowserElement; - } - - if (aLoadContext.IsPrivateBitValid()) - aIsPrivate = aLoadContext.mUsePrivateBrowsing; -} +using mozilla::dom::PBrowserParent; +using mozilla::net::NeckoParent; namespace mozilla { namespace net { +MOZ_WARN_UNUSED_RESULT +static bool +GetAppInfoFromParams(const IPC::SerializedLoadContext &aLoadContext, + PBrowserParent* aBrowser, + uint32_t& aAppId, + bool& aIsInBrowserElement) +{ + aAppId = NECKO_NO_APP_ID; + aIsInBrowserElement = false; + + const char* error = NeckoParent::GetValidatedAppInfo(aLoadContext, aBrowser, + &aAppId, + &aIsInBrowserElement); + if (error) { + NS_WARNING(nsPrintfCString("CookieServiceParent: GetAppInfoFromParams: " + "FATAL error: %s: KILLING CHILD PROCESS\n", + error).get()); + return false; + } + + return true; +} + CookieServiceParent::CookieServiceParent() { // Instantiate the cookieservice via the service manager, so it sticks around @@ -57,6 +64,7 @@ CookieServiceParent::RecvGetCookieString(const URIParams& aHost, const bool& aFromHttp, const IPC::SerializedLoadContext& aLoadContext, + PBrowserParent* aBrowser, nsCString* aResult) { if (!mCookieService) @@ -70,7 +78,11 @@ CookieServiceParent::RecvGetCookieString(const URIParams& aHost, uint32_t appId; bool isInBrowserElement, isPrivate; - GetAppInfoFromLoadContext(aLoadContext, appId, isInBrowserElement, isPrivate); + bool valid = GetAppInfoFromParams(aLoadContext, aBrowser, appId, + isInBrowserElement); + if (!valid) { + return false; + } mCookieService->GetCookieStringInternal(hostURI, aIsForeign, aFromHttp, appId, isInBrowserElement, isPrivate, *aResult); @@ -84,7 +96,8 @@ CookieServiceParent::RecvSetCookieString(const URIParams& aHost, const nsCString& aServerTime, const bool& aFromHttp, const IPC::SerializedLoadContext& - aLoadContext) + aLoadContext, + PBrowserParent* aBrowser) { if (!mCookieService) return true; @@ -97,7 +110,11 @@ CookieServiceParent::RecvSetCookieString(const URIParams& aHost, uint32_t appId; bool isInBrowserElement, isPrivate; - GetAppInfoFromLoadContext(aLoadContext, appId, isInBrowserElement, isPrivate); + bool valid = GetAppInfoFromParams(aLoadContext, aBrowser, appId, + isInBrowserElement); + if (!valid) { + return false; + } nsDependentCString cookieString(aCookieString, 0); //TODO: bug 812475, pass a real channel object diff --git a/netwerk/cookie/CookieServiceParent.h b/netwerk/cookie/CookieServiceParent.h index d51a209287ff..ec228ae6a67e 100644 --- a/netwerk/cookie/CookieServiceParent.h +++ b/netwerk/cookie/CookieServiceParent.h @@ -13,6 +13,9 @@ class nsCookieService; class nsIIOService; namespace mozilla { +namespace dom { + class PBrowserParent; +} namespace net { class CookieServiceParent : public PCookieServiceParent @@ -27,6 +30,7 @@ protected: const bool& aFromHttp, const IPC::SerializedLoadContext& loadContext, + mozilla::dom::PBrowserParent* aBrowser, nsCString* aResult); virtual bool RecvSetCookieString(const URIParams& aHost, @@ -35,7 +39,8 @@ protected: const nsCString& aServerTime, const bool& aFromHttp, const IPC::SerializedLoadContext& - loadContext); + loadContext, + mozilla::dom::PBrowserParent* aBrowser); nsRefPtr mCookieService; }; diff --git a/netwerk/cookie/PCookieService.ipdl b/netwerk/cookie/PCookieService.ipdl index 768eabf1f53e..5a004a9b1581 100644 --- a/netwerk/cookie/PCookieService.ipdl +++ b/netwerk/cookie/PCookieService.ipdl @@ -6,6 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ include protocol PNecko; +include protocol PBrowser; include URIParams; include "SerializedLoadContext.h"; @@ -64,7 +65,8 @@ parent: sync GetCookieString(URIParams host, bool isForeign, bool fromHttp, - SerializedLoadContext loadContext) + SerializedLoadContext loadContext, + nullable PBrowser browser) returns (nsCString result); /* @@ -101,7 +103,8 @@ parent: nsCString cookieString, nsCString serverTime, bool fromHttp, - SerializedLoadContext loadContext); + SerializedLoadContext loadContext, + nullable PBrowser browser); __delete__(); }; diff --git a/netwerk/ipc/NeckoChild.cpp b/netwerk/ipc/NeckoChild.cpp index 2eaa36849e11..195495a2ee43 100644 --- a/netwerk/ipc/NeckoChild.cpp +++ b/netwerk/ipc/NeckoChild.cpp @@ -86,7 +86,8 @@ NeckoChild::DeallocPHttpChannel(PHttpChannelChild* channel) } PFTPChannelChild* -NeckoChild::AllocPFTPChannel() +NeckoChild::AllocPFTPChannel(PBrowserChild* aBrowser, + const SerializedLoadContext& aSerialized) { // We don't allocate here: see FTPChannelChild::AsyncOpen() NS_RUNTIMEABORT("AllocPFTPChannel should not be called"); @@ -140,7 +141,8 @@ NeckoChild::DeallocPWyciwygChannel(PWyciwygChannelChild* channel) } PWebSocketChild* -NeckoChild::AllocPWebSocket(PBrowserChild* browser) +NeckoChild::AllocPWebSocket(PBrowserChild* browser, + const SerializedLoadContext& aSerialized) { NS_NOTREACHED("AllocPWebSocket should not be called"); return nullptr; diff --git a/netwerk/ipc/NeckoChild.h b/netwerk/ipc/NeckoChild.h index 1b3455a4c72d..c8c10de230e3 100644 --- a/netwerk/ipc/NeckoChild.h +++ b/netwerk/ipc/NeckoChild.h @@ -33,9 +33,10 @@ protected: virtual bool DeallocPCookieService(PCookieServiceChild*); virtual PWyciwygChannelChild* AllocPWyciwygChannel(); virtual bool DeallocPWyciwygChannel(PWyciwygChannelChild*); - virtual PFTPChannelChild* AllocPFTPChannel(); + virtual PFTPChannelChild* AllocPFTPChannel(PBrowserChild* aBrowser, + const SerializedLoadContext& aSerialized); virtual bool DeallocPFTPChannel(PFTPChannelChild*); - virtual PWebSocketChild* AllocPWebSocket(PBrowserChild*); + virtual PWebSocketChild* AllocPWebSocket(PBrowserChild*, const SerializedLoadContext&); virtual bool DeallocPWebSocket(PWebSocketChild*); virtual PTCPSocketChild* AllocPTCPSocket(const nsString& aHost, const uint16_t& aPort, diff --git a/netwerk/ipc/NeckoParent.cpp b/netwerk/ipc/NeckoParent.cpp index 9c5e80739a7f..a550d4568f82 100644 --- a/netwerk/ipc/NeckoParent.cpp +++ b/netwerk/ipc/NeckoParent.cpp @@ -17,7 +17,8 @@ #include "mozilla/dom/network/TCPSocketParent.h" #include "mozilla/ipc/URIUtils.h" #include "mozilla/Preferences.h" - +#include "mozilla/LoadContext.h" +#include "nsPrintfCString.h" #include "nsHTMLDNSPrefetch.h" #include "nsIAppsService.h" #include "nsEscape.h" @@ -25,6 +26,7 @@ using mozilla::dom::TabParent; using mozilla::net::PTCPSocketParent; using mozilla::dom::TCPSocketParent; +using IPC::SerializedLoadContext; namespace mozilla { namespace net { @@ -57,11 +59,116 @@ NeckoParent::~NeckoParent() { } -PHttpChannelParent* -NeckoParent::AllocPHttpChannel(PBrowserParent* browser, - const SerializedLoadContext& loadContext) +static PBOverrideStatus +PBOverrideStatusFromLoadContext(const SerializedLoadContext& aSerialized) { - HttpChannelParent *p = new HttpChannelParent(browser, loadContext); + if (!aSerialized.IsNotNull() && aSerialized.IsPrivateBitValid()) { + return aSerialized.mUsePrivateBrowsing ? + kPBOverride_Private : + kPBOverride_NotPrivate; + } + return kPBOverride_Unset; +} + +const char* +NeckoParent::GetValidatedAppInfo(const SerializedLoadContext& aSerialized, + PBrowserParent* aBrowser, + uint32_t* aAppId, + bool* aInBrowserElement) +{ + if (!gDisableIPCSecurity) { + if (!aBrowser) { + return "missing required PBrowser argument"; + } + if (!aSerialized.IsNotNull()) { + return "SerializedLoadContext from child is null"; + } + } + + *aAppId = NECKO_UNKNOWN_APP_ID; + *aInBrowserElement = false; + + if (aBrowser) { + nsRefPtr tabParent = static_cast(aBrowser); + + *aAppId = tabParent->OwnOrContainingAppId(); + *aInBrowserElement = tabParent->IsBrowserElement(); + + if (*aAppId == NECKO_UNKNOWN_APP_ID) { + return "TabParent reports appId=NECKO_UNKNOWN_APP_ID!"; + } + // We may get appID=NO_APP if child frame is neither a browser nor an app + if (*aAppId == NECKO_NO_APP_ID) { + if (tabParent->HasOwnApp()) { + return "TabParent reports NECKO_NO_APP_ID but also is an app"; + } + if (!gDisableIPCSecurity && tabParent->IsBrowserElement()) { + //