forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathpolicy.js
More file actions
77 lines (66 loc) · 1.74 KB
/
Copy pathpolicy.js
File metadata and controls
77 lines (66 loc) · 1.74 KB
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
'use strict';
const {
JSONParse,
ObjectFreeze,
ReflectSetPrototypeOf,
} = primordials;
const {
ERR_ACCESS_DENIED,
ERR_MANIFEST_TDZ,
} = require('internal/errors').codes;
const { Manifest } = require('internal/policy/manifest');
const { getOptionValue } = require('internal/options');
const deprecatedProcessBinding = getOptionValue('--deprecated-process-binding');
let manifest;
let manifestSrc;
let manifestURL;
module.exports = ObjectFreeze({
__proto__: null,
setup(src, url) {
manifestSrc = src;
manifestURL = url;
if (src === null) {
manifest = null;
return;
}
const json = JSONParse(src, (_, o) => {
if (o && typeof o === 'object') {
ReflectSetPrototypeOf(o, null);
ObjectFreeze(o);
}
return o;
});
manifest = new Manifest(json, url);
// process.binding() is deprecated (DEP0111) and trivially allows bypassing
// policies, so if policies are enabled, make this API unavailable.
if (deprecatedProcessBinding) {
process.binding = function binding(_module) {
throw new ERR_ACCESS_DENIED('process.binding');
};
}
process._linkedBinding = function _linkedBinding(_module) {
throw new ERR_ACCESS_DENIED('process._linkedBinding');
};
},
get manifest() {
if (typeof manifest === 'undefined') {
throw new ERR_MANIFEST_TDZ();
}
return manifest;
},
get src() {
if (typeof manifestSrc === 'undefined') {
throw new ERR_MANIFEST_TDZ();
}
return manifestSrc;
},
get url() {
if (typeof manifestURL === 'undefined') {
throw new ERR_MANIFEST_TDZ();
}
return manifestURL;
},
assertIntegrity(moduleURL, content) {
this.manifest.assertIntegrity(moduleURL, content);
},
});