-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwhitelist.js
450 lines (439 loc) · 13.8 KB
/
whitelist.js
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
// Copyright (C) 2011 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/**
* @fileoverview Exports {@code ses.whitelist}, a recursively defined
* JSON record enumerating all the naming paths in the ES5.1 spec,
* those de-facto extensions that we judge to be safe, and SES and
* Dr. SES extensions provided by the SES runtime.
*
* <p>Assumes only ES3. Compatible with ES5, ES5-strict, or
* anticipated ES6.
*
* //provides ses.whitelist
* @author Mark S. Miller,
* @overrides ses, whitelistModule
*/
var ses;
/**
* <p>Each JSON record enumerates the disposition of the properties on
* some corresponding primordial object, with the root record
* representing the global object. For each such record, the values
* associated with its property names can be
* <ul>
* <li>Another record, in which case this property is simply
* whitelisted and that next record represents the disposition of
* the object which is its value. For example, {@code "Object"}
* leads to another record explaining what properties {@code
* "Object"} may have and how each such property, if present,
* and its value should be tamed.
* <li>true, in which case this property is simply whitelisted. The
* value associated with that property is still traversed and
* tamed, but only according to the taming of the objects that
* object inherits from. For example, {@code "Object.freeze"} leads
* to true, meaning that the {@code "freeze"} property of {@code
* Object} should be whitelisted and the value of the property (a
* function) should be further tamed only according to the
* markings of the other objects it inherits from, like {@code
* "Function.prototype"} and {@code "Object.prototype").
* <li>"*", in which case this property on this object is whitelisted,
* as is this property as inherited by all objects that inherit
* from this object. The values associated with all such properties
* are still traversed and tamed, but only according to the taming
* of the objects that object inherits from. For example, {@code
* "Object.prototype.constructor"} leads to "*", meaning that we
* whitelist the {@code "constructor"} property on {@code
* Object.prototype} and on every object that inherits from {@code
* Object.prototype} that does not have a conflicting mark. Each
* of these is tamed as if with true, so that the value of the
* property is further tamed according to what other objects it
* inherits from.
* <li>"skip", in which case this property on this object is simply
* whitelisted, as is this property as inherited by all objects
* that inherit from this object, but we avoid taming the value
* associated with that property. For example, as of this writing
* {@code "Function.prototype.caller"} leads to "skip" because
* some current browser bugs prevent us from removing or even
* traversing this property on some platforms of interest.
* </ul>
*
* The "skip" markings are workarounds for browser bugs or other
* temporary problems. For each of these, there should be an
* explanatory comment explaining why or a bug citation. Ideally, we
* can retire all "skip" entries by the time SES is ready for secure
* production use.
*
* The members of the whitelist are either
* <ul>
* <li>(uncommented) defined by the ES5.1 normative standard text,
* <li>(questionable) provides a source of non-determinism, in
* violation of pure object-capability rules, but allowed anyway
* since we've given up on restricting JavaScript to a
* deterministic subset.
* <li>(ES5 Appendix B) common elements of de facto JavaScript
* described by the non-normative Appendix B.
* <li>(Harmless whatwg) extensions documented at
* <a href="http://wiki.whatwg.org/wiki/Web_ECMAScript"
* >http://wiki.whatwg.org/wiki/Web_ECMAScript</a> that seem to be
* harmless. Note that the RegExp constructor extensions on that
* page are <b>not harmless</b> and so must not be whitelisted.
* <li>(ES-Harmony proposal) accepted as "proposal" status for
* EcmaScript-Harmony.
* <li>(Marked as "skip") See above.
* </ul>
*
* <p>With the above encoding, there are some sensible whitelists we
* cannot express, such as marking a property both with "*" and a JSON
* record. This is an expedient decision based only on not having
* encountered such a need. Should we need this extra expressiveness,
* we'll need to refactor to enable a different encoding.
*
* <p>We factor out {@code true} into the variable {@code t} just to
* get a bit better compression from simple minifiers.
*/
(function whitelistModule() {
"use strict";
if (!ses) { ses = {}; }
var t = true;
ses.whitelist = {
cajaVM: { // Caja support
log: t,
tamperProof: t,
constFunc: t,
Nat: t,
def: t,
is: t,
compileExpr: t,
confine: t,
compileModule: t, // experimental
compileProgram: t, // Cannot be implemented in just ES5.1.
eval: t,
Function: t,
sharedImports: t,
makeImports: t,
copyToImports: t,
callWithEjector: t,
eject: t,
GuardT: {
coerce: t
},
makeTableGuard: t,
Trademark: {
stamp: t
},
guard: t,
passesGuard: t,
stamp: t,
makeSealerUnsealerPair: t,
makeArrayLike: {}
},
WeakMap: { // ES-Harmony proposal as currently implemented by FF6.0a1
prototype: {
// Note: coordinate this list with maintenance of repairES5.js
get: t,
set: t,
has: t,
'delete': t
}
},
StringMap: { // A specialized approximation of ES-Harmony's Map.
prototype: {} // Technically, the methods should be on the prototype,
// but doing so while preserving encapsulation will be
// needlessly expensive for current usage.
},
// As of this writing, the WeakMap emulation in WeakMap.js relies on
// the unguessability and undiscoverability of HIDDEN_NAME, a
// secret property name. However, on a platform with built-in
// Proxies, if whitelisted but not properly monkey patched, proxies
// could be used to trap and thereby discover HIDDEN_NAME. So until we
// (TODO(erights)) write the needed monkey patching of proxies, we
// omit them from our whitelist.
// Proxy: { // ES-Harmony proposal
// create: t,
// createFunction: t
// },
escape: t, // ES5 Appendix B
unescape: t, // ES5 Appendix B
Object: {
// If any new methods are added here that may reveal the
// HIDDEN_NAME within WeakMap.js, such as the proposed
// getOwnPropertyDescriptors or getPropertyDescriptors, then
// extend WeakMap.js to monkey patch these to avoid revealing
// HIDDEN_NAME.
getPropertyDescriptor: t, // ES-Harmony proposal
getPropertyNames: t, // ES-Harmony proposal
is: t, // ES-Harmony proposal
prototype: {
// Whitelisted only to work around a Chrome debugger
// stratification bug (TODO(erights): report). These are
// redefined in startSES.js in terms of standard methods, so
// that we can be confident they introduce no non-standard
// possibilities.
__defineGetter__: t,
__defineSetter__: t,
__lookupGetter__: t,
__lookupSetter__: t,
constructor: '*',
toString: '*',
toLocaleString: '*',
valueOf: t,
hasOwnProperty: t,
isPrototypeOf: t,
propertyIsEnumerable: t
},
getPrototypeOf: t,
getOwnPropertyDescriptor: t,
getOwnPropertyNames: t,
create: t,
defineProperty: t,
defineProperties: t,
seal: t,
freeze: t,
preventExtensions: t,
isSealed: t,
isFrozen: t,
isExtensible: t,
keys: t
},
NaN: t,
Infinity: t,
undefined: t,
// eval: t, // Whitelisting under separate control
// by TAME_GLOBAL_EVAL in startSES.js
parseInt: t,
parseFloat: t,
isNaN: t,
isFinite: t,
decodeURI: t,
decodeURIComponent: t,
encodeURI: t,
encodeURIComponent: t,
Function: {
prototype: {
apply: t,
call: t,
bind: t,
prototype: '*',
length: '*',
arity: '*', // non-std, deprecated in favor of length
name: '*' // non-std
}
},
Array: {
prototype: {
concat: t,
join: t,
pop: t,
push: t,
reverse: t,
shift: t,
slice: t,
sort: t,
splice: t,
unshift: t,
indexOf: t,
lastIndexOf: t,
every: t,
some: t,
forEach: t,
map: t,
filter: t,
reduce: t,
reduceRight: t,
length: 'skip' // can't be redefined on Mozilla
// See https://bugzilla.mozilla.org/show_bug.cgi?id=591059
// and https://bugzilla.mozilla.org/show_bug.cgi?id=598996
},
isArray: t
},
String: {
prototype: {
substr: t, // ES5 Appendix B
anchor: t, // Harmless whatwg
big: t, // Harmless whatwg
blink: t, // Harmless whatwg
bold: t, // Harmless whatwg
fixed: t, // Harmless whatwg
fontcolor: t, // Harmless whatwg
fontsize: t, // Harmless whatwg
italics: t, // Harmless whatwg
link: t, // Harmless whatwg
small: t, // Harmless whatwg
strike: t, // Harmless whatwg
sub: t, // Harmless whatwg
sup: t, // Harmless whatwg
trimLeft: t, // non-standard
trimRight: t, // non-standard
valueOf: t,
charAt: t,
charCodeAt: t,
concat: t,
indexOf: t,
lastIndexOf: t,
localeCompare: t,
match: t,
replace: t,
search: t,
slice: t,
split: t,
substring: t,
toLowerCase: t,
toLocaleLowerCase: t,
toUpperCase: t,
toLocaleUpperCase: t,
trim: t,
length: '*'
},
fromCharCode: t
},
Boolean: {
prototype: {
valueOf: t
}
},
Number: {
prototype: {
valueOf: t,
toFixed: t,
toExponential: t,
toPrecision: t
},
MAX_VALUE: t,
MIN_VALUE: t,
NaN: t,
NEGATIVE_INFINITY: t,
POSITIVE_INFINITY: t
},
Math: {
E: t,
LN10: t,
LN2: t,
LOG2E: t,
LOG10E: t,
PI: t,
SQRT1_2: t,
SQRT2: t,
abs: t,
acos: t,
asin: t,
atan: t,
atan2: t,
ceil: t,
cos: t,
exp: t,
floor: t,
log: t,
max: t,
min: t,
pow: t,
random: t, // questionable
round: t,
sin: t,
sqrt: t,
tan: t
},
Date: { // no-arg Date constructor is questionable
prototype: {
// Note: coordinate this list with maintanence of repairES5.js
getYear: t, // ES5 Appendix B
setYear: t, // ES5 Appendix B
toGMTString: t, // ES5 Appendix B
toDateString: t,
toTimeString: t,
toLocaleString: t,
toLocaleDateString: t,
toLocaleTimeString: t,
valueOf: t,
getTime: t,
getFullYear: t,
getUTCFullYear: t,
getMonth: t,
getUTCMonth: t,
getDate: t,
getUTCDate: t,
getDay: t,
getUTCDay: t,
getHours: t,
getUTCHours: t,
getMinutes: t,
getUTCMinutes: t,
getSeconds: t,
getUTCSeconds: t,
getMilliseconds: t,
getUTCMilliseconds: t,
getTimezoneOffset: t,
setTime: t,
setFullYear: t,
setUTCFullYear: t,
setMonth: t,
setUTCMonth: t,
setDate: t,
setUTCDate: t,
setHours: t,
setUTCHours: t,
setMinutes: t,
setUTCMinutes: t,
setSeconds: t,
setUTCSeconds: t,
setMilliseconds: t,
setUTCMilliseconds: t,
toUTCString: t,
toISOString: t,
toJSON: t
},
parse: t,
UTC: t,
now: t // questionable
},
RegExp: {
prototype: {
exec: t,
test: t,
source: '*',
global: '*',
ignoreCase: '*',
multiline: '*',
lastIndex: '*',
sticky: '*' // non-std
}
},
Error: {
prototype: {
name: '*',
message: '*'
}
},
EvalError: {
prototype: t
},
RangeError: {
prototype: t
},
ReferenceError: {
prototype: t
},
SyntaxError: {
prototype: t
},
TypeError: {
prototype: t
},
URIError: {
prototype: t
},
JSON: {
parse: t,
stringify: t
}
};
})();