@secure-exec/core 0.1.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +191 -0
- package/README.md +7 -0
- package/dist/bridge/active-handles.d.ts +21 -0
- package/dist/bridge/active-handles.js +60 -0
- package/dist/bridge/child-process.d.ts +90 -0
- package/dist/bridge/child-process.js +606 -0
- package/dist/bridge/fs.d.ts +281 -0
- package/dist/bridge/fs.js +2151 -0
- package/dist/bridge/index.d.ts +10 -0
- package/dist/bridge/index.js +41 -0
- package/dist/bridge/module.d.ts +75 -0
- package/dist/bridge/module.js +308 -0
- package/dist/bridge/network.d.ts +249 -0
- package/dist/bridge/network.js +1416 -0
- package/dist/bridge/os.d.ts +13 -0
- package/dist/bridge/os.js +256 -0
- package/dist/bridge/polyfills.d.ts +2 -0
- package/dist/bridge/polyfills.js +11 -0
- package/dist/bridge/process.d.ts +86 -0
- package/dist/bridge/process.js +938 -0
- package/dist/bridge-setup.d.ts +6 -0
- package/dist/bridge-setup.js +9 -0
- package/dist/bridge.js +11538 -0
- package/dist/esm-compiler.d.ts +14 -0
- package/dist/esm-compiler.js +68 -0
- package/dist/fs-helpers.d.ts +23 -0
- package/dist/fs-helpers.js +41 -0
- package/dist/generated/isolate-runtime.d.ts +19 -0
- package/dist/generated/isolate-runtime.js +21 -0
- package/dist/generated/polyfills.d.ts +82 -0
- package/dist/generated/polyfills.js +82 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.js +25 -0
- package/dist/isolate-runtime/apply-custom-global-policy.js +54 -0
- package/dist/isolate-runtime/apply-timing-mitigation-freeze.js +44 -0
- package/dist/isolate-runtime/apply-timing-mitigation-off.js +14 -0
- package/dist/isolate-runtime/bridge-attach.js +29 -0
- package/dist/isolate-runtime/bridge-initial-globals.js +246 -0
- package/dist/isolate-runtime/eval-script-result.js +8 -0
- package/dist/isolate-runtime/global-exposure-helpers.js +36 -0
- package/dist/isolate-runtime/init-commonjs-module-globals.js +28 -0
- package/dist/isolate-runtime/override-process-cwd.js +8 -0
- package/dist/isolate-runtime/override-process-env.js +8 -0
- package/dist/isolate-runtime/require-setup.js +650 -0
- package/dist/isolate-runtime/set-commonjs-file-globals.js +36 -0
- package/dist/isolate-runtime/set-stdin-data.js +10 -0
- package/dist/isolate-runtime/setup-dynamic-import.js +64 -0
- package/dist/isolate-runtime/setup-fs-facade.js +48 -0
- package/dist/module-resolver.d.ts +25 -0
- package/dist/module-resolver.js +264 -0
- package/dist/package-bundler.d.ts +36 -0
- package/dist/package-bundler.js +497 -0
- package/dist/python-runtime.d.ts +16 -0
- package/dist/python-runtime.js +45 -0
- package/dist/runtime-driver.d.ts +62 -0
- package/dist/runtime-driver.js +1 -0
- package/dist/runtime.d.ts +31 -0
- package/dist/runtime.js +69 -0
- package/dist/shared/api-types.d.ts +71 -0
- package/dist/shared/api-types.js +1 -0
- package/dist/shared/bridge-contract.d.ts +302 -0
- package/dist/shared/bridge-contract.js +82 -0
- package/dist/shared/console-formatter.d.ts +22 -0
- package/dist/shared/console-formatter.js +157 -0
- package/dist/shared/constants.d.ts +3 -0
- package/dist/shared/constants.js +3 -0
- package/dist/shared/errors.d.ts +16 -0
- package/dist/shared/errors.js +21 -0
- package/dist/shared/esm-utils.d.ts +28 -0
- package/dist/shared/esm-utils.js +97 -0
- package/dist/shared/global-exposure.d.ts +38 -0
- package/dist/shared/global-exposure.js +406 -0
- package/dist/shared/in-memory-fs.d.ts +42 -0
- package/dist/shared/in-memory-fs.js +341 -0
- package/dist/shared/permissions.d.ts +38 -0
- package/dist/shared/permissions.js +283 -0
- package/dist/shared/require-setup.d.ts +6 -0
- package/dist/shared/require-setup.js +9 -0
- package/dist/types.d.ts +206 -0
- package/dist/types.js +1 -0
- package/package.json +107 -0
package/dist/runtime.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { createNetworkStub, filterEnv } from "./shared/permissions.js";
|
|
2
|
+
const DEFAULT_SANDBOX_CWD = "/root";
|
|
3
|
+
const DEFAULT_SANDBOX_HOME = "/root";
|
|
4
|
+
const DEFAULT_SANDBOX_TMPDIR = "/tmp";
|
|
5
|
+
export class NodeRuntime {
|
|
6
|
+
runtimeDriver;
|
|
7
|
+
constructor(options) {
|
|
8
|
+
const { systemDriver, runtimeDriverFactory } = options;
|
|
9
|
+
const processConfig = {
|
|
10
|
+
...(systemDriver.runtime.process ?? {}),
|
|
11
|
+
};
|
|
12
|
+
processConfig.cwd ??= DEFAULT_SANDBOX_CWD;
|
|
13
|
+
processConfig.env = filterEnv(processConfig.env, systemDriver.permissions);
|
|
14
|
+
const osConfig = {
|
|
15
|
+
...(systemDriver.runtime.os ?? {}),
|
|
16
|
+
};
|
|
17
|
+
osConfig.homedir ??= DEFAULT_SANDBOX_HOME;
|
|
18
|
+
osConfig.tmpdir ??= DEFAULT_SANDBOX_TMPDIR;
|
|
19
|
+
this.runtimeDriver = runtimeDriverFactory.createRuntimeDriver({
|
|
20
|
+
system: systemDriver,
|
|
21
|
+
runtime: {
|
|
22
|
+
process: processConfig,
|
|
23
|
+
os: osConfig,
|
|
24
|
+
},
|
|
25
|
+
memoryLimit: options.memoryLimit,
|
|
26
|
+
cpuTimeLimitMs: options.cpuTimeLimitMs,
|
|
27
|
+
timingMitigation: options.timingMitigation,
|
|
28
|
+
onStdio: options.onStdio,
|
|
29
|
+
payloadLimits: options.payloadLimits,
|
|
30
|
+
resourceBudgets: options.resourceBudgets,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
get network() {
|
|
34
|
+
const adapter = this.runtimeDriver.network ?? createNetworkStub();
|
|
35
|
+
return {
|
|
36
|
+
fetch: (url, options) => adapter.fetch(url, options),
|
|
37
|
+
dnsLookup: (hostname) => adapter.dnsLookup(hostname),
|
|
38
|
+
httpRequest: (url, options) => adapter.httpRequest(url, options),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
get __unsafeIsoalte() {
|
|
42
|
+
if (this.runtimeDriver.unsafeIsolate === undefined) {
|
|
43
|
+
throw new Error("Driver runtime does not expose unsafe isolate access");
|
|
44
|
+
}
|
|
45
|
+
return this.runtimeDriver.unsafeIsolate;
|
|
46
|
+
}
|
|
47
|
+
async __unsafeCreateContext(options = {}) {
|
|
48
|
+
if (!this.runtimeDriver.createUnsafeContext) {
|
|
49
|
+
throw new Error("Driver runtime does not expose unsafe context creation");
|
|
50
|
+
}
|
|
51
|
+
return this.runtimeDriver.createUnsafeContext(options);
|
|
52
|
+
}
|
|
53
|
+
async run(code, filePath) {
|
|
54
|
+
return this.runtimeDriver.run(code, filePath);
|
|
55
|
+
}
|
|
56
|
+
async exec(code, options) {
|
|
57
|
+
return this.runtimeDriver.exec(code, options);
|
|
58
|
+
}
|
|
59
|
+
dispose() {
|
|
60
|
+
this.runtimeDriver.dispose();
|
|
61
|
+
}
|
|
62
|
+
async terminate() {
|
|
63
|
+
if (this.runtimeDriver.terminate) {
|
|
64
|
+
await this.runtimeDriver.terminate();
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
this.runtimeDriver.dispose();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export type TimingMitigation = "off" | "freeze";
|
|
2
|
+
export type StdioChannel = "stdout" | "stderr";
|
|
3
|
+
export interface StdioEvent {
|
|
4
|
+
channel: StdioChannel;
|
|
5
|
+
message: string;
|
|
6
|
+
}
|
|
7
|
+
export type StdioHook = (event: StdioEvent) => void;
|
|
8
|
+
export interface ProcessConfig {
|
|
9
|
+
platform?: string;
|
|
10
|
+
arch?: string;
|
|
11
|
+
version?: string;
|
|
12
|
+
cwd?: string;
|
|
13
|
+
env?: Record<string, string>;
|
|
14
|
+
argv?: string[];
|
|
15
|
+
execPath?: string;
|
|
16
|
+
pid?: number;
|
|
17
|
+
ppid?: number;
|
|
18
|
+
uid?: number;
|
|
19
|
+
gid?: number;
|
|
20
|
+
/** Stdin data to provide to the script */
|
|
21
|
+
stdin?: string;
|
|
22
|
+
/** Internal execution timing policy for bridge/process polyfills */
|
|
23
|
+
timingMitigation?: TimingMitigation;
|
|
24
|
+
/** Internal frozen clock source used when timing mitigation is enabled */
|
|
25
|
+
frozenTimeMs?: number;
|
|
26
|
+
}
|
|
27
|
+
export interface OSConfig {
|
|
28
|
+
platform?: string;
|
|
29
|
+
arch?: string;
|
|
30
|
+
type?: string;
|
|
31
|
+
release?: string;
|
|
32
|
+
version?: string;
|
|
33
|
+
homedir?: string;
|
|
34
|
+
tmpdir?: string;
|
|
35
|
+
hostname?: string;
|
|
36
|
+
}
|
|
37
|
+
export interface ExecutionStatus {
|
|
38
|
+
code: number;
|
|
39
|
+
errorMessage?: string;
|
|
40
|
+
}
|
|
41
|
+
export interface RunResult<T = unknown> extends ExecutionStatus {
|
|
42
|
+
exports?: T;
|
|
43
|
+
}
|
|
44
|
+
export interface PythonRunOptions {
|
|
45
|
+
filePath?: string;
|
|
46
|
+
globals?: string[];
|
|
47
|
+
env?: Record<string, string>;
|
|
48
|
+
cwd?: string;
|
|
49
|
+
stdin?: string;
|
|
50
|
+
cpuTimeLimitMs?: number;
|
|
51
|
+
onStdio?: StdioHook;
|
|
52
|
+
}
|
|
53
|
+
export interface PythonRunResult<T = unknown> extends ExecutionStatus {
|
|
54
|
+
value?: T;
|
|
55
|
+
globals?: Record<string, unknown>;
|
|
56
|
+
}
|
|
57
|
+
export interface ExecOptions {
|
|
58
|
+
filePath?: string;
|
|
59
|
+
env?: Record<string, string>;
|
|
60
|
+
cwd?: string;
|
|
61
|
+
/** Stdin data to pass to the script */
|
|
62
|
+
stdin?: string;
|
|
63
|
+
/** Maximum CPU time budget in milliseconds */
|
|
64
|
+
cpuTimeLimitMs?: number;
|
|
65
|
+
/** Timing side-channel mitigation mode */
|
|
66
|
+
timingMitigation?: TimingMitigation;
|
|
67
|
+
/** Optional streaming hook for console output events */
|
|
68
|
+
onStdio?: StdioHook;
|
|
69
|
+
}
|
|
70
|
+
export interface ExecResult extends ExecutionStatus {
|
|
71
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bridge contract: typed declarations for the globals shared between the
|
|
3
|
+
* host (Node.js) and the isolate (sandbox V8 context).
|
|
4
|
+
*
|
|
5
|
+
* Two categories:
|
|
6
|
+
* - Host bridge globals: set by the host before bridge code runs (fs refs, timers, etc.)
|
|
7
|
+
* - Runtime bridge globals: installed by the bridge bundle itself (active handles, modules, etc.)
|
|
8
|
+
*
|
|
9
|
+
* The typed `Ref` aliases describe the isolated-vm calling convention for each global.
|
|
10
|
+
*/
|
|
11
|
+
export type ValueOf<T> = T[keyof T];
|
|
12
|
+
/** Globals injected by the host before the bridge bundle executes. */
|
|
13
|
+
export declare const HOST_BRIDGE_GLOBAL_KEYS: {
|
|
14
|
+
readonly dynamicImport: "_dynamicImport";
|
|
15
|
+
readonly loadPolyfill: "_loadPolyfill";
|
|
16
|
+
readonly resolveModule: "_resolveModule";
|
|
17
|
+
readonly loadFile: "_loadFile";
|
|
18
|
+
readonly scheduleTimer: "_scheduleTimer";
|
|
19
|
+
readonly cryptoRandomFill: "_cryptoRandomFill";
|
|
20
|
+
readonly cryptoRandomUuid: "_cryptoRandomUUID";
|
|
21
|
+
readonly fsReadFile: "_fsReadFile";
|
|
22
|
+
readonly fsWriteFile: "_fsWriteFile";
|
|
23
|
+
readonly fsReadFileBinary: "_fsReadFileBinary";
|
|
24
|
+
readonly fsWriteFileBinary: "_fsWriteFileBinary";
|
|
25
|
+
readonly fsReadDir: "_fsReadDir";
|
|
26
|
+
readonly fsMkdir: "_fsMkdir";
|
|
27
|
+
readonly fsRmdir: "_fsRmdir";
|
|
28
|
+
readonly fsExists: "_fsExists";
|
|
29
|
+
readonly fsStat: "_fsStat";
|
|
30
|
+
readonly fsUnlink: "_fsUnlink";
|
|
31
|
+
readonly fsRename: "_fsRename";
|
|
32
|
+
readonly fsChmod: "_fsChmod";
|
|
33
|
+
readonly fsChown: "_fsChown";
|
|
34
|
+
readonly fsLink: "_fsLink";
|
|
35
|
+
readonly fsSymlink: "_fsSymlink";
|
|
36
|
+
readonly fsReadlink: "_fsReadlink";
|
|
37
|
+
readonly fsLstat: "_fsLstat";
|
|
38
|
+
readonly fsTruncate: "_fsTruncate";
|
|
39
|
+
readonly fsUtimes: "_fsUtimes";
|
|
40
|
+
readonly childProcessSpawnStart: "_childProcessSpawnStart";
|
|
41
|
+
readonly childProcessStdinWrite: "_childProcessStdinWrite";
|
|
42
|
+
readonly childProcessStdinClose: "_childProcessStdinClose";
|
|
43
|
+
readonly childProcessKill: "_childProcessKill";
|
|
44
|
+
readonly childProcessSpawnSync: "_childProcessSpawnSync";
|
|
45
|
+
readonly networkFetchRaw: "_networkFetchRaw";
|
|
46
|
+
readonly networkDnsLookupRaw: "_networkDnsLookupRaw";
|
|
47
|
+
readonly networkHttpRequestRaw: "_networkHttpRequestRaw";
|
|
48
|
+
readonly networkHttpServerListenRaw: "_networkHttpServerListenRaw";
|
|
49
|
+
readonly networkHttpServerCloseRaw: "_networkHttpServerCloseRaw";
|
|
50
|
+
readonly processConfig: "_processConfig";
|
|
51
|
+
readonly osConfig: "_osConfig";
|
|
52
|
+
readonly log: "_log";
|
|
53
|
+
readonly error: "_error";
|
|
54
|
+
};
|
|
55
|
+
/** Globals exposed by the bridge bundle and runtime scripts inside the isolate. */
|
|
56
|
+
export declare const RUNTIME_BRIDGE_GLOBAL_KEYS: {
|
|
57
|
+
readonly registerHandle: "_registerHandle";
|
|
58
|
+
readonly unregisterHandle: "_unregisterHandle";
|
|
59
|
+
readonly waitForActiveHandles: "_waitForActiveHandles";
|
|
60
|
+
readonly getActiveHandles: "_getActiveHandles";
|
|
61
|
+
readonly childProcessDispatch: "_childProcessDispatch";
|
|
62
|
+
readonly childProcessModule: "_childProcessModule";
|
|
63
|
+
readonly moduleModule: "_moduleModule";
|
|
64
|
+
readonly osModule: "_osModule";
|
|
65
|
+
readonly httpModule: "_httpModule";
|
|
66
|
+
readonly httpsModule: "_httpsModule";
|
|
67
|
+
readonly http2Module: "_http2Module";
|
|
68
|
+
readonly dnsModule: "_dnsModule";
|
|
69
|
+
readonly httpServerDispatch: "_httpServerDispatch";
|
|
70
|
+
readonly fsFacade: "_fs";
|
|
71
|
+
readonly requireFrom: "_requireFrom";
|
|
72
|
+
readonly moduleCache: "_moduleCache";
|
|
73
|
+
readonly processExitError: "ProcessExitError";
|
|
74
|
+
};
|
|
75
|
+
export type HostBridgeGlobalKey = ValueOf<typeof HOST_BRIDGE_GLOBAL_KEYS>;
|
|
76
|
+
export type RuntimeBridgeGlobalKey = ValueOf<typeof RUNTIME_BRIDGE_GLOBAL_KEYS>;
|
|
77
|
+
export type BridgeGlobalKey = HostBridgeGlobalKey | RuntimeBridgeGlobalKey;
|
|
78
|
+
export declare const HOST_BRIDGE_GLOBAL_KEY_LIST: ValueOf<{
|
|
79
|
+
readonly dynamicImport: "_dynamicImport";
|
|
80
|
+
readonly loadPolyfill: "_loadPolyfill";
|
|
81
|
+
readonly resolveModule: "_resolveModule";
|
|
82
|
+
readonly loadFile: "_loadFile";
|
|
83
|
+
readonly scheduleTimer: "_scheduleTimer";
|
|
84
|
+
readonly cryptoRandomFill: "_cryptoRandomFill";
|
|
85
|
+
readonly cryptoRandomUuid: "_cryptoRandomUUID";
|
|
86
|
+
readonly fsReadFile: "_fsReadFile";
|
|
87
|
+
readonly fsWriteFile: "_fsWriteFile";
|
|
88
|
+
readonly fsReadFileBinary: "_fsReadFileBinary";
|
|
89
|
+
readonly fsWriteFileBinary: "_fsWriteFileBinary";
|
|
90
|
+
readonly fsReadDir: "_fsReadDir";
|
|
91
|
+
readonly fsMkdir: "_fsMkdir";
|
|
92
|
+
readonly fsRmdir: "_fsRmdir";
|
|
93
|
+
readonly fsExists: "_fsExists";
|
|
94
|
+
readonly fsStat: "_fsStat";
|
|
95
|
+
readonly fsUnlink: "_fsUnlink";
|
|
96
|
+
readonly fsRename: "_fsRename";
|
|
97
|
+
readonly fsChmod: "_fsChmod";
|
|
98
|
+
readonly fsChown: "_fsChown";
|
|
99
|
+
readonly fsLink: "_fsLink";
|
|
100
|
+
readonly fsSymlink: "_fsSymlink";
|
|
101
|
+
readonly fsReadlink: "_fsReadlink";
|
|
102
|
+
readonly fsLstat: "_fsLstat";
|
|
103
|
+
readonly fsTruncate: "_fsTruncate";
|
|
104
|
+
readonly fsUtimes: "_fsUtimes";
|
|
105
|
+
readonly childProcessSpawnStart: "_childProcessSpawnStart";
|
|
106
|
+
readonly childProcessStdinWrite: "_childProcessStdinWrite";
|
|
107
|
+
readonly childProcessStdinClose: "_childProcessStdinClose";
|
|
108
|
+
readonly childProcessKill: "_childProcessKill";
|
|
109
|
+
readonly childProcessSpawnSync: "_childProcessSpawnSync";
|
|
110
|
+
readonly networkFetchRaw: "_networkFetchRaw";
|
|
111
|
+
readonly networkDnsLookupRaw: "_networkDnsLookupRaw";
|
|
112
|
+
readonly networkHttpRequestRaw: "_networkHttpRequestRaw";
|
|
113
|
+
readonly networkHttpServerListenRaw: "_networkHttpServerListenRaw";
|
|
114
|
+
readonly networkHttpServerCloseRaw: "_networkHttpServerCloseRaw";
|
|
115
|
+
readonly processConfig: "_processConfig";
|
|
116
|
+
readonly osConfig: "_osConfig";
|
|
117
|
+
readonly log: "_log";
|
|
118
|
+
readonly error: "_error";
|
|
119
|
+
}>[];
|
|
120
|
+
export declare const RUNTIME_BRIDGE_GLOBAL_KEY_LIST: ValueOf<{
|
|
121
|
+
readonly registerHandle: "_registerHandle";
|
|
122
|
+
readonly unregisterHandle: "_unregisterHandle";
|
|
123
|
+
readonly waitForActiveHandles: "_waitForActiveHandles";
|
|
124
|
+
readonly getActiveHandles: "_getActiveHandles";
|
|
125
|
+
readonly childProcessDispatch: "_childProcessDispatch";
|
|
126
|
+
readonly childProcessModule: "_childProcessModule";
|
|
127
|
+
readonly moduleModule: "_moduleModule";
|
|
128
|
+
readonly osModule: "_osModule";
|
|
129
|
+
readonly httpModule: "_httpModule";
|
|
130
|
+
readonly httpsModule: "_httpsModule";
|
|
131
|
+
readonly http2Module: "_http2Module";
|
|
132
|
+
readonly dnsModule: "_dnsModule";
|
|
133
|
+
readonly httpServerDispatch: "_httpServerDispatch";
|
|
134
|
+
readonly fsFacade: "_fs";
|
|
135
|
+
readonly requireFrom: "_requireFrom";
|
|
136
|
+
readonly moduleCache: "_moduleCache";
|
|
137
|
+
readonly processExitError: "ProcessExitError";
|
|
138
|
+
}>[];
|
|
139
|
+
export declare const BRIDGE_GLOBAL_KEY_LIST: readonly (ValueOf<{
|
|
140
|
+
readonly dynamicImport: "_dynamicImport";
|
|
141
|
+
readonly loadPolyfill: "_loadPolyfill";
|
|
142
|
+
readonly resolveModule: "_resolveModule";
|
|
143
|
+
readonly loadFile: "_loadFile";
|
|
144
|
+
readonly scheduleTimer: "_scheduleTimer";
|
|
145
|
+
readonly cryptoRandomFill: "_cryptoRandomFill";
|
|
146
|
+
readonly cryptoRandomUuid: "_cryptoRandomUUID";
|
|
147
|
+
readonly fsReadFile: "_fsReadFile";
|
|
148
|
+
readonly fsWriteFile: "_fsWriteFile";
|
|
149
|
+
readonly fsReadFileBinary: "_fsReadFileBinary";
|
|
150
|
+
readonly fsWriteFileBinary: "_fsWriteFileBinary";
|
|
151
|
+
readonly fsReadDir: "_fsReadDir";
|
|
152
|
+
readonly fsMkdir: "_fsMkdir";
|
|
153
|
+
readonly fsRmdir: "_fsRmdir";
|
|
154
|
+
readonly fsExists: "_fsExists";
|
|
155
|
+
readonly fsStat: "_fsStat";
|
|
156
|
+
readonly fsUnlink: "_fsUnlink";
|
|
157
|
+
readonly fsRename: "_fsRename";
|
|
158
|
+
readonly fsChmod: "_fsChmod";
|
|
159
|
+
readonly fsChown: "_fsChown";
|
|
160
|
+
readonly fsLink: "_fsLink";
|
|
161
|
+
readonly fsSymlink: "_fsSymlink";
|
|
162
|
+
readonly fsReadlink: "_fsReadlink";
|
|
163
|
+
readonly fsLstat: "_fsLstat";
|
|
164
|
+
readonly fsTruncate: "_fsTruncate";
|
|
165
|
+
readonly fsUtimes: "_fsUtimes";
|
|
166
|
+
readonly childProcessSpawnStart: "_childProcessSpawnStart";
|
|
167
|
+
readonly childProcessStdinWrite: "_childProcessStdinWrite";
|
|
168
|
+
readonly childProcessStdinClose: "_childProcessStdinClose";
|
|
169
|
+
readonly childProcessKill: "_childProcessKill";
|
|
170
|
+
readonly childProcessSpawnSync: "_childProcessSpawnSync";
|
|
171
|
+
readonly networkFetchRaw: "_networkFetchRaw";
|
|
172
|
+
readonly networkDnsLookupRaw: "_networkDnsLookupRaw";
|
|
173
|
+
readonly networkHttpRequestRaw: "_networkHttpRequestRaw";
|
|
174
|
+
readonly networkHttpServerListenRaw: "_networkHttpServerListenRaw";
|
|
175
|
+
readonly networkHttpServerCloseRaw: "_networkHttpServerCloseRaw";
|
|
176
|
+
readonly processConfig: "_processConfig";
|
|
177
|
+
readonly osConfig: "_osConfig";
|
|
178
|
+
readonly log: "_log";
|
|
179
|
+
readonly error: "_error";
|
|
180
|
+
}> | ValueOf<{
|
|
181
|
+
readonly registerHandle: "_registerHandle";
|
|
182
|
+
readonly unregisterHandle: "_unregisterHandle";
|
|
183
|
+
readonly waitForActiveHandles: "_waitForActiveHandles";
|
|
184
|
+
readonly getActiveHandles: "_getActiveHandles";
|
|
185
|
+
readonly childProcessDispatch: "_childProcessDispatch";
|
|
186
|
+
readonly childProcessModule: "_childProcessModule";
|
|
187
|
+
readonly moduleModule: "_moduleModule";
|
|
188
|
+
readonly osModule: "_osModule";
|
|
189
|
+
readonly httpModule: "_httpModule";
|
|
190
|
+
readonly httpsModule: "_httpsModule";
|
|
191
|
+
readonly http2Module: "_http2Module";
|
|
192
|
+
readonly dnsModule: "_dnsModule";
|
|
193
|
+
readonly httpServerDispatch: "_httpServerDispatch";
|
|
194
|
+
readonly fsFacade: "_fs";
|
|
195
|
+
readonly requireFrom: "_requireFrom";
|
|
196
|
+
readonly moduleCache: "_moduleCache";
|
|
197
|
+
readonly processExitError: "ProcessExitError";
|
|
198
|
+
}>)[];
|
|
199
|
+
/** An isolated-vm Reference that resolves async via `{ result: { promise: true } }`. */
|
|
200
|
+
export interface BridgeApplyRef<TArgs extends unknown[], TResult> {
|
|
201
|
+
apply(ctx: undefined, args: TArgs, options: {
|
|
202
|
+
result: {
|
|
203
|
+
promise: true;
|
|
204
|
+
};
|
|
205
|
+
}): Promise<TResult>;
|
|
206
|
+
}
|
|
207
|
+
/** An isolated-vm Reference called synchronously (blocks the isolate). */
|
|
208
|
+
export interface BridgeApplySyncRef<TArgs extends unknown[], TResult> {
|
|
209
|
+
applySync(ctx: undefined, args: TArgs): TResult;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* An isolated-vm Reference that blocks the isolate while the host resolves
|
|
213
|
+
* a Promise. Used for sync-looking APIs (require, readFileSync) that need
|
|
214
|
+
* async host operations.
|
|
215
|
+
*/
|
|
216
|
+
export interface BridgeApplySyncPromiseRef<TArgs extends unknown[], TResult> {
|
|
217
|
+
applySyncPromise(ctx: undefined, args: TArgs): TResult;
|
|
218
|
+
}
|
|
219
|
+
export type DynamicImportBridgeRef = BridgeApplyRef<[
|
|
220
|
+
string,
|
|
221
|
+
string
|
|
222
|
+
], Record<string, unknown> | null>;
|
|
223
|
+
export type LoadPolyfillBridgeRef = BridgeApplyRef<[string], string | null>;
|
|
224
|
+
export type ResolveModuleBridgeRef = BridgeApplySyncPromiseRef<[
|
|
225
|
+
string,
|
|
226
|
+
string
|
|
227
|
+
], string | null>;
|
|
228
|
+
export type LoadFileBridgeRef = BridgeApplySyncPromiseRef<[string], string | null>;
|
|
229
|
+
export type RequireFromBridgeFn = (request: string, dirname: string) => unknown;
|
|
230
|
+
export type ModuleCacheBridgeRecord = Record<string, unknown>;
|
|
231
|
+
export type ProcessLogBridgeRef = BridgeApplySyncRef<[string], void>;
|
|
232
|
+
export type ProcessErrorBridgeRef = BridgeApplySyncRef<[string], void>;
|
|
233
|
+
export type ScheduleTimerBridgeRef = BridgeApplyRef<[number], void>;
|
|
234
|
+
export type CryptoRandomFillBridgeRef = BridgeApplySyncRef<[number], string>;
|
|
235
|
+
export type CryptoRandomUuidBridgeRef = BridgeApplySyncRef<[], string>;
|
|
236
|
+
export type FsReadFileBridgeRef = BridgeApplySyncPromiseRef<[string], string>;
|
|
237
|
+
export type FsWriteFileBridgeRef = BridgeApplySyncPromiseRef<[string, string], void>;
|
|
238
|
+
export type FsReadFileBinaryBridgeRef = BridgeApplySyncPromiseRef<[string], string>;
|
|
239
|
+
export type FsWriteFileBinaryBridgeRef = BridgeApplySyncPromiseRef<[
|
|
240
|
+
string,
|
|
241
|
+
string
|
|
242
|
+
], void>;
|
|
243
|
+
export type FsReadDirBridgeRef = BridgeApplySyncPromiseRef<[string], string>;
|
|
244
|
+
export type FsMkdirBridgeRef = BridgeApplySyncPromiseRef<[string, boolean], void>;
|
|
245
|
+
export type FsRmdirBridgeRef = BridgeApplySyncPromiseRef<[string], void>;
|
|
246
|
+
export type FsExistsBridgeRef = BridgeApplySyncPromiseRef<[string], boolean>;
|
|
247
|
+
export type FsStatBridgeRef = BridgeApplySyncPromiseRef<[string], string>;
|
|
248
|
+
export type FsUnlinkBridgeRef = BridgeApplySyncPromiseRef<[string], void>;
|
|
249
|
+
export type FsRenameBridgeRef = BridgeApplySyncPromiseRef<[string, string], void>;
|
|
250
|
+
export type FsChmodBridgeRef = BridgeApplySyncPromiseRef<[string, number], void>;
|
|
251
|
+
export type FsChownBridgeRef = BridgeApplySyncPromiseRef<[string, number, number], void>;
|
|
252
|
+
export type FsLinkBridgeRef = BridgeApplySyncPromiseRef<[string, string], void>;
|
|
253
|
+
export type FsSymlinkBridgeRef = BridgeApplySyncPromiseRef<[string, string], void>;
|
|
254
|
+
export type FsReadlinkBridgeRef = BridgeApplySyncPromiseRef<[string], string>;
|
|
255
|
+
export type FsLstatBridgeRef = BridgeApplySyncPromiseRef<[string], string>;
|
|
256
|
+
export type FsTruncateBridgeRef = BridgeApplySyncPromiseRef<[string, number], void>;
|
|
257
|
+
export type FsUtimesBridgeRef = BridgeApplySyncPromiseRef<[string, number, number], void>;
|
|
258
|
+
/** Combined filesystem bridge facade installed as `globalThis._fs` in the isolate. */
|
|
259
|
+
export interface FsFacadeBridge {
|
|
260
|
+
readFile: FsReadFileBridgeRef;
|
|
261
|
+
writeFile: FsWriteFileBridgeRef;
|
|
262
|
+
readFileBinary: FsReadFileBinaryBridgeRef;
|
|
263
|
+
writeFileBinary: FsWriteFileBinaryBridgeRef;
|
|
264
|
+
readDir: FsReadDirBridgeRef;
|
|
265
|
+
mkdir: FsMkdirBridgeRef;
|
|
266
|
+
rmdir: FsRmdirBridgeRef;
|
|
267
|
+
exists: FsExistsBridgeRef;
|
|
268
|
+
stat: FsStatBridgeRef;
|
|
269
|
+
unlink: FsUnlinkBridgeRef;
|
|
270
|
+
rename: FsRenameBridgeRef;
|
|
271
|
+
chmod: FsChmodBridgeRef;
|
|
272
|
+
chown: FsChownBridgeRef;
|
|
273
|
+
link: FsLinkBridgeRef;
|
|
274
|
+
symlink: FsSymlinkBridgeRef;
|
|
275
|
+
readlink: FsReadlinkBridgeRef;
|
|
276
|
+
lstat: FsLstatBridgeRef;
|
|
277
|
+
truncate: FsTruncateBridgeRef;
|
|
278
|
+
utimes: FsUtimesBridgeRef;
|
|
279
|
+
}
|
|
280
|
+
export type ChildProcessSpawnStartBridgeRef = BridgeApplySyncRef<[
|
|
281
|
+
string,
|
|
282
|
+
string,
|
|
283
|
+
string
|
|
284
|
+
], number>;
|
|
285
|
+
export type ChildProcessStdinWriteBridgeRef = BridgeApplySyncRef<[
|
|
286
|
+
number,
|
|
287
|
+
Uint8Array
|
|
288
|
+
], void>;
|
|
289
|
+
export type ChildProcessStdinCloseBridgeRef = BridgeApplySyncRef<[number], void>;
|
|
290
|
+
export type ChildProcessKillBridgeRef = BridgeApplySyncRef<[number, number], void>;
|
|
291
|
+
export type ChildProcessSpawnSyncBridgeRef = BridgeApplySyncPromiseRef<[
|
|
292
|
+
string,
|
|
293
|
+
string,
|
|
294
|
+
string
|
|
295
|
+
], string>;
|
|
296
|
+
export type NetworkFetchRawBridgeRef = BridgeApplyRef<[string, string], string>;
|
|
297
|
+
export type NetworkDnsLookupRawBridgeRef = BridgeApplyRef<[string], string>;
|
|
298
|
+
export type NetworkHttpRequestRawBridgeRef = BridgeApplyRef<[string, string], string>;
|
|
299
|
+
export type NetworkHttpServerListenRawBridgeRef = BridgeApplyRef<[string], string>;
|
|
300
|
+
export type NetworkHttpServerCloseRawBridgeRef = BridgeApplyRef<[number], void>;
|
|
301
|
+
export type RegisterHandleBridgeFn = (id: string, description: string) => void;
|
|
302
|
+
export type UnregisterHandleBridgeFn = (id: string) => void;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bridge contract: typed declarations for the globals shared between the
|
|
3
|
+
* host (Node.js) and the isolate (sandbox V8 context).
|
|
4
|
+
*
|
|
5
|
+
* Two categories:
|
|
6
|
+
* - Host bridge globals: set by the host before bridge code runs (fs refs, timers, etc.)
|
|
7
|
+
* - Runtime bridge globals: installed by the bridge bundle itself (active handles, modules, etc.)
|
|
8
|
+
*
|
|
9
|
+
* The typed `Ref` aliases describe the isolated-vm calling convention for each global.
|
|
10
|
+
*/
|
|
11
|
+
function valuesOf(object) {
|
|
12
|
+
return Object.values(object);
|
|
13
|
+
}
|
|
14
|
+
/** Globals injected by the host before the bridge bundle executes. */
|
|
15
|
+
export const HOST_BRIDGE_GLOBAL_KEYS = {
|
|
16
|
+
dynamicImport: "_dynamicImport",
|
|
17
|
+
loadPolyfill: "_loadPolyfill",
|
|
18
|
+
resolveModule: "_resolveModule",
|
|
19
|
+
loadFile: "_loadFile",
|
|
20
|
+
scheduleTimer: "_scheduleTimer",
|
|
21
|
+
cryptoRandomFill: "_cryptoRandomFill",
|
|
22
|
+
cryptoRandomUuid: "_cryptoRandomUUID",
|
|
23
|
+
fsReadFile: "_fsReadFile",
|
|
24
|
+
fsWriteFile: "_fsWriteFile",
|
|
25
|
+
fsReadFileBinary: "_fsReadFileBinary",
|
|
26
|
+
fsWriteFileBinary: "_fsWriteFileBinary",
|
|
27
|
+
fsReadDir: "_fsReadDir",
|
|
28
|
+
fsMkdir: "_fsMkdir",
|
|
29
|
+
fsRmdir: "_fsRmdir",
|
|
30
|
+
fsExists: "_fsExists",
|
|
31
|
+
fsStat: "_fsStat",
|
|
32
|
+
fsUnlink: "_fsUnlink",
|
|
33
|
+
fsRename: "_fsRename",
|
|
34
|
+
fsChmod: "_fsChmod",
|
|
35
|
+
fsChown: "_fsChown",
|
|
36
|
+
fsLink: "_fsLink",
|
|
37
|
+
fsSymlink: "_fsSymlink",
|
|
38
|
+
fsReadlink: "_fsReadlink",
|
|
39
|
+
fsLstat: "_fsLstat",
|
|
40
|
+
fsTruncate: "_fsTruncate",
|
|
41
|
+
fsUtimes: "_fsUtimes",
|
|
42
|
+
childProcessSpawnStart: "_childProcessSpawnStart",
|
|
43
|
+
childProcessStdinWrite: "_childProcessStdinWrite",
|
|
44
|
+
childProcessStdinClose: "_childProcessStdinClose",
|
|
45
|
+
childProcessKill: "_childProcessKill",
|
|
46
|
+
childProcessSpawnSync: "_childProcessSpawnSync",
|
|
47
|
+
networkFetchRaw: "_networkFetchRaw",
|
|
48
|
+
networkDnsLookupRaw: "_networkDnsLookupRaw",
|
|
49
|
+
networkHttpRequestRaw: "_networkHttpRequestRaw",
|
|
50
|
+
networkHttpServerListenRaw: "_networkHttpServerListenRaw",
|
|
51
|
+
networkHttpServerCloseRaw: "_networkHttpServerCloseRaw",
|
|
52
|
+
processConfig: "_processConfig",
|
|
53
|
+
osConfig: "_osConfig",
|
|
54
|
+
log: "_log",
|
|
55
|
+
error: "_error",
|
|
56
|
+
};
|
|
57
|
+
/** Globals exposed by the bridge bundle and runtime scripts inside the isolate. */
|
|
58
|
+
export const RUNTIME_BRIDGE_GLOBAL_KEYS = {
|
|
59
|
+
registerHandle: "_registerHandle",
|
|
60
|
+
unregisterHandle: "_unregisterHandle",
|
|
61
|
+
waitForActiveHandles: "_waitForActiveHandles",
|
|
62
|
+
getActiveHandles: "_getActiveHandles",
|
|
63
|
+
childProcessDispatch: "_childProcessDispatch",
|
|
64
|
+
childProcessModule: "_childProcessModule",
|
|
65
|
+
moduleModule: "_moduleModule",
|
|
66
|
+
osModule: "_osModule",
|
|
67
|
+
httpModule: "_httpModule",
|
|
68
|
+
httpsModule: "_httpsModule",
|
|
69
|
+
http2Module: "_http2Module",
|
|
70
|
+
dnsModule: "_dnsModule",
|
|
71
|
+
httpServerDispatch: "_httpServerDispatch",
|
|
72
|
+
fsFacade: "_fs",
|
|
73
|
+
requireFrom: "_requireFrom",
|
|
74
|
+
moduleCache: "_moduleCache",
|
|
75
|
+
processExitError: "ProcessExitError",
|
|
76
|
+
};
|
|
77
|
+
export const HOST_BRIDGE_GLOBAL_KEY_LIST = valuesOf(HOST_BRIDGE_GLOBAL_KEYS);
|
|
78
|
+
export const RUNTIME_BRIDGE_GLOBAL_KEY_LIST = valuesOf(RUNTIME_BRIDGE_GLOBAL_KEYS);
|
|
79
|
+
export const BRIDGE_GLOBAL_KEY_LIST = [
|
|
80
|
+
...HOST_BRIDGE_GLOBAL_KEY_LIST,
|
|
81
|
+
...RUNTIME_BRIDGE_GLOBAL_KEY_LIST,
|
|
82
|
+
];
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Controls how deeply and widely console.log arguments are serialized.
|
|
3
|
+
* Prevents CPU amplification and memory buildup from deeply-nested or
|
|
4
|
+
* massive objects being logged inside the sandbox.
|
|
5
|
+
*/
|
|
6
|
+
export interface ConsoleSerializationBudget {
|
|
7
|
+
maxDepth: number;
|
|
8
|
+
maxKeys: number;
|
|
9
|
+
maxArrayLength: number;
|
|
10
|
+
maxOutputLength: number;
|
|
11
|
+
}
|
|
12
|
+
export declare const DEFAULT_CONSOLE_SERIALIZATION_BUDGET: ConsoleSerializationBudget;
|
|
13
|
+
/** Serialize a single value with circular reference detection and budget limits. */
|
|
14
|
+
export declare function safeStringifyConsoleValue(value: unknown, rawBudget: ConsoleSerializationBudget): string;
|
|
15
|
+
/** Format an array of console arguments into a single space-separated string. */
|
|
16
|
+
export declare function formatConsoleArgs(args: unknown[], rawBudget: ConsoleSerializationBudget): string;
|
|
17
|
+
/**
|
|
18
|
+
* Generate isolate-side JavaScript that installs a `globalThis.console` shim.
|
|
19
|
+
* The shim serializes arguments using the budget and forwards them to host
|
|
20
|
+
* bridge references (`_log` / `_error`) via `applySync`.
|
|
21
|
+
*/
|
|
22
|
+
export declare function getConsoleSetupCode(budget?: ConsoleSerializationBudget): string;
|