From 386d23bfe734b76eea85c5339c70f171ba3034fb Mon Sep 17 00:00:00 2001 From: Bogdan Tara Date: Fri, 3 May 2019 06:12:25 +0300 Subject: [PATCH] Backed out 4 changesets (bug 1320404) for test_permmanager_load_invalid_entries.js failures Backed out changeset 7c2f4e64d38e (bug 1320404) Backed out changeset a7e7c0251179 (bug 1320404) Backed out changeset dd741b25a244 (bug 1320404) Backed out changeset de9073c57d20 (bug 1320404) --- ...browser_principalSerialization_version1.js | 6 + ...wser_restore_cookies_noOriginAttributes.js | 1 + caps/BasePrincipal.cpp | 12 + caps/BasePrincipal.h | 2 + caps/OriginAttributes.cpp | 17 +- caps/OriginAttributes.h | 18 +- caps/nsIPrincipal.idl | 18 ++ caps/nsIScriptSecurityManager.idl | 3 + caps/tests/gtest/TestOriginAttributes.cpp | 10 +- caps/tests/unit/test_origin.js | 89 ++++++- docshell/base/LoadContext.h | 7 +- docshell/base/nsDocShell.h | 2 +- dom/base/ChromeUtils.h | 3 +- dom/base/Document.cpp | 4 + dom/base/PostMessageEvent.cpp | 3 + dom/base/nsFrameLoader.cpp | 5 + .../test/test_messagemanager_principal.html | 3 + .../test_messagemanager_send_principal.html | 3 + .../test/test_messagemanager_targetchain.html | 5 +- .../mochitest/browserElement_Auth.js | 4 +- .../mochitest/browserElement_CopyPaste.js | 1 + dom/chrome-webidl/ChromeUtils.webidl | 2 + dom/ipc/BrowserBridgeParent.cpp | 1 + dom/ipc/PTabContext.ipdlh | 6 +- dom/ipc/TabContext.cpp | 5 + ..._presentation_mixed_security_contexts.html | 1 + .../test/xpcshell/test_clear_origin_data.js | 44 +++- .../test/xpcshell/test_notification_http2.js | 8 +- .../test/xpcshell/test_reconnect_retry.js | 4 +- .../xpcshell/test_register_5xxCode_http2.js | 1 + dom/push/test/xpcshell/test_register_case.js | 2 +- .../xpcshell/test_register_error_http2.js | 12 +- .../xpcshell/test_register_invalid_channel.js | 2 +- .../test_register_invalid_endpoint.js | 2 +- .../xpcshell/test_register_invalid_json.js | 2 +- dom/push/test/xpcshell/test_register_no_id.js | 2 +- .../xpcshell/test_register_request_queue.js | 4 +- .../test/xpcshell/test_register_rollback.js | 2 +- .../test/xpcshell/test_register_success.js | 2 +- .../xpcshell/test_register_success_http2.js | 4 +- .../test/xpcshell/test_register_timeout.js | 2 +- .../test/xpcshell/test_register_wrong_id.js | 2 +- .../test/xpcshell/test_register_wrong_type.js | 2 +- .../test/xpcshell/test_registration_error.js | 2 +- .../xpcshell/test_registration_error_http2.js | 2 +- .../test/xpcshell/test_registration_none.js | 2 +- .../xpcshell/test_registration_success.js | 16 ++ .../test_registration_success_http2.js | 8 +- .../xpcshell/test_unregister_empty_scope.js | 2 +- .../xpcshell/test_unregister_invalid_json.js | 2 +- .../xpcshell/test_unregister_not_found.js | 2 +- .../xpcshell/test_unregister_success_http2.js | 4 +- .../test_updateRecordNoEncryptionKeys_ws.js | 2 +- dom/quota/ActorsParent.cpp | 54 ++++- dom/quota/SerializationHelpers.h | 4 +- dom/quota/nsIQuotaManagerService.idl | 14 +- dom/quota/test/gtest/TestQuotaManager.cpp | 24 ++ .../test/unit/removeAppsUpgrade_profile.zip | Bin 0 -> 3145 bytes dom/quota/test/unit/test_removeAppsUpgrade.js | 66 ++++++ dom/quota/test/unit/xpcshell.ini | 2 + dom/serviceworkers/ServiceWorkerManager.cpp | 6 + dom/serviceworkers/ServiceWorkerManager.h | 5 +- .../test/gtest/TestReadWrite.cpp | 46 ++-- dom/storage/StorageDBUpdater.cpp | 3 +- dom/storage/StorageUtils.cpp | 6 +- dom/workers/WorkerLoadInfo.cpp | 2 +- .../permissions/nsPermissionManager.cpp | 112 +++------ .../test/unit/test_permmanager_cleardata.js | 12 +- .../test/unit/test_permmanager_defaults.js | 4 +- .../test_permmanager_load_invalid_entries.js | 43 ++-- .../test/unit/test_permmanager_matches.js | 146 +++++++++--- .../test/unit/test_permmanager_matchesuri.js | 6 +- .../test/unit/test_permmanager_migrate_4-7.js | 15 +- ...test_permmanager_migrate_4-7_no_history.js | 12 +- .../unit/test_permmanager_migrate_5-7a.js | 17 +- .../unit/test_permmanager_migrate_5-7b.js | 7 +- .../unit/test_permmanager_migrate_6-7a.js | 17 +- .../unit/test_permmanager_migrate_6-7b.js | 7 +- .../test/unit/test_permmanager_migrate_7-8.js | 4 +- .../unit/test_permmanager_migrate_9-10.js | 217 ------------------ .../unit/test_permmanager_removeforapp.js | 99 ++++++++ extensions/permissions/test/unit/xpcshell.ini | 2 +- ipc/glue/BackgroundUtils.cpp | 6 +- ipc/glue/ProtocolUtils.h | 3 + .../components/ContentPermissionPrompt.js | 14 +- netwerk/base/nsILoadContextInfo.idl | 3 + netwerk/base/nsNetUtil.h | 13 +- netwerk/cache2/CacheFileUtils.cpp | 3 +- netwerk/cache2/CacheStorageService.cpp | 2 +- netwerk/cookie/nsCookieService.cpp | 5 +- netwerk/ipc/NeckoParent.cpp | 2 +- netwerk/protocol/about/nsAboutCache.cpp | 8 +- netwerk/protocol/http/nsHttpChannel.h | 4 +- netwerk/test/unit/head_channels.js | 4 +- netwerk/test/unit/test_auth_jar.js | 22 +- netwerk/test/unit/test_cache_jar.js | 47 +++- .../content/SpecialPowersObserver.jsm | 4 +- .../specialpowers/content/specialpowersAPI.js | 1 + .../talos/talos/xtalos/xperf_whitelist.json | 6 - .../aboutcache/content/aboutCache.js | 8 +- toolkit/content/aboutServiceWorkers.js | 7 + .../toolkit/about/aboutServiceWorkers.ftl | 7 + 102 files changed, 944 insertions(+), 547 deletions(-) create mode 100644 dom/quota/test/unit/removeAppsUpgrade_profile.zip create mode 100644 dom/quota/test/unit/test_removeAppsUpgrade.js delete mode 100644 extensions/permissions/test/unit/test_permmanager_migrate_9-10.js create mode 100644 extensions/permissions/test/unit/test_permmanager_removeforapp.js diff --git a/browser/base/content/test/caps/browser_principalSerialization_version1.js b/browser/base/content/test/caps/browser_principalSerialization_version1.js index 51c54b270bfd3..e93c0fb75747d 100644 --- a/browser/base/content/test/caps/browser_principalSerialization_version1.js +++ b/browser/base/content/test/caps/browser_principalSerialization_version1.js @@ -113,6 +113,7 @@ add_task(async function test_realHistoryCheck() { "output": { "URI": false, "originAttributes": { + "appId": 0, "firstPartyDomain": "", "inIsolatedMozBrowser": false, "privateBrowsingId": 0, @@ -127,6 +128,7 @@ add_task(async function test_realHistoryCheck() { "cspJSON": "{\"csp-policies\":[{\"child-src\":[\"https://www.googletagmanager.com\",\"https://www.google-analytics.com\",\"https://www.youtube-nocookie.com\",\"https://trackertest.org\",\"https://www.surveygizmo.com\",\"https://accounts.firefox.com\",\"https://accounts.firefox.com.cn\",\"https://www.youtube.com\"],\"connect-src\":[\"'self'\",\"https://*.mozilla.net\",\"https://*.mozilla.org\",\"https://*.mozilla.com\",\"https://www.googletagmanager.com\",\"https://www.google-analytics.com\",\"https://accounts.firefox.com/\",\"https://accounts.firefox.com.cn/\"],\"default-src\":[\"'self'\",\"https://*.mozilla.net\",\"https://*.mozilla.org\",\"https://*.mozilla.com\"],\"frame-src\":[\"https://www.googletagmanager.com\",\"https://www.google-analytics.com\",\"https://www.youtube-nocookie.com\",\"https://trackertest.org\",\"https://www.surveygizmo.com\",\"https://accounts.firefox.com\",\"https://accounts.firefox.com.cn\",\"https://www.youtube.com\"],\"img-src\":[\"'self'\",\"https://*.mozilla.net\",\"https://*.mozilla.org\",\"https://*.mozilla.com\",\"data:\",\"https://mozilla.org\",\"https://www.googletagmanager.com\",\"https://www.google-analytics.com\",\"https://adservice.google.com\",\"https://adservice.google.de\",\"https://adservice.google.dk\",\"https://creativecommons.org\",\"https://ad.doubleclick.net\"],\"report-only\":false,\"script-src\":[\"'self'\",\"https://*.mozilla.net\",\"https://*.mozilla.org\",\"https://*.mozilla.com\",\"'unsafe-inline'\",\"'unsafe-eval'\",\"https://www.googletagmanager.com\",\"https://www.google-analytics.com\",\"https://tagmanager.google.com\",\"https://www.youtube.com\",\"https://s.ytimg.com\"],\"style-src\":[\"'self'\",\"https://*.mozilla.net\",\"https://*.mozilla.org\",\"https://*.mozilla.com\",\"'unsafe-inline'\"]}]}", "URISpec": "https://www.mozilla.org/en-US/", "originAttributes": { + "appId": 0, "firstPartyDomain": "", "inIsolatedMozBrowser": false, "privateBrowsingId": 0, @@ -139,6 +141,7 @@ add_task(async function test_realHistoryCheck() { "output": { "URISpec": "https://www.mozilla.org/en-US/firefox/accounts/", "originAttributes": { + "appId": 0, "firstPartyDomain": "", "inIsolatedMozBrowser": false, "privateBrowsingId": 0, @@ -152,6 +155,7 @@ add_task(async function test_realHistoryCheck() { "output": { "URISpec": "https://developer.mozilla.org/en-US/?utm_source=www.mozilla.org&utm_medium=referral&utm_campaign=nav&utm_content=developers", "originAttributes": { + "appId": 0, "firstPartyDomain": "", "inIsolatedMozBrowser": false, "privateBrowsingId": 0, @@ -165,6 +169,7 @@ add_task(async function test_realHistoryCheck() { "output": { "URI": false, "originAttributes": { + "appId": 0, "firstPartyDomain": "", "inIsolatedMozBrowser": false, "privateBrowsingId": 0, @@ -178,6 +183,7 @@ add_task(async function test_realHistoryCheck() { "output": { "URISpec": "moz-nullprincipal:{045ca18d-436c-4744-bbb6-b1a15366df79}", "originAttributes": { + "appId": 0, "firstPartyDomain": "", "inIsolatedMozBrowser": false, "privateBrowsingId": 0, diff --git a/browser/components/sessionstore/test/browser_restore_cookies_noOriginAttributes.js b/browser/components/sessionstore/test/browser_restore_cookies_noOriginAttributes.js index a05c01aeb1bd1..3e4a3d0fe5b08 100644 --- a/browser/components/sessionstore/test/browser_restore_cookies_noOriginAttributes.js +++ b/browser/components/sessionstore/test/browser_restore_cookies_noOriginAttributes.js @@ -107,6 +107,7 @@ const SESSION_DATA_OA = JSON.stringify( name: "test1", originAttributes: { addonId: "", + appId: 0, inIsolatedMozBrowser: false, userContextId: 0, }, diff --git a/caps/BasePrincipal.cpp b/caps/BasePrincipal.cpp index d0e99bbaa6455..c4fe508e934f6 100644 --- a/caps/BasePrincipal.cpp +++ b/caps/BasePrincipal.cpp @@ -293,6 +293,18 @@ BasePrincipal::GetOriginSuffix(nsACString& aOriginAttributes) { return NS_OK; } +NS_IMETHODIMP +BasePrincipal::GetAppId(uint32_t* aAppId) { + if (AppId() == nsIScriptSecurityManager::UNKNOWN_APP_ID) { + MOZ_ASSERT(false); + *aAppId = nsIScriptSecurityManager::NO_APP_ID; + return NS_OK; + } + + *aAppId = AppId(); + return NS_OK; +} + NS_IMETHODIMP BasePrincipal::GetUserContextId(uint32_t* aUserContextId) { *aUserContextId = UserContextId(); diff --git a/caps/BasePrincipal.h b/caps/BasePrincipal.h index d228505763ba3..15d5ad03053c9 100644 --- a/caps/BasePrincipal.h +++ b/caps/BasePrincipal.h @@ -122,6 +122,7 @@ class BasePrincipal : public nsJSPrincipals { NS_IMETHOD GetOriginAttributes(JSContext* aCx, JS::MutableHandle aVal) final; NS_IMETHOD GetOriginSuffix(nsACString& aOriginSuffix) final; + NS_IMETHOD GetAppId(uint32_t* aAppId) final; NS_IMETHOD GetIsInIsolatedMozBrowserElement( bool* aIsInIsolatedMozBrowserElement) final; NS_IMETHOD GetUserContextId(uint32_t* aUserContextId) final; @@ -153,6 +154,7 @@ class BasePrincipal : public nsJSPrincipals { const OriginAttributes& OriginAttributesRef() final { return mOriginAttributes; } + uint32_t AppId() const { return mOriginAttributes.mAppId; } extensions::WebExtensionPolicy* AddonPolicy(); uint32_t UserContextId() const { return mOriginAttributes.mUserContextId; } uint32_t PrivateBrowsingId() const { diff --git a/caps/OriginAttributes.cpp b/caps/OriginAttributes.cpp index 7f40e6549310b..bc4abe31a9654 100644 --- a/caps/OriginAttributes.cpp +++ b/caps/OriginAttributes.cpp @@ -133,6 +133,11 @@ void OriginAttributes::CreateSuffix(nsACString& aStr) const { // naming. // + if (mAppId != nsIScriptSecurityManager::NO_APP_ID) { + value.AppendInt(mAppId); + params.Set(NS_LITERAL_STRING("appId"), value); + } + if (mInIsolatedMozBrowser) { params.Set(NS_LITERAL_STRING("inBrowser"), NS_LITERAL_STRING("1")); } @@ -202,6 +207,16 @@ class MOZ_STACK_CLASS PopulateFromSuffixIterator final bool URLParamsIterator(const nsAString& aName, const nsAString& aValue) override { + if (aName.EqualsLiteral("appId")) { + nsresult rv; + int64_t val = aValue.ToInteger64(&rv); + NS_ENSURE_SUCCESS(rv, false); + NS_ENSURE_TRUE(val <= UINT32_MAX, false); + mOriginAttributes->mAppId = static_cast(val); + + return true; + } + if (aName.EqualsLiteral("inBrowser")) { if (!aValue.EqualsLiteral("1")) { return false; @@ -211,7 +226,7 @@ class MOZ_STACK_CLASS PopulateFromSuffixIterator final return true; } - if (aName.EqualsLiteral("addonId") || aName.EqualsLiteral("appId")) { + if (aName.EqualsLiteral("addonId")) { // No longer supported. Silently ignore so that legacy origin strings // don't cause failures. return true; diff --git a/caps/OriginAttributes.h b/caps/OriginAttributes.h index 9b36b797f0a2b..582265b290060 100644 --- a/caps/OriginAttributes.h +++ b/caps/OriginAttributes.h @@ -17,7 +17,8 @@ class OriginAttributes : public dom::OriginAttributesDictionary { public: OriginAttributes() {} - explicit OriginAttributes(bool aInIsolatedMozBrowser) { + OriginAttributes(uint32_t aAppId, bool aInIsolatedMozBrowser) { + mAppId = aAppId; mInIsolatedMozBrowser = aInIsolatedMozBrowser; } @@ -45,7 +46,8 @@ class OriginAttributes : public dom::OriginAttributesDictionary { } bool operator==(const OriginAttributes& aOther) const { - return mInIsolatedMozBrowser == aOther.mInIsolatedMozBrowser && + return mAppId == aOther.mAppId && + mInIsolatedMozBrowser == aOther.mInIsolatedMozBrowser && mUserContextId == aOther.mUserContextId && mPrivateBrowsingId == aOther.mPrivateBrowsingId && mFirstPartyDomain == aOther.mFirstPartyDomain; @@ -56,7 +58,8 @@ class OriginAttributes : public dom::OriginAttributesDictionary { } MOZ_MUST_USE bool EqualsIgnoringFPD(const OriginAttributes& aOther) const { - return mInIsolatedMozBrowser == aOther.mInIsolatedMozBrowser && + return mAppId == aOther.mAppId && + mInIsolatedMozBrowser == aOther.mInIsolatedMozBrowser && mUserContextId == aOther.mUserContextId && mPrivateBrowsingId == aOther.mPrivateBrowsingId; } @@ -126,6 +129,10 @@ class OriginAttributesPattern : public dom::OriginAttributesPatternDictionary { // Performs a match of |aAttrs| against this pattern. bool Matches(const OriginAttributes& aAttrs) const { + if (mAppId.WasPassed() && mAppId.Value() != aAttrs.mAppId) { + return false; + } + if (mInIsolatedMozBrowser.WasPassed() && mInIsolatedMozBrowser.Value() != aAttrs.mInIsolatedMozBrowser) { return false; @@ -150,6 +157,11 @@ class OriginAttributesPattern : public dom::OriginAttributesPatternDictionary { } bool Overlaps(const OriginAttributesPattern& aOther) const { + if (mAppId.WasPassed() && aOther.mAppId.WasPassed() && + mAppId.Value() != aOther.mAppId.Value()) { + return false; + } + if (mInIsolatedMozBrowser.WasPassed() && aOther.mInIsolatedMozBrowser.WasPassed() && mInIsolatedMozBrowser.Value() != aOther.mInIsolatedMozBrowser.Value()) { diff --git a/caps/nsIPrincipal.idl b/caps/nsIPrincipal.idl index 6c062c403822e..609cf4069185c 100644 --- a/caps/nsIPrincipal.idl +++ b/caps/nsIPrincipal.idl @@ -267,6 +267,24 @@ interface nsIPrincipal : nsISerializable */ readonly attribute ACString baseDomain; + /** + * Gets the id of the app this principal is inside. If this principal is + * not inside an app, returns nsIScriptSecurityManager::NO_APP_ID. + * + * Note that this principal does not necessarily have the permissions of + * the app identified by appId. For example, this principal might + * correspond to an iframe whose origin differs from that of the app frame + * containing it. In this case, the iframe will have the appId of its + * containing app frame, but the iframe must not run with the app's + * permissions. + * + * Similarly, this principal might correspond to an