@memberjunction/code-execution 5.29.0 → 5.30.0
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/.turbo/turbo-build.log +6 -2
- package/CHANGELOG.md +16 -0
- package/dist/WorkerPool.d.ts +39 -1
- package/dist/WorkerPool.d.ts.map +1 -1
- package/dist/WorkerPool.js +305 -22
- package/dist/WorkerPool.js.map +1 -1
- package/dist/libraries/bundled-libs/date-fns.js +3 -0
- package/dist/libraries/bundled-libs/jstat.js +1 -0
- package/dist/libraries/bundled-libs/lodash.js +140 -0
- package/dist/libraries/bundled-libs/mathjs.js +3 -0
- package/dist/libraries/bundled-libs/papaparse.js +7 -0
- package/dist/libraries/bundled-libs/uuid.js +43 -0
- package/dist/libraries/bundled-libs/validator.js +23 -0
- package/dist/libraries/index.js +128 -7
- package/dist/libraries/index.js.map +1 -1
- package/dist/types/index.d.ts +106 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/worker.d.ts +22 -0
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +194 -4
- package/dist/worker.js.map +1 -1
- package/package.json +5 -4
- package/src/WorkerPool.ts +398 -26
- package/src/__tests__/WorkerPool.test.ts +7 -3
- package/src/__tests__/bridge.test.ts +188 -0
- package/src/__tests__/libraries.test.ts +13 -17
- package/src/libraries/index.ts +129 -7
- package/src/types/index.ts +129 -5
- package/src/worker.ts +255 -8
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* A host-side bridge handler function. Registered per-execution via
|
|
3
|
+
* `CodeExecutionService.execute({ bridgeHandlers, ... })` and invoked when
|
|
4
|
+
* sandboxed code calls `__bridgeCall(name, args)`. The handler receives the
|
|
5
|
+
* args (already JSON-round-tripped, so primitives + plain objects only) and
|
|
6
|
+
* returns any JSON-serializable value; it may also throw, in which case the
|
|
7
|
+
* sandbox's `await __bridgeCall(...)` rejects with the error's message.
|
|
8
|
+
*
|
|
9
|
+
* The handler runs in the **host process**, not the sandbox. It has full
|
|
10
|
+
* access to MJ's services, DB, and filesystem — so higher layers
|
|
11
|
+
* (RuntimeActionBridge in @memberjunction/action-runtime) are responsible
|
|
12
|
+
* for enforcing per-Runtime-action permission scopes before each call
|
|
13
|
+
* reaches this point.
|
|
14
|
+
*/
|
|
15
|
+
export type BridgeHandler = (args: unknown) => Promise<unknown> | unknown;
|
|
16
|
+
/**
|
|
17
|
+
* A name → handler map passed to `CodeExecutionService.execute()` for a
|
|
18
|
+
* single invocation. The sandbox can only call names that are present in
|
|
19
|
+
* this map; unknown names reject with a "handler not registered" error.
|
|
20
|
+
*/
|
|
21
|
+
export type BridgeHandlerMap = Record<string, BridgeHandler>;
|
|
22
|
+
/**
|
|
23
|
+
* Parameters for code execution.
|
|
24
|
+
*
|
|
25
|
+
* `bridgeHandlers` is the ONLY field that is NOT sent over IPC — functions
|
|
26
|
+
* can't be serialized across the process boundary. The host keeps the map
|
|
27
|
+
* alive for the duration of this execution and uses it to service
|
|
28
|
+
* `bridge-call` messages coming back from the worker.
|
|
3
29
|
*/
|
|
4
30
|
export interface CodeExecutionParams {
|
|
5
31
|
/**
|
|
@@ -23,6 +49,26 @@ export interface CodeExecutionParams {
|
|
|
23
49
|
* Note: Memory limiting requires Node.js flags, enforced at process level
|
|
24
50
|
*/
|
|
25
51
|
memoryLimitMB?: number;
|
|
52
|
+
/**
|
|
53
|
+
* Optional map of bridge handlers to expose to sandbox code as
|
|
54
|
+
* `__bridgeCall(name, args)`. When present, the sandbox can make async
|
|
55
|
+
* round-trips to the host for each registered name. Host-side only — not
|
|
56
|
+
* sent over IPC. See {@link BridgeHandler}.
|
|
57
|
+
*/
|
|
58
|
+
bridgeHandlers?: BridgeHandlerMap;
|
|
59
|
+
/**
|
|
60
|
+
* Optional cap on the number of bridge calls a single execution may
|
|
61
|
+
* make (default: 100). The (N+1)th call rejects with a BRIDGE_LIMIT
|
|
62
|
+
* error. Prevents runaway loops inside sandbox code.
|
|
63
|
+
*/
|
|
64
|
+
maxBridgeCalls?: number;
|
|
65
|
+
/**
|
|
66
|
+
* Optional AbortSignal for upstream cancellation. When aborted, any
|
|
67
|
+
* in-flight `await __bridgeCall(...)` inside the sandbox rejects and
|
|
68
|
+
* the sandbox script is left to wind down (we don't dispose the isolate
|
|
69
|
+
* mid-execution — see design notes in the plan).
|
|
70
|
+
*/
|
|
71
|
+
abortSignal?: AbortSignal;
|
|
26
72
|
}
|
|
27
73
|
/**
|
|
28
74
|
* Result of code execution
|
|
@@ -70,6 +116,65 @@ export interface JavaScriptExecutionOptions {
|
|
|
70
116
|
*/
|
|
71
117
|
allowedLibraries?: string[];
|
|
72
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* IPC message types for worker/host communication.
|
|
121
|
+
*
|
|
122
|
+
* Existing: `execute`, `result`, `error`, `ready`.
|
|
123
|
+
* NEW for the bridge: `bridge-call` (worker→host), `bridge-response`
|
|
124
|
+
* (host→worker), `abort` (host→worker).
|
|
125
|
+
*/
|
|
126
|
+
/** Host → Worker: run this code. */
|
|
127
|
+
export interface ExecuteIpcMessage {
|
|
128
|
+
type: 'execute';
|
|
129
|
+
requestId: string;
|
|
130
|
+
/** The IPC-safe subset of `CodeExecutionParams` (no `bridgeHandlers`). */
|
|
131
|
+
params: Omit<CodeExecutionParams, 'bridgeHandlers' | 'abortSignal'>;
|
|
132
|
+
}
|
|
133
|
+
/** Worker → Host: execution finished cleanly. */
|
|
134
|
+
export interface ResultIpcMessage {
|
|
135
|
+
type: 'result';
|
|
136
|
+
requestId: string;
|
|
137
|
+
result: CodeExecutionResult;
|
|
138
|
+
}
|
|
139
|
+
/** Worker → Host: execution threw before the handler could assemble a result. */
|
|
140
|
+
export interface ErrorIpcMessage {
|
|
141
|
+
type: 'error';
|
|
142
|
+
requestId: string;
|
|
143
|
+
error: string;
|
|
144
|
+
}
|
|
145
|
+
/** Worker → Host: sandbox code wants the host to service a bridge call. */
|
|
146
|
+
export interface BridgeCallIpcMessage {
|
|
147
|
+
type: 'bridge-call';
|
|
148
|
+
requestId: string;
|
|
149
|
+
/** Unique per call so Promise.all-style concurrency is correlated correctly. */
|
|
150
|
+
callId: string;
|
|
151
|
+
/** Name registered in the execution's `bridgeHandlers` map. */
|
|
152
|
+
functionName: string;
|
|
153
|
+
/** JSON-round-tripped args. */
|
|
154
|
+
args: unknown;
|
|
155
|
+
}
|
|
156
|
+
/** Host → Worker: result of a bridge call. One of `result` | `error` is populated. */
|
|
157
|
+
export interface BridgeResponseIpcMessage {
|
|
158
|
+
type: 'bridge-response';
|
|
159
|
+
requestId: string;
|
|
160
|
+
callId: string;
|
|
161
|
+
result?: unknown;
|
|
162
|
+
error?: string;
|
|
163
|
+
}
|
|
164
|
+
/** Host → Worker: abort in-flight bridge calls for this requestId. */
|
|
165
|
+
export interface AbortIpcMessage {
|
|
166
|
+
type: 'abort';
|
|
167
|
+
requestId: string;
|
|
168
|
+
reason: string;
|
|
169
|
+
}
|
|
170
|
+
/** Worker → Host: initial ready signal (no requestId). */
|
|
171
|
+
export interface ReadyIpcMessage {
|
|
172
|
+
type: 'ready';
|
|
173
|
+
}
|
|
174
|
+
/** Host → Worker message types. */
|
|
175
|
+
export type HostToWorkerMessage = ExecuteIpcMessage | BridgeResponseIpcMessage | AbortIpcMessage;
|
|
176
|
+
/** Worker → Host message types. */
|
|
177
|
+
export type WorkerToHostMessage = ResultIpcMessage | ErrorIpcMessage | BridgeCallIpcMessage | ReadyIpcMessage;
|
|
73
178
|
/**
|
|
74
179
|
* Sandbox context provided to executed code
|
|
75
180
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,aAAa,GAAG,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ACzB,gBAAgB,GAChB,eAAe,GACf,oBAAoB,GACpB,eAAe,CAAC;AAEtB;;GAEG;AACH,MAAM,WAAW,cAAc;IAC3B;;OAEG;IACH,KAAK,EAAE,GAAG,CAAC;IAEX;;OAEG;IACH,MAAM,EAAE,GAAG,CAAC;IAEZ;;OAEG;IACH,OAAO,EAAE;QACL,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;QAC9B,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;QAChC,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;QAC/B,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;KAClC,CAAC;CACL"}
|
package/dist/worker.d.ts
CHANGED
|
@@ -17,6 +17,28 @@
|
|
|
17
17
|
* 2. V8 isolate (isolated-vm) - protects against sandbox escapes
|
|
18
18
|
* 3. Module blocking - prevents dangerous Node.js API access
|
|
19
19
|
* 4. Resource limits - prevents DoS via timeout/memory exhaustion
|
|
20
|
+
*
|
|
21
|
+
* ==============================================================================
|
|
22
|
+
* Bidirectional Bridge (Phase 1d)
|
|
23
|
+
* ==============================================================================
|
|
24
|
+
* Sandbox code can call `__bridgeCall(name, args)` to invoke a host-registered
|
|
25
|
+
* handler and await its result. The flow:
|
|
26
|
+
*
|
|
27
|
+
* 1. Sandbox calls `__bridgeCall('rv.RunView', { EntityName: '...' })`
|
|
28
|
+
* 2. That dispatches to the host-side `_bridgeCall` ivm.Reference via
|
|
29
|
+
* `applyAsync`. The reference's JS body sends a `bridge-call` IPC
|
|
30
|
+
* message to the parent process and waits for the matching
|
|
31
|
+
* `bridge-response`.
|
|
32
|
+
* 3. Parent process routes the request to the registered handler,
|
|
33
|
+
* executes it, and sends `bridge-response` back.
|
|
34
|
+
* 4. The worker's `process.on('message')` handler resolves the pending
|
|
35
|
+
* promise for that callId.
|
|
36
|
+
* 5. `applyAsync` resolves inside the isolate with the JSON-stringified
|
|
37
|
+
* result. Sandbox code parses it and sees a plain object.
|
|
38
|
+
*
|
|
39
|
+
* The bridge is scoped per-requestId: each `execute` message opens a new
|
|
40
|
+
* pending-calls map that is either drained on completion or rejected en
|
|
41
|
+
* masse on `abort`. Nothing persists between executions.
|
|
20
42
|
*/
|
|
21
43
|
export {};
|
|
22
44
|
//# sourceMappingURL=worker.d.ts.map
|
package/dist/worker.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG"}
|
package/dist/worker.js
CHANGED
|
@@ -17,9 +17,35 @@
|
|
|
17
17
|
* 2. V8 isolate (isolated-vm) - protects against sandbox escapes
|
|
18
18
|
* 3. Module blocking - prevents dangerous Node.js API access
|
|
19
19
|
* 4. Resource limits - prevents DoS via timeout/memory exhaustion
|
|
20
|
+
*
|
|
21
|
+
* ==============================================================================
|
|
22
|
+
* Bidirectional Bridge (Phase 1d)
|
|
23
|
+
* ==============================================================================
|
|
24
|
+
* Sandbox code can call `__bridgeCall(name, args)` to invoke a host-registered
|
|
25
|
+
* handler and await its result. The flow:
|
|
26
|
+
*
|
|
27
|
+
* 1. Sandbox calls `__bridgeCall('rv.RunView', { EntityName: '...' })`
|
|
28
|
+
* 2. That dispatches to the host-side `_bridgeCall` ivm.Reference via
|
|
29
|
+
* `applyAsync`. The reference's JS body sends a `bridge-call` IPC
|
|
30
|
+
* message to the parent process and waits for the matching
|
|
31
|
+
* `bridge-response`.
|
|
32
|
+
* 3. Parent process routes the request to the registered handler,
|
|
33
|
+
* executes it, and sends `bridge-response` back.
|
|
34
|
+
* 4. The worker's `process.on('message')` handler resolves the pending
|
|
35
|
+
* promise for that callId.
|
|
36
|
+
* 5. `applyAsync` resolves inside the isolate with the JSON-stringified
|
|
37
|
+
* result. Sandbox code parses it and sees a plain object.
|
|
38
|
+
*
|
|
39
|
+
* The bridge is scoped per-requestId: each `execute` message opens a new
|
|
40
|
+
* pending-calls map that is either drained on completion or rejected en
|
|
41
|
+
* masse on `abort`. Nothing persists between executions.
|
|
20
42
|
*/
|
|
21
43
|
import ivm from 'isolated-vm';
|
|
22
44
|
import { getLibrarySource, isModuleAllowed, getAllowedModuleNames } from './libraries/index.js';
|
|
45
|
+
const bridgeStates = new Map();
|
|
46
|
+
function getBridgeState(requestId) {
|
|
47
|
+
return bridgeStates.get(requestId);
|
|
48
|
+
}
|
|
23
49
|
/**
|
|
24
50
|
* Execute JavaScript code in an isolated-vm isolate
|
|
25
51
|
*
|
|
@@ -28,10 +54,20 @@ import { getLibrarySource, isModuleAllowed, getAllowedModuleNames } from './libr
|
|
|
28
54
|
* - Module loading is strictly controlled via allowlist
|
|
29
55
|
* - Input/output data is properly serialized (no object references leak)
|
|
30
56
|
*/
|
|
31
|
-
async function executeInIsolate(params) {
|
|
57
|
+
async function executeInIsolate(params, requestId) {
|
|
32
58
|
const startTime = Date.now();
|
|
33
59
|
const timeoutMs = (params.timeoutSeconds || 30) * 1000;
|
|
34
60
|
const memoryLimitMB = params.memoryLimitMB || 128;
|
|
61
|
+
const maxBridgeCalls = params.maxBridgeCalls ?? 100;
|
|
62
|
+
// Open the bridge state for this execution before the isolate starts so
|
|
63
|
+
// any bridge-response / abort messages that race in are delivered to a
|
|
64
|
+
// real slot rather than dropped.
|
|
65
|
+
bridgeStates.set(requestId, {
|
|
66
|
+
pending: new Map(),
|
|
67
|
+
callCount: 0,
|
|
68
|
+
maxCalls: maxBridgeCalls,
|
|
69
|
+
aborted: false
|
|
70
|
+
});
|
|
35
71
|
let isolate = null;
|
|
36
72
|
let context = null;
|
|
37
73
|
try {
|
|
@@ -88,6 +124,99 @@ async function executeInIsolate(params) {
|
|
|
88
124
|
throw new Error('Security Error: Network access via fetch() is not allowed in sandboxed code');
|
|
89
125
|
};
|
|
90
126
|
`);
|
|
127
|
+
// ===================================================================
|
|
128
|
+
// BRIDGE SETUP
|
|
129
|
+
//
|
|
130
|
+
// Inject a single host-backed async function as `_bridgeCall`. The
|
|
131
|
+
// reference's body sends an IPC message to the parent and awaits the
|
|
132
|
+
// matching `bridge-response` via the `bridgeStates` map above. The
|
|
133
|
+
// isolate wraps it as `globalThis.__bridgeCall(name, args)` which
|
|
134
|
+
// returns a Promise resolving to the parsed JSON result (or rejects
|
|
135
|
+
// with the host error message).
|
|
136
|
+
//
|
|
137
|
+
// Args + result cross the boundary as JSON strings so complex object
|
|
138
|
+
// shapes, Dates, etc. behave consistently and no ivm.Reference ever
|
|
139
|
+
// leaks back into user code.
|
|
140
|
+
// ===================================================================
|
|
141
|
+
// The bridge callback NEVER throws — errors are encoded as a JSON
|
|
142
|
+
// envelope `{ __bridgeError: '...' }` and re-thrown inside the
|
|
143
|
+
// isolate. This avoids firing unhandled-rejection in the worker
|
|
144
|
+
// process when the caller exceeds maxBridgeCalls or the host handler
|
|
145
|
+
// throws; isolated-vm would propagate the rejection across the
|
|
146
|
+
// boundary, but Node 24+'s strict unhandled-rejection semantics can
|
|
147
|
+
// fire a process.unhandledRejection handler before isolated-vm's
|
|
148
|
+
// delivery settles, killing the worker.
|
|
149
|
+
const bridgeCall = new ivm.Reference(async (callId, functionName, argsJson) => {
|
|
150
|
+
try {
|
|
151
|
+
const state = getBridgeState(requestId);
|
|
152
|
+
if (!state) {
|
|
153
|
+
throw new Error('Bridge state missing for this execution');
|
|
154
|
+
}
|
|
155
|
+
if (state.aborted) {
|
|
156
|
+
throw new Error(state.abortReason ?? 'Execution aborted');
|
|
157
|
+
}
|
|
158
|
+
if (state.callCount >= state.maxCalls) {
|
|
159
|
+
throw new Error(`Bridge call limit exceeded (maxBridgeCalls=${state.maxCalls}). ` +
|
|
160
|
+
'Runtime action tried to make too many host round-trips.');
|
|
161
|
+
}
|
|
162
|
+
state.callCount++;
|
|
163
|
+
let args;
|
|
164
|
+
try {
|
|
165
|
+
args = JSON.parse(argsJson);
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
throw new Error('Bridge call args must be JSON-serializable');
|
|
169
|
+
}
|
|
170
|
+
const resultPromise = new Promise((resolve, reject) => {
|
|
171
|
+
state.pending.set(callId, { resolve, reject });
|
|
172
|
+
});
|
|
173
|
+
const callMessage = {
|
|
174
|
+
type: 'bridge-call',
|
|
175
|
+
requestId,
|
|
176
|
+
callId,
|
|
177
|
+
functionName,
|
|
178
|
+
args
|
|
179
|
+
};
|
|
180
|
+
// SECURITY: IPC is JSON-serialized by Node's child-process
|
|
181
|
+
// plumbing; no references leak.
|
|
182
|
+
process.send(callMessage);
|
|
183
|
+
const hostResult = await resultPromise;
|
|
184
|
+
// Return as a JSON string so the isolate receives a primitive
|
|
185
|
+
// it can safely JSON.parse — no copyInto / ExternalCopy needed.
|
|
186
|
+
return JSON.stringify({ ok: hostResult === undefined ? null : hostResult });
|
|
187
|
+
}
|
|
188
|
+
catch (err) {
|
|
189
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
190
|
+
return JSON.stringify({ __bridgeError: message });
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
await jail.set('_bridgeCall', bridgeCall);
|
|
194
|
+
// Counter inside the isolate for unique callIds — we use a monotonic
|
|
195
|
+
// counter instead of Math.random() so the sequence is deterministic
|
|
196
|
+
// for debugging and tests.
|
|
197
|
+
await context.eval(`
|
|
198
|
+
globalThis.__bridgeCallSeq = 0;
|
|
199
|
+
globalThis.__bridgeCall = async function(functionName, args) {
|
|
200
|
+
const callId = 'bc-' + (++globalThis.__bridgeCallSeq);
|
|
201
|
+
const argsJson = JSON.stringify(args ?? null);
|
|
202
|
+
// Reference.apply returns a Promise when called from inside
|
|
203
|
+
// an isolate. { result: { promise: true } } tells isolated-vm
|
|
204
|
+
// that the host callback returns a Promise it should await
|
|
205
|
+
// before resolving. The result is a primitive string, which
|
|
206
|
+
// transfers cleanly without needing ExternalCopy.
|
|
207
|
+
const envelope = await _bridgeCall.apply(
|
|
208
|
+
undefined,
|
|
209
|
+
[callId, functionName, argsJson],
|
|
210
|
+
{ result: { promise: true } }
|
|
211
|
+
);
|
|
212
|
+
const parsed = envelope ? JSON.parse(envelope) : null;
|
|
213
|
+
if (parsed && parsed.__bridgeError) {
|
|
214
|
+
throw new Error(parsed.__bridgeError);
|
|
215
|
+
}
|
|
216
|
+
// Envelope is always { ok: value } on success.
|
|
217
|
+
return parsed ? parsed.ok : null;
|
|
218
|
+
};
|
|
219
|
+
`);
|
|
91
220
|
// Set up module cache for require()
|
|
92
221
|
await jail.set('_moduleCache', new ivm.Reference({}));
|
|
93
222
|
// SECURITY: Create require() function with strict module allowlisting
|
|
@@ -141,8 +270,14 @@ async function executeInIsolate(params) {
|
|
|
141
270
|
// We store output in globalThis._output because script.run() doesn't reliably
|
|
142
271
|
// return the IIFE's return value - we need to extract it from the context
|
|
143
272
|
await jail.set('_output', undefined);
|
|
273
|
+
// Now that the bridge can be awaited, user code may be async. Wrap in
|
|
274
|
+
// an async IIFE that exposes its return value via globalThis._output.
|
|
275
|
+
// The script.run() call below awaits the script completion (the IIFE
|
|
276
|
+
// itself returns a Promise, and with `promise: true` script.run
|
|
277
|
+
// awaits it). Back-compat: code that does NOT use await still works
|
|
278
|
+
// because the wrapper is an async function.
|
|
144
279
|
const wrappedCode = `
|
|
145
|
-
(function() {
|
|
280
|
+
(async function() {
|
|
146
281
|
let output;
|
|
147
282
|
${params.code}
|
|
148
283
|
globalThis._output = output;
|
|
@@ -152,7 +287,9 @@ async function executeInIsolate(params) {
|
|
|
152
287
|
// CVE-2022-39266: Never use cachedData from untrusted sources
|
|
153
288
|
// We do NOT pass any cachedData parameter here - only compile from source
|
|
154
289
|
const script = await isolate.compileScript(wrappedCode);
|
|
155
|
-
|
|
290
|
+
// `promise: true` ensures script.run awaits the IIFE's returned Promise
|
|
291
|
+
// so await __bridgeCall(...) inside user code works end-to-end.
|
|
292
|
+
await script.run(context, { timeout: timeoutMs, promise: true });
|
|
156
293
|
// SECURITY: Extract output value - use .copySync() to get plain data, not References
|
|
157
294
|
// This ensures no ivm objects leak back to caller
|
|
158
295
|
const outputRef = await jail.get('_output');
|
|
@@ -195,6 +332,15 @@ async function executeInIsolate(params) {
|
|
|
195
332
|
};
|
|
196
333
|
}
|
|
197
334
|
finally {
|
|
335
|
+
// Clean up bridge state — reject any promises that didn't resolve
|
|
336
|
+
// naturally (e.g. execution threw before a bridge call returned).
|
|
337
|
+
const state = bridgeStates.get(requestId);
|
|
338
|
+
if (state) {
|
|
339
|
+
for (const [, entry] of state.pending) {
|
|
340
|
+
entry.reject(new Error('Execution ended with pending bridge call'));
|
|
341
|
+
}
|
|
342
|
+
bridgeStates.delete(requestId);
|
|
343
|
+
}
|
|
198
344
|
// Clean up resources
|
|
199
345
|
if (context) {
|
|
200
346
|
context.release();
|
|
@@ -230,7 +376,7 @@ function formatConsoleArg(arg) {
|
|
|
230
376
|
process.on('message', async (message) => {
|
|
231
377
|
if (message.type === 'execute') {
|
|
232
378
|
try {
|
|
233
|
-
const result = await executeInIsolate(message.params);
|
|
379
|
+
const result = await executeInIsolate(message.params, message.requestId);
|
|
234
380
|
const response = {
|
|
235
381
|
type: 'result',
|
|
236
382
|
requestId: message.requestId,
|
|
@@ -247,8 +393,52 @@ process.on('message', async (message) => {
|
|
|
247
393
|
};
|
|
248
394
|
process.send(response);
|
|
249
395
|
}
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
if (message.type === 'bridge-response') {
|
|
399
|
+
const state = bridgeStates.get(message.requestId);
|
|
400
|
+
if (!state) {
|
|
401
|
+
// Stale response — execution already ended. Drop silently.
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
const entry = state.pending.get(message.callId);
|
|
405
|
+
if (!entry) {
|
|
406
|
+
// Unknown callId — either it was already aborted or we've got a
|
|
407
|
+
// bug. Drop silently; the server-side WorkerPool would re-issue
|
|
408
|
+
// if it still cared.
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
state.pending.delete(message.callId);
|
|
412
|
+
if (message.error) {
|
|
413
|
+
entry.reject(new Error(message.error));
|
|
414
|
+
}
|
|
415
|
+
else {
|
|
416
|
+
entry.resolve(message.result);
|
|
417
|
+
}
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
if (message.type === 'abort') {
|
|
421
|
+
const state = bridgeStates.get(message.requestId);
|
|
422
|
+
if (!state) {
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
state.aborted = true;
|
|
426
|
+
state.abortReason = message.reason;
|
|
427
|
+
const pending = Array.from(state.pending.entries());
|
|
428
|
+
state.pending.clear();
|
|
429
|
+
for (const [, entry] of pending) {
|
|
430
|
+
entry.reject(new Error(message.reason || 'Execution aborted'));
|
|
431
|
+
}
|
|
432
|
+
// Note: we do NOT dispose the isolate from here. isolated-vm's
|
|
433
|
+
// `script.run(..., { timeout })` will still terminate the script
|
|
434
|
+
// when its own deadline fires, and rejecting the pending bridge
|
|
435
|
+
// calls is enough for cooperative user code to unwind.
|
|
436
|
+
return;
|
|
250
437
|
}
|
|
251
438
|
});
|
|
439
|
+
// Export nothing — this file is only executed as a child process entrypoint.
|
|
440
|
+
// The ParentOutboundMessage type is exported via the types module instead.
|
|
441
|
+
void {};
|
|
252
442
|
// Signal that worker is ready to accept work
|
|
253
443
|
process.send({ type: 'ready' });
|
|
254
444
|
//# sourceMappingURL=worker.js.map
|
package/dist/worker.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;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,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/code-execution",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "5.
|
|
4
|
+
"version": "5.30.0",
|
|
5
5
|
"description": "Sandboxed code execution service for MemberJunction actions and agents",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"scripts": {
|
|
9
|
-
"build": "tsc && tsc-alias -f",
|
|
9
|
+
"build": "tsc && tsc-alias -f && npm run copy:bundled-libs",
|
|
10
|
+
"copy:bundled-libs": "node -e \"const fs=require('fs'),p=require('path');const src=p.join('src','libraries','bundled-libs');const dst=p.join('dist','libraries','bundled-libs');fs.mkdirSync(dst,{recursive:true});for(const f of fs.readdirSync(src))fs.copyFileSync(p.join(src,f),p.join(dst,f));\"",
|
|
10
11
|
"watch": "tsc --watch",
|
|
11
12
|
"test": "vitest run",
|
|
12
13
|
"test:watch": "vitest"
|
|
13
14
|
},
|
|
14
15
|
"dependencies": {
|
|
15
|
-
"@memberjunction/core": "5.
|
|
16
|
-
"@memberjunction/global": "5.
|
|
16
|
+
"@memberjunction/core": "5.30.0",
|
|
17
|
+
"@memberjunction/global": "5.30.0",
|
|
17
18
|
"isolated-vm": "^6.0.2",
|
|
18
19
|
"lodash": "^4.17.23",
|
|
19
20
|
"date-fns": "^3.0.0",
|