mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:30:27 +00:00
fe9be1dd79
- Bug 1254848 part 1. Take ownership of error reporting on the AutoEntryScript in mozJSComponentLoader::ObjectForLocation. r=bholley (39b4b835e2)
- Bug 1254848 part 2. Take ownership of error reporting on the AutoEntryScript in mozJSComponentLoader::PrepareObjectForLocation. r=bholley (d0ca0f3b48)
- Bug 1254848 part 3. Take ownership of error reporting on the AutoEntryScript in AsyncScriptLoader::OnStreamComplete. r=bholley (d9059437f7)
- Bug 1254303 - Remove SEC_NORMAL from js/. r=sicking (a05bb976fc)
- Bug 1137151: Marked destructors of ref-counted MTP classes as protected, r=dhylands (683cd78bd7)
- Bug 1167090 - Fix MTP date and time queried through getObjectInfo. r=alchen (d1055dab5b)
- Bug 1188796 - Have MTP record modified timestamps when they're passed. r=alchen (7e09ea19c0)
- Bug 1205028 - Don't tell MTP server about files that it added/modified. r=alchen (65d84062ad)
- Bug 1174228 - Set up TYPE_APP for navigator.getDeviceStorage for B2GDroid r=dhylands (5cd46dda53)
- Bug 1242899 - consolidate mozApps tests into dom/apps/tests/ dir; r=marco (9208d75401)
- Bug 1238160 - Add assertions in non-desktop code paths. r=bz,fabrice (96ea4796b5)
- Bug 1176712 - Cannot have two activities with same name and different filters. Tests. r=fabrice (b5cd3f34fa)
- Bug 1251179 - Ensure that the lock protecting the CPU sleep functionality is always valid r=dhylands (dba414ecfa)
- Bug 1253571 - Remove the remaining uses of ScopedDeletePtr and ScopedFreePtr from the HAL and MTP code r=dhylands (a294472d97)
- Bug 1251519 Part 2 - Remove nsLayoutUtils::IsRectVisibleInScrollFrames(). r=mats (c73a0272b7)
- Bug 1212186 - Disable 'layout.word_select.eat_space_to_next_word' in carets tests. r=mtseng (7d231a66bf)
- Bug 1207934 - Fix word_location(). r=automatedtester (6828f466f1)
- Bug 1199625 - Test focus not being changed by long-pressing on non-selectable. r=mtseng (7aefe76cdc)
- Bug 1206545 - Add a marionette test case. r=roc (18e224214c)
- Bug 1209841 - Delete test_selectioncarets2.py. r=automatedtester (99c3d5d144)
- Bug 1221459 - Remove TouchCaret and SelectionCarets from marionette tests. r=mtseng (c9a452fe67)
- Bug 1253989 Part 1 - Remove tests for accessiblecaret preference off. r=mtseng (ddc3c57a93)
- Bug 1253989 Part 2 - Use @parameterized to rewrite cursor mode tests. r=mtseng (5a4cbff605)
- Bug 1201036: Bump marionette client and marionette driver for releases; r=jgriffin (9522a37ce7)
- Bug 1209698: Bump version numbers for Marionette packages; r=jgriffin (6a952dc063)
- Bug 1137972: Centralize unwrapping the response from marionette; r=jgriffin (78d40d42d2)
- Bug 1137972: Send W3C Element Key to Marionette Server from python client; r=jgriffin (074cbdb12c)
- Bug 1185486 - Part 1: Use a timeout when waiting on the browser process after a timed out command. r=jgriffin (ebb6f6421d)
- Bug 1159219: Make ContentSender a separate module (034e08ef83)
- Bug 1159238. Generate UUID internally to ContentSender (be45ead810)
- Bug 1185486 - Part 2: Prevent message listeners from a failed command from causing an out of order response when a content command hangs. r=ato (d706eaba14)
- Bug 1164124 - Add using_prefs context manager. r=jgriffin (f789f9a6fa)
- Bug 1211503: Support for Marionette protocol level 3 in the Python client (88d062980d)
- Bug 1211503: Support for Marionette protocol level 3 in the Python client (1d805ac020)
- Bug 1216967: Bump Marionette Python packages (5877bcee90)
- cleanup (56b0351ad3)
- Bug 1144240 - Fix generated Marionette documentation. r=ato (6beeb13017)
- Bug 1223171 - [marionette] add ability to install addons programatically, r=ato (c8d04e974a)
- Bug 1223517 - Release marionette-client 2.0.0 and marionette-driver 1.1.1; r=automatedtester (de1c1f1d18)
- Bug 1008453. Add support for navigator.hardwareConcurrency. r=khuey (ebd1c0e2d9)
- Bug 1200409 - |marionette --help| causes stack trace. r=ato (479af08b4f)
- Bug 1212608 - Add parts of firefox_ui_harness to Marionette runner; r=automatedtester (9977013243)
- Bug 1222388: Correct ./mach marionette-test r=ato (27bae1cbf9)
- Bug 1223429 - Return exit code 10 when Marionette harness has failing tests; r=automatedtester (b7b7ba91f4)
- Bug 1227918 - Log exception in harness class setup; r=automatedtester (9708cb7113)
- Bug 1221187: testing/marionette/client: Explicitly define --version flag; r=automatedtester (6886b6b925)
- Bug 1237179 - Add mach command to run firefox-ui-tests from the source directory. r=gps (3bb6ed2ff0)
- Bug 1208242 - Part 2: WebExtension blocklist tests for b2g r=ferjm (cf19a285a4)
- Bug 1165943 - Remove non existing "security.uri.allow_scheme_mismatch" preference from test. r=nsm (60cdcfc933)
- Bug 1223297 - Add multiple audio channel test. r=baku (55765d11dd)
426 lines
12 KiB
C++
426 lines
12 KiB
C++
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#include "AppProcessChecker.h"
|
|
#include "nsIPermissionManager.h"
|
|
#ifdef MOZ_CHILD_PERMISSIONS
|
|
#include "ContentParent.h"
|
|
#include "mozIApplication.h"
|
|
#include "mozilla/hal_sandbox/PHalParent.h"
|
|
#include "nsIAppsService.h"
|
|
#include "nsIPrincipal.h"
|
|
#include "nsPrintfCString.h"
|
|
#include "nsIURI.h"
|
|
#include "nsContentUtils.h"
|
|
#include "nsNetUtil.h"
|
|
#include "nsServiceManagerUtils.h"
|
|
#include "TabParent.h"
|
|
|
|
#include <algorithm>
|
|
|
|
using namespace mozilla::dom;
|
|
using namespace mozilla::hal_sandbox;
|
|
using namespace mozilla::services;
|
|
#else
|
|
namespace mozilla {
|
|
namespace dom {
|
|
class PContentParent;
|
|
} // namespace dom
|
|
} // namespace mozilla
|
|
|
|
class nsIPrincipal;
|
|
#endif
|
|
|
|
namespace mozilla {
|
|
|
|
#if DEUBG
|
|
#define LOG(args...) printf_stderr(args)
|
|
#else
|
|
#define LOG(...)
|
|
#endif
|
|
|
|
#ifdef MOZ_CHILD_PERMISSIONS
|
|
|
|
static bool
|
|
CheckAppTypeHelper(mozIApplication* aApp,
|
|
AssertAppProcessType aType,
|
|
const char* aCapability,
|
|
bool aIsBrowserElement)
|
|
{
|
|
bool aValid = false;
|
|
|
|
// isBrowser frames inherit their app descriptor to identify their
|
|
// data storage, but they don't inherit the capability associated
|
|
// with that descriptor.
|
|
if (aApp && (aType == ASSERT_APP_HAS_PERMISSION || !aIsBrowserElement)) {
|
|
switch (aType) {
|
|
case ASSERT_APP_HAS_PERMISSION:
|
|
case ASSERT_APP_PROCESS_PERMISSION:
|
|
if (!NS_SUCCEEDED(aApp->HasPermission(aCapability, &aValid))) {
|
|
aValid = false;
|
|
}
|
|
break;
|
|
case ASSERT_APP_PROCESS_MANIFEST_URL: {
|
|
nsAutoString manifestURL;
|
|
if (NS_SUCCEEDED(aApp->GetManifestURL(manifestURL)) &&
|
|
manifestURL.EqualsASCII(aCapability)) {
|
|
aValid = true;
|
|
}
|
|
break;
|
|
}
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
return aValid;
|
|
}
|
|
|
|
bool
|
|
AssertAppProcess(PBrowserParent* aActor,
|
|
AssertAppProcessType aType,
|
|
const char* aCapability)
|
|
{
|
|
if (!aActor) {
|
|
NS_WARNING("Testing process capability for null actor");
|
|
return false;
|
|
}
|
|
|
|
TabParent* tab = TabParent::GetFrom(aActor);
|
|
nsCOMPtr<mozIApplication> app = tab->GetOwnOrContainingApp();
|
|
|
|
return CheckAppTypeHelper(app, aType, aCapability, tab->IsMozBrowserElement());
|
|
}
|
|
|
|
static bool
|
|
CheckAppStatusHelper(mozIApplication* aApp,
|
|
unsigned short aStatus)
|
|
{
|
|
bool valid = false;
|
|
|
|
if (aApp) {
|
|
unsigned short appStatus = 0;
|
|
if (NS_SUCCEEDED(aApp->GetAppStatus(&appStatus))) {
|
|
valid = appStatus == aStatus;
|
|
}
|
|
}
|
|
|
|
return valid;
|
|
}
|
|
|
|
bool
|
|
AssertAppStatus(PBrowserParent* aActor,
|
|
unsigned short aStatus)
|
|
{
|
|
if (!aActor) {
|
|
NS_WARNING("Testing process capability for null actor");
|
|
return false;
|
|
}
|
|
|
|
TabParent* tab = TabParent::GetFrom(aActor);
|
|
nsCOMPtr<mozIApplication> app = tab->GetOwnOrContainingApp();
|
|
|
|
return CheckAppStatusHelper(app, aStatus);
|
|
}
|
|
|
|
// A general purpose helper function to check permission against the origin
|
|
// rather than mozIApplication.
|
|
static bool
|
|
CheckOriginPermission(const nsACString& aOrigin, const char* aPermission)
|
|
{
|
|
LOG("CheckOriginPermission: %s, %s\n", nsCString(aOrigin).get(), aPermission);
|
|
|
|
nsIScriptSecurityManager *securityManager =
|
|
nsContentUtils::GetSecurityManager();
|
|
|
|
nsCOMPtr<nsIPrincipal> principal;
|
|
securityManager->CreateCodebasePrincipalFromOrigin(aOrigin,
|
|
getter_AddRefs(principal));
|
|
|
|
nsCOMPtr<nsIPermissionManager> permMgr = services::GetPermissionManager();
|
|
NS_ENSURE_TRUE(permMgr, false);
|
|
|
|
uint32_t perm;
|
|
nsresult rv = permMgr->TestExactPermissionFromPrincipal(principal, aPermission, &perm);
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
LOG("Permission %s for %s: %d\n", aPermission, nsCString(aOrigin).get(), perm);
|
|
return nsIPermissionManager::ALLOW_ACTION == perm;
|
|
}
|
|
|
|
bool
|
|
AssertAppProcess(TabContext& aContext,
|
|
AssertAppProcessType aType,
|
|
const char* aCapability)
|
|
{
|
|
const mozilla::OriginAttributes& attr = aContext.OriginAttributesRef();
|
|
nsCString suffix;
|
|
attr.CreateSuffix(suffix);
|
|
|
|
if (!aContext.SignedPkgOriginNoSuffix().IsEmpty()) {
|
|
LOG("TabContext owning signed package origin: %s, originAttr; %s\n",
|
|
nsCString(aContext.SignedPkgOriginNoSuffix()).get(),
|
|
suffix.get());
|
|
}
|
|
|
|
// Do a origin-based permission check if the TabContext owns a signed package.
|
|
if (!aContext.SignedPkgOriginNoSuffix().IsEmpty() &&
|
|
(ASSERT_APP_HAS_PERMISSION == aType || ASSERT_APP_PROCESS_PERMISSION == aType)) {
|
|
nsCString origin = aContext.SignedPkgOriginNoSuffix() + suffix;
|
|
return CheckOriginPermission(origin, aCapability);
|
|
}
|
|
|
|
nsCOMPtr<mozIApplication> app = aContext.GetOwnOrContainingApp();
|
|
return CheckAppTypeHelper(app, aType, aCapability, aContext.IsMozBrowserElement());
|
|
}
|
|
|
|
bool
|
|
AssertAppStatus(TabContext& aContext,
|
|
unsigned short aStatus)
|
|
{
|
|
|
|
nsCOMPtr<mozIApplication> app = aContext.GetOwnOrContainingApp();
|
|
return CheckAppStatusHelper(app, aStatus);
|
|
}
|
|
|
|
bool
|
|
AssertAppProcess(PContentParent* aActor,
|
|
AssertAppProcessType aType,
|
|
const char* aCapability)
|
|
{
|
|
nsTArray<TabContext> contextArray =
|
|
static_cast<ContentParent*>(aActor)->GetManagedTabContext();
|
|
for (uint32_t i = 0; i < contextArray.Length(); ++i) {
|
|
if (AssertAppProcess(contextArray[i], aType, aCapability)) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
NS_ERROR(
|
|
nsPrintfCString(
|
|
"Security problem: Content process does not have `%s'. It will be killed.\n",
|
|
aCapability).get());
|
|
|
|
static_cast<ContentParent*>(aActor)->KillHard("AssertAppProcess");
|
|
|
|
return false;
|
|
}
|
|
|
|
bool
|
|
AssertAppStatus(PContentParent* aActor,
|
|
unsigned short aStatus)
|
|
{
|
|
nsTArray<TabContext> contextArray =
|
|
static_cast<ContentParent*>(aActor)->GetManagedTabContext();
|
|
for (uint32_t i = 0; i < contextArray.Length(); ++i) {
|
|
if (AssertAppStatus(contextArray[i], aStatus)) {
|
|
return true;
|
|
}
|
|
}
|
|
|
|
NS_ERROR(
|
|
nsPrintfCString(
|
|
"Security problem: Content process does not have `%d' status. It will be killed.",
|
|
aStatus).get());
|
|
|
|
static_cast<ContentParent*>(aActor)->KillHard("AssertAppStatus");
|
|
|
|
return false;
|
|
}
|
|
|
|
bool
|
|
AssertAppProcess(PHalParent* aActor,
|
|
AssertAppProcessType aType,
|
|
const char* aCapability)
|
|
{
|
|
return AssertAppProcess(aActor->Manager(), aType, aCapability);
|
|
}
|
|
|
|
bool
|
|
AssertAppPrincipal(PContentParent* aActor,
|
|
nsIPrincipal* aPrincipal)
|
|
{
|
|
if (!aPrincipal) {
|
|
NS_WARNING("Principal is invalid, killing app process");
|
|
static_cast<ContentParent*>(aActor)->KillHard("AssertAppPrincipal");
|
|
return false;
|
|
}
|
|
|
|
uint32_t principalAppId = aPrincipal->GetAppId();
|
|
bool inIsolatedBrowser = aPrincipal->GetIsInIsolatedMozBrowserElement();
|
|
|
|
// Check if the permission's appId matches a child we manage.
|
|
nsTArray<TabContext> contextArray =
|
|
static_cast<ContentParent*>(aActor)->GetManagedTabContext();
|
|
for (uint32_t i = 0; i < contextArray.Length(); ++i) {
|
|
if (contextArray[i].OwnOrContainingAppId() == principalAppId) {
|
|
// If the child only runs isolated browser content and the principal
|
|
// claims it's not in an isolated browser element, it's lying.
|
|
if (!contextArray[i].IsIsolatedMozBrowserElement() || inIsolatedBrowser) {
|
|
return true;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
NS_WARNING("Principal is invalid, killing app process");
|
|
static_cast<ContentParent*>(aActor)->KillHard("AssertAppPrincipal");
|
|
return false;
|
|
}
|
|
|
|
already_AddRefed<nsIPrincipal>
|
|
GetAppPrincipal(uint32_t aAppId)
|
|
{
|
|
nsCOMPtr<nsIAppsService> appsService = do_GetService(APPS_SERVICE_CONTRACTID);
|
|
|
|
nsCOMPtr<mozIApplication> app;
|
|
nsresult rv = appsService->GetAppByLocalId(aAppId, getter_AddRefs(app));
|
|
NS_ENSURE_SUCCESS(rv, nullptr);
|
|
|
|
nsCOMPtr<nsIPrincipal> principal;
|
|
app->GetPrincipal(getter_AddRefs(principal));
|
|
|
|
return principal.forget();
|
|
}
|
|
|
|
uint32_t
|
|
CheckPermission(PContentParent* aActor,
|
|
nsIPrincipal* aPrincipal,
|
|
const char* aPermission)
|
|
{
|
|
if (!AssertAppPrincipal(aActor, aPrincipal)) {
|
|
return nsIPermissionManager::DENY_ACTION;
|
|
}
|
|
|
|
nsCOMPtr<nsIPermissionManager> pm =
|
|
services::GetPermissionManager();
|
|
NS_ENSURE_TRUE(pm, nsIPermissionManager::DENY_ACTION);
|
|
|
|
// Make sure that `aPermission' is an app permission before checking the origin.
|
|
nsCOMPtr<nsIPrincipal> appPrincipal = GetAppPrincipal(aPrincipal->GetAppId());
|
|
uint32_t appPerm = nsIPermissionManager::UNKNOWN_ACTION;
|
|
nsresult rv = pm->TestExactPermissionFromPrincipal(appPrincipal, aPermission, &appPerm);
|
|
NS_ENSURE_SUCCESS(rv, nsIPermissionManager::UNKNOWN_ACTION);
|
|
// Setting to "deny" in the settings UI should deny everywhere.
|
|
if (appPerm == nsIPermissionManager::UNKNOWN_ACTION ||
|
|
appPerm == nsIPermissionManager::DENY_ACTION) {
|
|
return appPerm;
|
|
}
|
|
|
|
uint32_t permission = nsIPermissionManager::UNKNOWN_ACTION;
|
|
rv = pm->TestExactPermissionFromPrincipal(aPrincipal, aPermission, &permission);
|
|
NS_ENSURE_SUCCESS(rv, nsIPermissionManager::UNKNOWN_ACTION);
|
|
if (permission == nsIPermissionManager::UNKNOWN_ACTION ||
|
|
permission == nsIPermissionManager::DENY_ACTION) {
|
|
return permission;
|
|
}
|
|
|
|
// For browser content (and if the app hasn't explicitly denied this),
|
|
// consider the requesting origin, not the app.
|
|
// After bug 1238160, the principal no longer knows how to answer "is this a
|
|
// browser element", which is really what this code path wants. Currently,
|
|
// desktop is the only platform where we intend to disable isolation on a
|
|
// browser frame, so non-desktop should be able to assume that
|
|
// inIsolatedMozBrowser is true for all mozbrowser frames. This code path is
|
|
// currently unused on desktop, since MOZ_CHILD_PERMISSIONS is only set for
|
|
// MOZ_B2G. We use a release assertion in
|
|
// nsFrameLoader::OwnerIsIsolatedMozBrowserFrame so that platforms with apps
|
|
// can assume inIsolatedMozBrowser is true for all mozbrowser frames.
|
|
if (appPerm == nsIPermissionManager::PROMPT_ACTION &&
|
|
aPrincipal->GetIsInIsolatedMozBrowserElement()) {
|
|
return permission;
|
|
}
|
|
|
|
// Setting to "prompt" in the settings UI should prompt everywhere in
|
|
// non-browser content.
|
|
if (appPerm == nsIPermissionManager::PROMPT_ACTION ||
|
|
permission == nsIPermissionManager::PROMPT_ACTION) {
|
|
return nsIPermissionManager::PROMPT_ACTION;
|
|
}
|
|
|
|
if (appPerm == nsIPermissionManager::ALLOW_ACTION ||
|
|
permission == nsIPermissionManager::ALLOW_ACTION) {
|
|
return nsIPermissionManager::ALLOW_ACTION;
|
|
}
|
|
|
|
NS_RUNTIMEABORT("Invalid permission value");
|
|
return nsIPermissionManager::DENY_ACTION;
|
|
}
|
|
|
|
#else
|
|
|
|
bool
|
|
AssertAppProcess(mozilla::dom::PBrowserParent* aActor,
|
|
AssertAppProcessType aType,
|
|
const char* aCapability)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
bool
|
|
AssertAppStatus(mozilla::dom::PBrowserParent* aActor,
|
|
unsigned short aStatus)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
bool
|
|
AssertAppProcess(const mozilla::dom::TabContext& aContext,
|
|
AssertAppProcessType aType,
|
|
const char* aCapability)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
bool
|
|
AssertAppStatus(const mozilla::dom::TabContext& aContext,
|
|
unsigned short aStatus)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
|
|
bool
|
|
AssertAppProcess(mozilla::dom::PContentParent* aActor,
|
|
AssertAppProcessType aType,
|
|
const char* aCapability)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
bool
|
|
AssertAppStatus(mozilla::dom::PContentParent* aActor,
|
|
unsigned short aStatus)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
bool
|
|
AssertAppProcess(mozilla::hal_sandbox::PHalParent* aActor,
|
|
AssertAppProcessType aType,
|
|
const char* aCapability)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
bool
|
|
AssertAppPrincipal(mozilla::dom::PContentParent* aActor,
|
|
nsIPrincipal* aPrincipal)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
uint32_t
|
|
CheckPermission(mozilla::dom::PContentParent* aActor,
|
|
nsIPrincipal* aPrincipal,
|
|
const char* aPermission)
|
|
{
|
|
return nsIPermissionManager::ALLOW_ACTION;
|
|
}
|
|
|
|
#endif
|
|
|
|
} // namespace mozilla
|