-
-
Notifications
You must be signed in to change notification settings - Fork 35.3k
Expand file tree
/
Copy pathcode_integrity.js
More file actions
44 lines (35 loc) · 1.18 KB
/
code_integrity.js
File metadata and controls
44 lines (35 loc) · 1.18 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
// Code integrity is a security feature which prevents unsigned
// code from executing. More information can be found in the docs
// doc/api/code_integrity.md
'use strict';
const { emitWarning } = require('internal/process/warning');
const {
isFileTrustedBySystemCodeIntegrityPolicy,
isInteractiveModeDisabled,
isSystemEnforcingCodeIntegrity,
} = internalBinding('code_integrity');
let isCodeIntegrityEnforced;
let alreadyQueriedSystemCodeEnforcmentMode = false;
function isAllowedToExecuteFile(filepath) {
if (!alreadyQueriedSystemCodeEnforcmentMode) {
isCodeIntegrityEnforced = isSystemEnforcingCodeIntegrity();
if (isCodeIntegrityEnforced) {
emitWarning(
'Code integrity is being enforced by system policy.' +
'\nCode integrity is an experimental feature.' +
' See docs for more info.',
'ExperimentalWarning');
}
alreadyQueriedSystemCodeEnforcmentMode = true;
}
if (!isCodeIntegrityEnforced) {
return true;
}
return isFileTrustedBySystemCodeIntegrityPolicy(filepath);
}
module.exports = {
isAllowedToExecuteFile,
isFileTrustedBySystemCodeIntegrityPolicy,
isInteractiveModeDisabled,
isSystemEnforcingCodeIntegrity,
};