2010-06-25 15:58:09 -07: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 04:12:37 -07: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-25 15:58:09 -07:00
|
|
|
|
2012-07-27 03:15:46 -07:00
|
|
|
#ifndef __AccessCheck_h__
|
|
|
|
#define __AccessCheck_h__
|
|
|
|
|
2010-06-25 15:58:09 -07:00
|
|
|
#include "jsapi.h"
|
|
|
|
#include "jswrapper.h"
|
2012-03-23 14:59:07 -07:00
|
|
|
#include "WrapperFactory.h"
|
2010-06-25 15:58:09 -07:00
|
|
|
|
2010-09-24 18:00:58 -07:00
|
|
|
class nsIPrincipal;
|
|
|
|
|
2010-06-25 15:58:09 -07:00
|
|
|
namespace xpc {
|
|
|
|
|
|
|
|
class AccessCheck {
|
|
|
|
public:
|
2012-07-12 01:10:15 -07:00
|
|
|
static bool subsumes(JSCompartment *a, JSCompartment *b);
|
2012-12-07 14:49:11 -08:00
|
|
|
static bool subsumes(JSObject *a, JSObject *b);
|
2012-09-11 01:05:10 -07:00
|
|
|
static bool wrapperSubsumes(JSObject *wrapper);
|
2012-09-11 10:23:20 -07:00
|
|
|
static bool subsumesIgnoringDomain(JSCompartment *a, JSCompartment *b);
|
2010-07-02 13:54:53 -07:00
|
|
|
static bool isChrome(JSCompartment *compartment);
|
2012-09-11 01:05:10 -07:00
|
|
|
static bool isChrome(JSObject *obj);
|
2012-06-18 06:47:09 -07:00
|
|
|
static bool callerIsChrome();
|
2010-09-24 18:00:58 -07:00
|
|
|
static nsIPrincipal *getPrincipal(JSCompartment *compartment);
|
2010-09-17 14:54:40 -07:00
|
|
|
static bool isCrossOriginAccessPermitted(JSContext *cx, JSObject *obj, jsid id,
|
2011-09-08 20:29:15 -07:00
|
|
|
js::Wrapper::Action act);
|
2010-07-02 13:54:53 -07:00
|
|
|
static bool isSystemOnlyAccessPermitted(JSContext *cx);
|
|
|
|
|
|
|
|
static bool needsSystemOnlyWrapper(JSObject *obj);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Policy {
|
|
|
|
};
|
|
|
|
|
2013-01-22 21:04:38 -08:00
|
|
|
// This policy only allows calling the underlying callable. All other operations throw.
|
|
|
|
struct Opaque : public Policy {
|
|
|
|
static bool check(JSContext *cx, JSObject *wrapper, jsid id, js::Wrapper::Action act) {
|
|
|
|
return act == js::Wrapper::CALL;
|
|
|
|
}
|
2013-02-25 13:54:18 -08:00
|
|
|
static bool deny(js::Wrapper::Action act) {
|
2013-01-22 21:04:38 -08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
static bool allowNativeCall(JSContext *cx, JS::IsAcceptableThis test, JS::NativeImpl impl)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2013-03-21 08:20:41 -07:00
|
|
|
static bool isSafeToUnwrap() {
|
|
|
|
return false;
|
|
|
|
}
|
2013-01-22 21:04:38 -08:00
|
|
|
};
|
|
|
|
|
2010-07-02 13:54:53 -07:00
|
|
|
// This policy only permits access to the object if the subject can touch
|
|
|
|
// system objects.
|
|
|
|
struct OnlyIfSubjectIsSystem : public Policy {
|
2012-11-02 17:47:49 -07:00
|
|
|
static bool check(JSContext *cx, JSObject *wrapper, jsid id, js::Wrapper::Action act) {
|
|
|
|
return AccessCheck::isSystemOnlyAccessPermitted(cx);
|
|
|
|
}
|
|
|
|
|
2013-02-25 13:54:18 -08:00
|
|
|
static bool deny(js::Wrapper::Action act) {
|
2011-01-29 18:48:30 -08:00
|
|
|
return false;
|
2010-07-02 13:54:53 -07:00
|
|
|
}
|
2012-12-20 22:33:26 -08:00
|
|
|
|
|
|
|
static bool allowNativeCall(JSContext *cx, JS::IsAcceptableThis test, JS::NativeImpl impl)
|
|
|
|
{
|
|
|
|
return AccessCheck::isSystemOnlyAccessPermitted(cx);
|
|
|
|
}
|
2013-03-21 08:20:41 -07:00
|
|
|
|
|
|
|
static bool isSafeToUnwrap();
|
2010-07-02 13:54:53 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// This policy only permits access to properties that are safe to be used
|
|
|
|
// across origins.
|
|
|
|
struct CrossOriginAccessiblePropertiesOnly : public Policy {
|
2012-11-02 17:47:49 -07:00
|
|
|
static bool check(JSContext *cx, JSObject *wrapper, jsid id, js::Wrapper::Action act) {
|
|
|
|
return AccessCheck::isCrossOriginAccessPermitted(cx, wrapper, id, act);
|
|
|
|
}
|
2013-02-25 13:54:18 -08:00
|
|
|
static bool deny(js::Wrapper::Action act) {
|
2011-01-29 18:48:30 -08:00
|
|
|
return false;
|
2010-07-02 13:54:53 -07:00
|
|
|
}
|
2012-12-20 22:33:26 -08:00
|
|
|
static bool allowNativeCall(JSContext *cx, JS::IsAcceptableThis test, JS::NativeImpl impl)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2013-03-21 08:20:41 -07:00
|
|
|
|
|
|
|
static bool isSafeToUnwrap() {
|
|
|
|
return false;
|
|
|
|
}
|
2010-07-02 13:54:53 -07:00
|
|
|
};
|
2010-06-25 15:58:09 -07:00
|
|
|
|
2010-07-02 13:54:53 -07:00
|
|
|
// This policy only permits access to properties if they appear in the
|
|
|
|
// objects exposed properties list.
|
|
|
|
struct ExposedPropertiesOnly : public Policy {
|
2012-11-02 17:47:49 -07:00
|
|
|
static bool check(JSContext *cx, JSObject *wrapper, jsid id, js::Wrapper::Action act);
|
|
|
|
|
2013-02-25 13:54:18 -08:00
|
|
|
static bool deny(js::Wrapper::Action act) {
|
|
|
|
// Fail silently for GETs.
|
|
|
|
return act == js::Wrapper::GET;
|
2012-11-02 17:47:49 -07:00
|
|
|
}
|
2012-12-20 22:33:26 -08:00
|
|
|
static bool allowNativeCall(JSContext *cx, JS::IsAcceptableThis test, JS::NativeImpl impl);
|
2013-03-21 08:20:41 -07:00
|
|
|
|
|
|
|
static bool isSafeToUnwrap() {
|
|
|
|
return false;
|
|
|
|
}
|
2010-06-25 15:58:09 -07:00
|
|
|
};
|
|
|
|
|
2012-04-28 06:12:28 -07:00
|
|
|
// Components specific policy
|
|
|
|
struct ComponentsObjectPolicy : public Policy {
|
2012-11-02 17:47:49 -07:00
|
|
|
static bool check(JSContext *cx, JSObject *wrapper, jsid id, js::Wrapper::Action act);
|
|
|
|
|
2013-02-25 13:54:18 -08:00
|
|
|
static bool deny(js::Wrapper::Action act) {
|
2012-11-02 17:47:49 -07:00
|
|
|
return false;
|
|
|
|
}
|
2012-12-20 22:33:26 -08:00
|
|
|
static bool allowNativeCall(JSContext *cx, JS::IsAcceptableThis test, JS::NativeImpl impl) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-03-21 08:20:41 -07:00
|
|
|
|
|
|
|
static bool isSafeToUnwrap() {
|
|
|
|
return false;
|
|
|
|
}
|
2012-04-28 06:12:28 -07:00
|
|
|
};
|
|
|
|
|
2010-06-25 15:58:09 -07:00
|
|
|
}
|
2012-07-27 03:15:46 -07:00
|
|
|
|
|
|
|
#endif /* __AccessCheck_h__ */
|