1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
/* -*- 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/. */
#ifndef __AccessCheck_h__
#define __AccessCheck_h__
#include "js/Id.h"
#include "js/Wrapper.h"
#include "nsString.h"
#ifdef XP_MACOSX
// AssertMacros.h defines 'check' which conflicts with the method declarations
// in this file.
# undef check
#endif
namespace xpc {
class AccessCheck {
public:
static bool subsumes(JSObject* a, JSObject* b);
static bool wrapperSubsumes(JSObject* wrapper);
static bool subsumesConsideringDomain(JS::Realm* a, JS::Realm* b);
static bool subsumesConsideringDomainIgnoringFPD(JS::Realm* a, JS::Realm* b);
static bool isChrome(JS::Compartment* compartment);
static bool isChrome(JS::Realm* realm);
static bool isChrome(JSObject* obj);
static bool checkPassToPrivilegedCode(JSContext* cx, JS::HandleObject wrapper,
JS::HandleValue value);
static bool checkPassToPrivilegedCode(JSContext* cx, JS::HandleObject wrapper,
const JS::CallArgs& args);
// Called to report the correct sort of exception when our policy denies and
// should throw. The accessType argument should be one of "access",
// "define", "delete", depending on which operation is being denied.
static void reportCrossOriginDenial(JSContext* cx, JS::HandleId id,
const nsACString& accessType);
};
/**
* Returns true if the given object (which is expected to be stripped of
* cross-compartment wrappers in practice, but this function doesn't assume
* that) is a WindowProxy or Location object, which need special wrapping
* behavior due to being usable cross-origin in limited ways.
*/
bool IsCrossOriginAccessibleObject(JSObject* obj);
struct Policy {
static bool checkCall(JSContext* cx, JS::HandleObject wrapper,
const JS::CallArgs& args) {
MOZ_CRASH("As a rule, filtering wrappers are non-callable");
}
};
// This policy allows no interaction with the underlying callable. Everything
// throws.
struct Opaque : public Policy {
static bool check(JSContext* cx, JSObject* wrapper, jsid id,
js::Wrapper::Action act) {
return false;
}
static bool deny(JSContext* cx, js::Wrapper::Action act, JS::HandleId id,
bool mayThrow) {
return false;
}
static bool allowNativeCall(JSContext* cx, JS::IsAcceptableThis test,
JS::NativeImpl impl) {
return false;
}
};
// Like the above, but allows CALL.
struct OpaqueWithCall : public Policy {
static bool check(JSContext* cx, JSObject* wrapper, jsid id,
js::Wrapper::Action act) {
return act == js::Wrapper::CALL;
}
static bool deny(JSContext* cx, js::Wrapper::Action act, JS::HandleId id,
bool mayThrow) {
return false;
}
static bool allowNativeCall(JSContext* cx, JS::IsAcceptableThis test,
JS::NativeImpl impl) {
return false;
}
static bool checkCall(JSContext* cx, JS::HandleObject wrapper,
const JS::CallArgs& args) {
return AccessCheck::checkPassToPrivilegedCode(cx, wrapper, args);
}
};
// This class used to support permitting access to properties if they
// appeared in an access list on the object, but now it acts like an
// Opaque wrapper, with the exception that it fails silently for GET,
// ENUMERATE, and GET_PROPERTY_DESCRIPTOR. This is done for backwards
// compatibility. See bug 1397513.
struct OpaqueWithSilentFailing : public Policy {
static bool check(JSContext* cx, JS::HandleObject wrapper, JS::HandleId id,
js::Wrapper::Action act) {
return false;
}
static bool deny(JSContext* cx, js::Wrapper::Action act, JS::HandleId id,
bool mayThrow);
static bool allowNativeCall(JSContext* cx, JS::IsAcceptableThis test,
JS::NativeImpl impl) {
return false;
}
};
} // namespace xpc
#endif /* __AccessCheck_h__ */
|