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