2010-06-26 02:58:09 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* vim: set ts=4 sw=4 et tw=99 ft=cpp:
|
|
|
|
*
|
2012-05-21 15:12:37 +04:00
|
|
|
* 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/. */
|
2010-06-26 02:58:09 +04:00
|
|
|
|
2011-10-11 09:50:08 +04:00
|
|
|
#include "mozilla/Util.h"
|
|
|
|
|
2010-07-03 00:54:53 +04:00
|
|
|
#include "AccessCheck.h"
|
2010-06-26 02:58:09 +04:00
|
|
|
|
|
|
|
#include "nsJSPrincipals.h"
|
2013-03-17 11:55:15 +04:00
|
|
|
#include "nsIDocument.h"
|
2010-07-03 00:54:53 +04:00
|
|
|
#include "nsIDOMWindow.h"
|
2013-03-17 11:55:15 +04:00
|
|
|
#include "nsPIDOMWindow.h"
|
2010-07-03 00:54:53 +04:00
|
|
|
#include "nsIDOMWindowCollection.h"
|
2010-09-18 01:54:40 +04:00
|
|
|
#include "nsContentUtils.h"
|
2012-05-25 20:42:40 +04:00
|
|
|
#include "nsJSUtils.h"
|
2010-06-26 02:58:09 +04:00
|
|
|
|
2010-07-03 00:54:53 +04:00
|
|
|
#include "XPCWrapper.h"
|
2010-09-18 01:54:40 +04:00
|
|
|
#include "XrayWrapper.h"
|
2010-10-11 02:39:08 +04:00
|
|
|
#include "FilteringWrapper.h"
|
2010-06-26 02:58:09 +04:00
|
|
|
|
2011-04-13 20:27:37 +04:00
|
|
|
#include "jsfriendapi.h"
|
2012-09-13 00:29:30 +04:00
|
|
|
#include "mozilla/dom/BindingUtils.h"
|
2010-10-28 19:15:53 +04:00
|
|
|
|
2011-10-11 09:50:08 +04:00
|
|
|
using namespace mozilla;
|
2011-09-09 07:29:15 +04:00
|
|
|
using namespace js;
|
|
|
|
|
2010-06-26 02:58:09 +04:00
|
|
|
namespace xpc {
|
|
|
|
|
2011-08-07 01:05:25 +04:00
|
|
|
nsIPrincipal *
|
2010-06-26 02:58:09 +04:00
|
|
|
GetCompartmentPrincipal(JSCompartment *compartment)
|
|
|
|
{
|
2012-03-09 13:48:50 +04:00
|
|
|
return nsJSPrincipals::get(JS_GetCompartmentPrincipals(compartment));
|
2010-06-26 02:58:09 +04:00
|
|
|
}
|
|
|
|
|
2013-05-07 03:53:10 +04:00
|
|
|
nsIPrincipal *
|
|
|
|
GetObjectPrincipal(JSObject *obj)
|
|
|
|
{
|
|
|
|
return GetCompartmentPrincipal(js::GetObjectCompartment(obj));
|
|
|
|
}
|
|
|
|
|
2012-07-12 12:10:15 +04:00
|
|
|
// Does the principal of compartment a subsume the principal of compartment b?
|
2010-06-26 02:58:09 +04:00
|
|
|
bool
|
2012-07-12 12:10:15 +04:00
|
|
|
AccessCheck::subsumes(JSCompartment *a, JSCompartment *b)
|
2010-07-03 00:54:53 +04:00
|
|
|
{
|
2010-10-13 22:37:25 +04:00
|
|
|
nsIPrincipal *aprin = GetCompartmentPrincipal(a);
|
|
|
|
nsIPrincipal *bprin = GetCompartmentPrincipal(b);
|
|
|
|
|
|
|
|
// If either a or b doesn't have principals, we don't have enough
|
|
|
|
// information to tell. Seeing as how this is Gecko, we are default-unsafe
|
|
|
|
// in this case.
|
|
|
|
if (!aprin || !bprin)
|
|
|
|
return true;
|
|
|
|
|
2012-07-12 12:10:15 +04:00
|
|
|
bool subsumes;
|
2012-07-12 12:10:15 +04:00
|
|
|
nsresult rv = aprin->Subsumes(bprin, &subsumes);
|
2012-07-12 12:10:15 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
2011-02-03 09:05:07 +03:00
|
|
|
|
2012-07-12 12:10:15 +04:00
|
|
|
return subsumes;
|
2010-07-03 00:54:53 +04:00
|
|
|
}
|
|
|
|
|
2012-12-08 02:49:11 +04:00
|
|
|
bool
|
|
|
|
AccessCheck::subsumes(JSObject *a, JSObject *b)
|
|
|
|
{
|
|
|
|
return subsumes(js::GetObjectCompartment(a), js::GetObjectCompartment(b));
|
|
|
|
}
|
|
|
|
|
2012-09-11 21:23:20 +04:00
|
|
|
// Same as above, but ignoring document.domain.
|
|
|
|
bool
|
|
|
|
AccessCheck::subsumesIgnoringDomain(JSCompartment *a, JSCompartment *b)
|
|
|
|
{
|
|
|
|
nsIPrincipal *aprin = GetCompartmentPrincipal(a);
|
|
|
|
nsIPrincipal *bprin = GetCompartmentPrincipal(b);
|
|
|
|
|
|
|
|
if (!aprin || !bprin)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
bool subsumes;
|
|
|
|
nsresult rv = aprin->SubsumesIgnoringDomain(bprin, &subsumes);
|
|
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
|
|
|
|
|
|
return subsumes;
|
|
|
|
}
|
|
|
|
|
2012-09-11 12:05:10 +04:00
|
|
|
// Does the compartment of the wrapper subsumes the compartment of the wrappee?
|
|
|
|
bool
|
|
|
|
AccessCheck::wrapperSubsumes(JSObject *wrapper)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(js::IsWrapper(wrapper));
|
2013-04-11 22:50:18 +04:00
|
|
|
JSObject *wrapped = js::UncheckedUnwrap(wrapper);
|
2012-09-11 12:05:10 +04:00
|
|
|
return AccessCheck::subsumes(js::GetObjectCompartment(wrapper),
|
|
|
|
js::GetObjectCompartment(wrapped));
|
|
|
|
}
|
|
|
|
|
2010-07-03 00:54:53 +04:00
|
|
|
bool
|
|
|
|
AccessCheck::isChrome(JSCompartment *compartment)
|
2010-06-26 02:58:09 +04:00
|
|
|
{
|
|
|
|
nsIScriptSecurityManager *ssm = XPCWrapper::GetSecurityManager();
|
2010-07-03 00:54:53 +04:00
|
|
|
if (!ssm) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool privileged;
|
2010-07-03 00:54:53 +04:00
|
|
|
nsIPrincipal *principal = GetCompartmentPrincipal(compartment);
|
|
|
|
return NS_SUCCEEDED(ssm->IsSystemPrincipal(principal, &privileged)) && privileged;
|
|
|
|
}
|
|
|
|
|
2012-09-11 12:05:10 +04:00
|
|
|
bool
|
|
|
|
AccessCheck::isChrome(JSObject *obj)
|
|
|
|
{
|
|
|
|
return isChrome(js::GetObjectCompartment(obj));
|
|
|
|
}
|
|
|
|
|
2012-06-18 17:47:09 +04:00
|
|
|
bool
|
|
|
|
AccessCheck::callerIsChrome()
|
|
|
|
{
|
|
|
|
nsIScriptSecurityManager *ssm = XPCWrapper::GetSecurityManager();
|
|
|
|
if (!ssm)
|
|
|
|
return false;
|
|
|
|
bool subjectIsSystem;
|
|
|
|
nsresult rv = ssm->SubjectPrincipalIsSystem(&subjectIsSystem);
|
|
|
|
return NS_SUCCEEDED(rv) && subjectIsSystem;
|
|
|
|
}
|
|
|
|
|
2010-09-25 05:00:58 +04:00
|
|
|
nsIPrincipal *
|
|
|
|
AccessCheck::getPrincipal(JSCompartment *compartment)
|
|
|
|
{
|
|
|
|
return GetCompartmentPrincipal(compartment);
|
|
|
|
}
|
|
|
|
|
2010-10-28 19:15:53 +04:00
|
|
|
#define NAME(ch, str, cases) \
|
|
|
|
case ch: if (!strcmp(name, str)) switch (propChars[0]) { cases }; break;
|
2010-07-03 00:54:53 +04:00
|
|
|
#define PROP(ch, actions) case ch: { actions }; break;
|
2010-12-03 11:24:17 +03:00
|
|
|
#define RW(str) if (JS_FlatStringEqualsAscii(prop, str)) return true;
|
|
|
|
#define R(str) if (!set && JS_FlatStringEqualsAscii(prop, str)) return true;
|
|
|
|
#define W(str) if (set && JS_FlatStringEqualsAscii(prop, str)) return true;
|
2010-07-03 00:54:53 +04:00
|
|
|
|
|
|
|
// Hardcoded policy for cross origin property access. This was culled from the
|
|
|
|
// preferences file (all.js). We don't want users to overwrite highly sensitive
|
|
|
|
// security policies.
|
|
|
|
static bool
|
2010-12-03 11:24:17 +03:00
|
|
|
IsPermitted(const char *name, JSFlatString *prop, bool set)
|
2010-07-03 00:54:53 +04:00
|
|
|
{
|
2010-10-28 19:15:53 +04:00
|
|
|
size_t propLength;
|
2012-01-15 12:13:07 +04:00
|
|
|
const jschar *propChars =
|
|
|
|
JS_GetInternedStringCharsAndLength(JS_FORGET_STRING_FLATNESS(prop), &propLength);
|
2010-10-28 19:15:53 +04:00
|
|
|
if (!propLength)
|
|
|
|
return false;
|
2011-10-14 21:52:48 +04:00
|
|
|
switch (name[0]) {
|
2010-09-18 01:54:40 +04:00
|
|
|
NAME('L', "Location",
|
2013-02-11 03:05:17 +04:00
|
|
|
PROP('h', W("href"))
|
2010-09-18 01:54:40 +04:00
|
|
|
PROP('r', R("replace")))
|
2010-07-03 00:54:53 +04:00
|
|
|
NAME('W', "Window",
|
|
|
|
PROP('b', R("blur"))
|
|
|
|
PROP('c', R("close") R("closed"))
|
|
|
|
PROP('f', R("focus") R("frames"))
|
|
|
|
PROP('l', RW("location") R("length"))
|
|
|
|
PROP('o', R("opener"))
|
|
|
|
PROP('p', R("parent") R("postMessage"))
|
|
|
|
PROP('s', R("self"))
|
|
|
|
PROP('t', R("top"))
|
|
|
|
PROP('w', R("window")))
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef NAME
|
|
|
|
#undef RW
|
|
|
|
#undef R
|
|
|
|
#undef W
|
|
|
|
|
|
|
|
static bool
|
2013-04-17 19:38:44 +04:00
|
|
|
IsFrameId(JSContext *cx, JSObject *objArg, jsid idArg)
|
2010-07-03 00:54:53 +04:00
|
|
|
{
|
2013-04-17 19:38:44 +04:00
|
|
|
RootedObject obj(cx, objArg);
|
|
|
|
RootedId id(cx, idArg);
|
|
|
|
|
2013-03-21 19:20:45 +04:00
|
|
|
obj = JS_ObjectToInnerObject(cx, obj);
|
|
|
|
MOZ_ASSERT(!js::IsWrapper(obj));
|
2013-04-19 23:58:30 +04:00
|
|
|
XPCWrappedNative *wn = IS_WN_REFLECTOR(obj) ? XPCWrappedNative::Get(obj)
|
|
|
|
: nullptr;
|
2010-09-18 01:54:40 +04:00
|
|
|
if (!wn) {
|
|
|
|
return false;
|
|
|
|
}
|
2010-07-03 00:54:53 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMWindow> domwin(do_QueryWrappedNative(wn));
|
|
|
|
if (!domwin) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMWindowCollection> col;
|
|
|
|
domwin->GetFrames(getter_AddRefs(col));
|
|
|
|
if (!col) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (JSID_IS_INT(id)) {
|
|
|
|
col->Item(JSID_TO_INT(id), getter_AddRefs(domwin));
|
2012-01-15 12:13:07 +04:00
|
|
|
} else if (JSID_IS_STRING(id)) {
|
2010-12-03 11:24:17 +03:00
|
|
|
nsAutoString str(JS_GetInternedStringChars(JSID_TO_STRING(id)));
|
2010-07-03 00:54:53 +04:00
|
|
|
col->NamedItem(str, getter_AddRefs(domwin));
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return domwin != nullptr;
|
2010-07-03 00:54:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
IsWindow(const char *name)
|
|
|
|
{
|
|
|
|
return name[0] == 'W' && !strcmp(name, "Window");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-04-23 20:50:17 +04:00
|
|
|
AccessCheck::isCrossOriginAccessPermitted(JSContext *cx, JSObject *wrapperArg, jsid idArg,
|
2011-09-09 07:29:15 +04:00
|
|
|
Wrapper::Action act)
|
2010-07-03 00:54:53 +04:00
|
|
|
{
|
2010-09-18 01:54:40 +04:00
|
|
|
if (!XPCWrapper::GetSecurityManager())
|
|
|
|
return true;
|
2010-07-03 00:54:53 +04:00
|
|
|
|
2011-09-09 07:29:15 +04:00
|
|
|
if (act == Wrapper::CALL)
|
2013-05-23 08:27:16 +04:00
|
|
|
return false;
|
2010-09-18 01:54:40 +04:00
|
|
|
|
2013-04-23 20:50:17 +04:00
|
|
|
RootedId id(cx, idArg);
|
|
|
|
RootedObject wrapper(cx, wrapperArg);
|
|
|
|
RootedObject obj(cx, Wrapper::wrappedObject(wrapper));
|
2010-07-03 00:54:53 +04:00
|
|
|
|
2013-05-23 08:27:15 +04:00
|
|
|
// Enumerate-like operations pass JSID_VOID to |enter|, since there isn't
|
|
|
|
// another sane value to pass. For XOWs, we generally want to deny such
|
|
|
|
// operations but fail silently (see CrossOriginAccessiblePropertiesOnly::
|
|
|
|
// deny). We could just fall through here and rely on the fact that none
|
|
|
|
// of the whitelisted properties below will match JSID_VOID, but EIBTI.
|
|
|
|
if (id == JSID_VOID)
|
|
|
|
return false;
|
|
|
|
|
2010-09-18 01:54:40 +04:00
|
|
|
const char *name;
|
2011-10-04 18:06:54 +04:00
|
|
|
js::Class *clasp = js::GetObjectClass(obj);
|
2010-09-24 02:56:28 +04:00
|
|
|
NS_ASSERTION(Jsvalify(clasp) != &XrayUtils::HolderClass, "shouldn't have a holder here");
|
2010-09-18 01:54:40 +04:00
|
|
|
if (clasp->ext.innerObject)
|
|
|
|
name = "Window";
|
|
|
|
else
|
|
|
|
name = clasp->name;
|
2010-07-03 00:54:53 +04:00
|
|
|
|
2012-01-15 12:13:07 +04:00
|
|
|
if (JSID_IS_STRING(id)) {
|
2011-09-09 07:29:15 +04:00
|
|
|
if (IsPermitted(name, JSID_TO_FLAT_STRING(id), act == Wrapper::SET))
|
2010-07-03 00:54:53 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-04-23 20:50:17 +04:00
|
|
|
// Check for frame IDs. If we're resolving named frames, make sure to only
|
|
|
|
// resolve ones that don't shadow native properties. See bug 860494.
|
|
|
|
if (IsWindow(name)) {
|
|
|
|
if (JSID_IS_STRING(id) && !XrayUtils::IsXrayResolving(cx, wrapper, id)) {
|
|
|
|
bool wouldShadow = false;
|
|
|
|
if (!XrayUtils::HasNativeProperty(cx, wrapper, id, &wouldShadow) ||
|
|
|
|
wouldShadow)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return IsFrameId(cx, obj, id);
|
|
|
|
}
|
|
|
|
return false;
|
2010-07-03 00:54:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
AccessCheck::needsSystemOnlyWrapper(JSObject *obj)
|
|
|
|
{
|
2012-09-13 00:29:30 +04:00
|
|
|
JSObject* wrapper = obj;
|
|
|
|
if (dom::GetSameCompartmentWrapperForDOMBinding(wrapper))
|
|
|
|
return wrapper != obj;
|
|
|
|
|
2013-04-19 23:58:30 +04:00
|
|
|
if (!IS_WN_REFLECTOR(obj))
|
2010-09-18 01:54:40 +04:00
|
|
|
return false;
|
|
|
|
|
2011-10-04 18:06:54 +04:00
|
|
|
XPCWrappedNative *wn = static_cast<XPCWrappedNative *>(js::GetObjectPrivate(obj));
|
2010-07-03 00:54:53 +04:00
|
|
|
return wn->NeedsSOW();
|
2010-06-26 02:58:09 +04:00
|
|
|
}
|
|
|
|
|
2011-01-30 05:47:17 +03:00
|
|
|
enum Access { READ = (1<<0), WRITE = (1<<1), NO_ACCESS = 0 };
|
|
|
|
|
2012-12-08 02:49:11 +04:00
|
|
|
static void
|
|
|
|
EnterAndThrow(JSContext *cx, JSObject *wrapper, const char *msg)
|
|
|
|
{
|
|
|
|
JSAutoCompartment ac(cx, wrapper);
|
|
|
|
JS_ReportError(cx, msg);
|
|
|
|
}
|
|
|
|
|
2010-06-26 02:58:09 +04:00
|
|
|
bool
|
2013-04-17 19:38:44 +04:00
|
|
|
ExposedPropertiesOnly::check(JSContext *cx, JSObject *wrapperArg, jsid idArg, Wrapper::Action act)
|
2010-06-26 02:58:09 +04:00
|
|
|
{
|
2013-04-17 19:38:44 +04:00
|
|
|
RootedObject wrapper(cx, wrapperArg);
|
|
|
|
RootedId id(cx, idArg);
|
|
|
|
RootedObject wrappedObject(cx, Wrapper::wrappedObject(wrapper));
|
2011-01-30 05:47:17 +03:00
|
|
|
|
2012-11-03 04:47:49 +04:00
|
|
|
if (act == Wrapper::CALL)
|
2011-01-30 05:47:17 +03:00
|
|
|
return true;
|
2010-07-03 00:54:53 +04:00
|
|
|
|
2013-04-17 19:38:44 +04:00
|
|
|
RootedId exposedPropsId(cx, GetRTIdByIndex(cx, XPCJSRuntime::IDX_EXPOSEDPROPS));
|
2010-07-03 00:54:53 +04:00
|
|
|
|
2012-06-18 17:47:09 +04:00
|
|
|
// We need to enter the wrappee's compartment to look at __exposedProps__,
|
2012-09-11 12:05:10 +04:00
|
|
|
// but we want to be in the wrapper's compartment if we call Deny().
|
2012-06-18 17:47:09 +04:00
|
|
|
//
|
|
|
|
// Unfortunately, |cx| can be in either compartment when we call ::check. :-(
|
2012-08-22 05:42:53 +04:00
|
|
|
JSAutoCompartment ac(cx, wrappedObject);
|
2012-06-18 17:47:09 +04:00
|
|
|
|
|
|
|
JSBool found = false;
|
|
|
|
if (!JS_HasPropertyById(cx, wrappedObject, exposedPropsId, &found))
|
2010-07-03 00:54:53 +04:00
|
|
|
return false;
|
2011-01-30 05:47:17 +03:00
|
|
|
|
|
|
|
// Always permit access to "length" and indexed properties of arrays.
|
2012-09-06 01:05:32 +04:00
|
|
|
if ((JS_IsArrayObject(cx, wrappedObject) ||
|
2012-11-14 21:56:26 +04:00
|
|
|
JS_IsTypedArrayObject(wrappedObject)) &&
|
2011-01-30 05:47:17 +03:00
|
|
|
((JSID_IS_INT(id) && JSID_TO_INT(id) >= 0) ||
|
2012-01-15 12:13:07 +04:00
|
|
|
(JSID_IS_STRING(id) && JS_FlatStringEqualsAscii(JSID_TO_FLAT_STRING(id), "length")))) {
|
2010-07-03 00:54:53 +04:00
|
|
|
return true; // Allow
|
|
|
|
}
|
|
|
|
|
2011-01-30 05:47:17 +03:00
|
|
|
// If no __exposedProps__ existed, deny access.
|
|
|
|
if (!found) {
|
2012-11-03 04:47:49 +04:00
|
|
|
return false;
|
2011-01-30 05:47:17 +03:00
|
|
|
}
|
|
|
|
|
2012-11-03 04:47:49 +04:00
|
|
|
if (id == JSID_VOID)
|
2010-06-26 02:58:09 +04:00
|
|
|
return true;
|
2010-07-03 00:54:53 +04:00
|
|
|
|
2013-04-17 19:38:44 +04:00
|
|
|
RootedValue exposedProps(cx);
|
|
|
|
if (!JS_LookupPropertyById(cx, wrappedObject, exposedPropsId, exposedProps.address()))
|
2010-07-02 02:45:08 +04:00
|
|
|
return false;
|
2010-07-03 00:54:53 +04:00
|
|
|
|
2012-11-03 04:47:49 +04:00
|
|
|
if (exposedProps.isNullOrUndefined())
|
|
|
|
return false;
|
2010-07-02 02:45:08 +04:00
|
|
|
|
2012-05-11 19:46:26 +04:00
|
|
|
if (!exposedProps.isObject()) {
|
2012-12-08 02:49:11 +04:00
|
|
|
EnterAndThrow(cx, wrapper, "__exposedProps__ must be undefined, null, or an Object");
|
2010-07-03 00:54:53 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-04-26 21:50:18 +04:00
|
|
|
RootedObject hallpass(cx, &exposedProps.toObject());
|
2010-07-03 00:54:53 +04:00
|
|
|
|
2013-04-11 22:50:18 +04:00
|
|
|
if (!AccessCheck::subsumes(js::UncheckedUnwrap(hallpass), wrappedObject)) {
|
2012-12-08 02:49:11 +04:00
|
|
|
EnterAndThrow(cx, wrapper, "Invalid __exposedProps__");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-07-03 00:54:53 +04:00
|
|
|
Access access = NO_ACCESS;
|
|
|
|
|
2013-04-26 21:50:18 +04:00
|
|
|
Rooted<JSPropertyDescriptor> desc(cx);
|
|
|
|
if (!JS_GetPropertyDescriptorById(cx, hallpass, id, 0, desc.address())) {
|
2010-07-03 00:54:53 +04:00
|
|
|
return false; // Error
|
2010-07-02 02:45:08 +04:00
|
|
|
}
|
2013-04-26 21:50:18 +04:00
|
|
|
if (!desc.object() || !desc.isEnumerable())
|
2012-11-03 04:47:49 +04:00
|
|
|
return false;
|
2010-07-03 00:54:53 +04:00
|
|
|
|
2013-04-26 21:50:18 +04:00
|
|
|
if (!desc.value().isString()) {
|
2012-12-08 02:49:11 +04:00
|
|
|
EnterAndThrow(cx, wrapper, "property must be a string");
|
2010-07-03 00:54:53 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-04-26 21:50:18 +04:00
|
|
|
JSString *str = desc.value().toString();
|
2010-12-03 11:24:17 +03:00
|
|
|
size_t length;
|
|
|
|
const jschar *chars = JS_GetStringCharsAndLength(cx, str, &length);
|
|
|
|
if (!chars)
|
|
|
|
return false;
|
|
|
|
|
2010-07-03 00:54:53 +04:00
|
|
|
for (size_t i = 0; i < length; ++i) {
|
|
|
|
switch (chars[i]) {
|
|
|
|
case 'r':
|
|
|
|
if (access & READ) {
|
2012-12-08 02:49:11 +04:00
|
|
|
EnterAndThrow(cx, wrapper, "duplicate 'readable' property flag");
|
2010-07-03 00:54:53 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
access = Access(access | READ);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'w':
|
|
|
|
if (access & WRITE) {
|
2012-12-08 02:49:11 +04:00
|
|
|
EnterAndThrow(cx, wrapper, "duplicate 'writable' property flag");
|
2010-07-03 00:54:53 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
access = Access(access | WRITE);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2012-12-08 02:49:11 +04:00
|
|
|
EnterAndThrow(cx, wrapper, "properties can only be readable or read and writable");
|
2010-07-03 00:54:53 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (access == NO_ACCESS) {
|
2012-12-08 02:49:11 +04:00
|
|
|
EnterAndThrow(cx, wrapper, "specified properties must have a permission bit set");
|
2010-07-03 00:54:53 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-09-09 07:29:15 +04:00
|
|
|
if ((act == Wrapper::SET && !(access & WRITE)) ||
|
|
|
|
(act != Wrapper::SET && !(access & READ))) {
|
2012-11-03 04:47:49 +04:00
|
|
|
return false;
|
2010-07-03 00:54:53 +04:00
|
|
|
}
|
|
|
|
|
2012-11-03 04:47:49 +04:00
|
|
|
return true;
|
2010-06-26 02:58:09 +04:00
|
|
|
}
|
|
|
|
|
2012-12-21 10:33:26 +04:00
|
|
|
bool
|
|
|
|
ExposedPropertiesOnly::allowNativeCall(JSContext *cx, JS::IsAcceptableThis test,
|
|
|
|
JS::NativeImpl impl)
|
|
|
|
{
|
|
|
|
return js::IsReadOnlyDateMethod(test, impl) || js::IsTypedArrayThisCheck(test);
|
|
|
|
}
|
|
|
|
|
2012-04-28 17:12:28 +04:00
|
|
|
bool
|
2013-04-17 19:38:44 +04:00
|
|
|
ComponentsObjectPolicy::check(JSContext *cx, JSObject *wrapperArg, jsid idArg, Wrapper::Action act)
|
2012-04-28 17:12:28 +04:00
|
|
|
{
|
2013-04-17 19:38:44 +04:00
|
|
|
RootedObject wrapper(cx, wrapperArg);
|
|
|
|
RootedId id(cx, idArg);
|
2012-08-22 05:42:53 +04:00
|
|
|
JSAutoCompartment ac(cx, wrapper);
|
2012-04-28 17:12:28 +04:00
|
|
|
|
|
|
|
if (JSID_IS_STRING(id) && act == Wrapper::GET) {
|
|
|
|
JSFlatString *flatId = JSID_TO_FLAT_STRING(id);
|
|
|
|
if (JS_FlatStringEqualsAscii(flatId, "isSuccessCode") ||
|
|
|
|
JS_FlatStringEqualsAscii(flatId, "lookupMethod") ||
|
|
|
|
JS_FlatStringEqualsAscii(flatId, "interfaces") ||
|
|
|
|
JS_FlatStringEqualsAscii(flatId, "interfacesByID") ||
|
|
|
|
JS_FlatStringEqualsAscii(flatId, "results"))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-11 12:05:10 +04:00
|
|
|
// We don't have any way to recompute same-compartment Components wrappers,
|
|
|
|
// so we need this dynamic check. This can go away when we expose Components
|
|
|
|
// as SpecialPowers.wrap(Components) during automation.
|
|
|
|
if (xpc::IsUniversalXPConnectEnabled(cx)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-11-03 04:47:49 +04:00
|
|
|
return false;
|
2012-04-28 17:12:28 +04:00
|
|
|
}
|
|
|
|
|
2010-06-26 02:58:09 +04:00
|
|
|
}
|