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 "jswrapper.h"
|
2013-09-05 16:08:57 -07:00
|
|
|
#include "js/Id.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);
|
2014-02-13 18:57:34 -08:00
|
|
|
static bool subsumesConsideringDomain(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 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-06-21 06:12:46 -07:00
|
|
|
static bool deny(js::Wrapper::Action act, JS::HandleId id) {
|
2013-01-22 21:04:38 -08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
static bool allowNativeCall(JSContext *cx, JS::IsAcceptableThis test, JS::NativeImpl impl)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-04-03 11:41:23 -07:00
|
|
|
// This policy is designed to protect privileged callers from untrusted non-
|
|
|
|
// Xrayable objects. Nothing is allowed, and nothing throws.
|
|
|
|
struct GentlyOpaque : public Policy {
|
|
|
|
static bool check(JSContext *cx, JSObject *wrapper, jsid id, js::Wrapper::Action act) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-06-21 06:12:46 -07:00
|
|
|
static bool deny(js::Wrapper::Action act, JS::HandleId id) {
|
2013-04-03 11:41:23 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
static bool allowNativeCall(JSContext *cx, JS::IsAcceptableThis test, JS::NativeImpl impl)
|
|
|
|
{
|
|
|
|
// We allow nativeCall here because the alternative is throwing (which
|
|
|
|
// happens in SecurityWrapper::nativeCall), which we don't want. There's
|
|
|
|
// unlikely to be too much harm to letting this through, because this
|
|
|
|
// wrapper is only used to wrap less-privileged objects in more-privileged
|
|
|
|
// scopes, so unwrapping here only drops privileges.
|
|
|
|
return true;
|
|
|
|
}
|
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-06-21 06:12:46 -07:00
|
|
|
static bool deny(js::Wrapper::Action act, JS::HandleId id) {
|
2013-05-22 21:27:15 -07:00
|
|
|
// Silently fail for enumerate-like operations.
|
2014-02-13 10:54:08 -08:00
|
|
|
if (act == js::Wrapper::ENUMERATE)
|
2013-05-22 21:27:15 -07:00
|
|
|
return true;
|
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;
|
|
|
|
}
|
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-06-21 06:12:46 -07:00
|
|
|
static bool deny(js::Wrapper::Action act, JS::HandleId id) {
|
2014-02-13 10:54:08 -08:00
|
|
|
// Fail silently for GETs and ENUMERATEs.
|
|
|
|
return act == js::Wrapper::GET || act == js::Wrapper::ENUMERATE;
|
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);
|
2010-06-25 15:58:09 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
2012-07-27 03:15:46 -07:00
|
|
|
|
|
|
|
#endif /* __AccessCheck_h__ */
|