just-bash 2.9.2 → 2.9.4
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/dist/bin/chunks/{chunk-2ODUA7YH.js → chunk-B3E7BBYK.js} +36 -36
- package/dist/bin/chunks/chunk-HSNUCOOQ.js +6 -0
- package/dist/bin/chunks/chunk-UYBH3FNE.js +2 -0
- package/dist/bin/{shell/chunks/curl-7IUASLUJ.js → chunks/curl-RWQO3SBN.js} +18 -18
- package/dist/bin/{shell/chunks/expansion-QOAPT4NU.js → chunks/expansion-LR5H7O2U.js} +1 -1
- package/dist/bin/chunks/{jq-BMOLDA72.js → jq-EIPK4SZA.js} +1 -1
- package/dist/bin/chunks/worker.js +902 -2
- package/dist/bin/chunks/{xan-EAK3S7KJ.js → xan-QLNZCWIG.js} +35 -35
- package/dist/bin/chunks/{yq-WYJ3A4JF.js → yq-XD7UYY5C.js} +1 -1
- package/dist/bin/just-bash.js +138 -138
- package/dist/bin/shell/chunks/{chunk-2ODUA7YH.js → chunk-B3E7BBYK.js} +36 -36
- package/dist/bin/shell/chunks/chunk-HSNUCOOQ.js +6 -0
- package/dist/bin/shell/chunks/chunk-UYBH3FNE.js +2 -0
- package/dist/bin/{chunks/curl-7IUASLUJ.js → shell/chunks/curl-RWQO3SBN.js} +18 -18
- package/dist/bin/{chunks/expansion-QOAPT4NU.js → shell/chunks/expansion-LR5H7O2U.js} +1 -1
- package/dist/bin/shell/chunks/{jq-BMOLDA72.js → jq-EIPK4SZA.js} +1 -1
- package/dist/bin/shell/chunks/{xan-EAK3S7KJ.js → xan-QLNZCWIG.js} +35 -35
- package/dist/bin/shell/chunks/{yq-WYJ3A4JF.js → yq-XD7UYY5C.js} +1 -1
- package/dist/bin/shell/shell.js +144 -144
- package/dist/bundle/browser.js +491 -491
- package/dist/bundle/chunks/chunk-7MKBHGLS.js +1 -0
- package/dist/bundle/chunks/{chunk-2AON5K3E.js → chunk-RERCNF7Z.js} +36 -36
- package/dist/bundle/chunks/chunk-WQCJYUEW.js +5 -0
- package/dist/bundle/chunks/{curl-QDCXHQMX.js → curl-6L7YZUIH.js} +18 -18
- package/dist/bundle/chunks/{expansion-7IMG6HKQ.js → expansion-OFFC2R4K.js} +1 -1
- package/dist/bundle/chunks/{jq-GMMYKAEP.js → jq-6U2TPE6U.js} +1 -1
- package/dist/bundle/chunks/worker.js +902 -2
- package/dist/bundle/chunks/{xan-DYADHWWG.js → xan-EN6JZQ3T.js} +35 -35
- package/dist/bundle/chunks/{yq-5WHXPM6R.js → yq-JD6M7T5A.js} +1 -1
- package/dist/bundle/index.js +227 -227
- package/dist/commands/python3/worker.d.ts +6 -0
- package/dist/commands/query-engine/safe-object.d.ts +10 -0
- package/dist/commands/query-engine/value-operations.d.ts +1 -0
- package/dist/commands/sqlite3/worker.d.ts +10 -0
- package/dist/fs/read-write-fs/read-write-fs.d.ts +4 -1
- package/dist/parser/parser.d.ts +6 -0
- package/dist/parser/types.d.ts +1 -0
- package/package.json +4 -4
- package/dist/bin/chunks/chunk-FJTZ5HFK.js +0 -6
- package/dist/bin/shell/chunks/chunk-FJTZ5HFK.js +0 -6
- package/dist/bundle/chunks/chunk-IHEPHGKB.js +0 -5
|
@@ -1,7 +1,873 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
+
});
|
|
7
|
+
|
|
1
8
|
// src/commands/python3/worker.ts
|
|
2
9
|
import { parentPort, workerData } from "node:worker_threads";
|
|
3
10
|
import { loadPyodide } from "pyodide";
|
|
4
11
|
|
|
12
|
+
// src/security/blocked-globals.ts
|
|
13
|
+
function getBlockedGlobals() {
|
|
14
|
+
const globals = [
|
|
15
|
+
// Direct code execution vectors
|
|
16
|
+
{
|
|
17
|
+
prop: "Function",
|
|
18
|
+
target: globalThis,
|
|
19
|
+
violationType: "function_constructor",
|
|
20
|
+
strategy: "throw",
|
|
21
|
+
reason: "Function constructor allows arbitrary code execution"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
prop: "eval",
|
|
25
|
+
target: globalThis,
|
|
26
|
+
violationType: "eval",
|
|
27
|
+
strategy: "throw",
|
|
28
|
+
reason: "eval() allows arbitrary code execution"
|
|
29
|
+
},
|
|
30
|
+
// Timer functions with string argument allow code execution
|
|
31
|
+
{
|
|
32
|
+
prop: "setTimeout",
|
|
33
|
+
target: globalThis,
|
|
34
|
+
violationType: "setTimeout",
|
|
35
|
+
strategy: "throw",
|
|
36
|
+
reason: "setTimeout with string argument allows code execution"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
prop: "setInterval",
|
|
40
|
+
target: globalThis,
|
|
41
|
+
violationType: "setInterval",
|
|
42
|
+
strategy: "throw",
|
|
43
|
+
reason: "setInterval with string argument allows code execution"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
prop: "setImmediate",
|
|
47
|
+
target: globalThis,
|
|
48
|
+
violationType: "setImmediate",
|
|
49
|
+
strategy: "throw",
|
|
50
|
+
reason: "setImmediate could be used to escape sandbox context"
|
|
51
|
+
},
|
|
52
|
+
// Note: We intentionally do NOT block `process` entirely because:
|
|
53
|
+
// 1. Node.js internals (Promise resolution, etc.) use process.nextTick
|
|
54
|
+
// 2. Blocking process entirely breaks normal async operation
|
|
55
|
+
// 3. The primary code execution vectors (Function, eval) are already blocked
|
|
56
|
+
// However, we DO block specific dangerous process properties.
|
|
57
|
+
{
|
|
58
|
+
prop: "env",
|
|
59
|
+
target: process,
|
|
60
|
+
violationType: "process_env",
|
|
61
|
+
strategy: "throw",
|
|
62
|
+
reason: "process.env could leak sensitive environment variables"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
prop: "binding",
|
|
66
|
+
target: process,
|
|
67
|
+
violationType: "process_binding",
|
|
68
|
+
strategy: "throw",
|
|
69
|
+
reason: "process.binding provides access to native Node.js modules"
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
prop: "_linkedBinding",
|
|
73
|
+
target: process,
|
|
74
|
+
violationType: "process_binding",
|
|
75
|
+
strategy: "throw",
|
|
76
|
+
reason: "process._linkedBinding provides access to native Node.js modules"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
prop: "dlopen",
|
|
80
|
+
target: process,
|
|
81
|
+
violationType: "process_dlopen",
|
|
82
|
+
strategy: "throw",
|
|
83
|
+
reason: "process.dlopen allows loading native addons"
|
|
84
|
+
},
|
|
85
|
+
// Note: process.mainModule is handled specially in defense-in-depth-box.ts
|
|
86
|
+
// and worker-defense-in-depth.ts because it may be undefined in ESM contexts
|
|
87
|
+
// but we still want to block both reading and setting it.
|
|
88
|
+
// We also don't block `require` because:
|
|
89
|
+
// 1. It may not exist in all environments (ESM)
|
|
90
|
+
// 2. import() is the modern escape vector and can't be blocked this way
|
|
91
|
+
// Reference leak vectors
|
|
92
|
+
{
|
|
93
|
+
prop: "WeakRef",
|
|
94
|
+
target: globalThis,
|
|
95
|
+
violationType: "weak_ref",
|
|
96
|
+
strategy: "throw",
|
|
97
|
+
reason: "WeakRef could be used to leak references outside sandbox"
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
prop: "FinalizationRegistry",
|
|
101
|
+
target: globalThis,
|
|
102
|
+
violationType: "finalization_registry",
|
|
103
|
+
strategy: "throw",
|
|
104
|
+
reason: "FinalizationRegistry could be used to leak references outside sandbox"
|
|
105
|
+
},
|
|
106
|
+
// Introspection/interception vectors (freeze instead of throw)
|
|
107
|
+
{
|
|
108
|
+
prop: "Reflect",
|
|
109
|
+
target: globalThis,
|
|
110
|
+
violationType: "reflect",
|
|
111
|
+
strategy: "freeze",
|
|
112
|
+
reason: "Reflect provides introspection capabilities"
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
prop: "Proxy",
|
|
116
|
+
target: globalThis,
|
|
117
|
+
violationType: "proxy",
|
|
118
|
+
strategy: "throw",
|
|
119
|
+
reason: "Proxy allows intercepting and modifying object behavior"
|
|
120
|
+
},
|
|
121
|
+
// WebAssembly allows arbitrary code execution
|
|
122
|
+
{
|
|
123
|
+
prop: "WebAssembly",
|
|
124
|
+
target: globalThis,
|
|
125
|
+
violationType: "webassembly",
|
|
126
|
+
strategy: "throw",
|
|
127
|
+
reason: "WebAssembly allows executing arbitrary compiled code"
|
|
128
|
+
},
|
|
129
|
+
// SharedArrayBuffer and Atomics can enable side-channel attacks
|
|
130
|
+
{
|
|
131
|
+
prop: "SharedArrayBuffer",
|
|
132
|
+
target: globalThis,
|
|
133
|
+
violationType: "shared_array_buffer",
|
|
134
|
+
strategy: "throw",
|
|
135
|
+
reason: "SharedArrayBuffer could enable side-channel communication or timing attacks"
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
prop: "Atomics",
|
|
139
|
+
target: globalThis,
|
|
140
|
+
violationType: "atomics",
|
|
141
|
+
strategy: "throw",
|
|
142
|
+
reason: "Atomics could enable side-channel communication or timing attacks"
|
|
143
|
+
}
|
|
144
|
+
// Note: Error.prepareStackTrace is handled specially in defense-in-depth-box.ts
|
|
145
|
+
// because we only want to block SETTING it, not reading (V8 reads it internally)
|
|
146
|
+
];
|
|
147
|
+
try {
|
|
148
|
+
const AsyncFunction = Object.getPrototypeOf(async () => {
|
|
149
|
+
}).constructor;
|
|
150
|
+
if (AsyncFunction && AsyncFunction !== Function) {
|
|
151
|
+
globals.push({
|
|
152
|
+
prop: "constructor",
|
|
153
|
+
target: Object.getPrototypeOf(async () => {
|
|
154
|
+
}),
|
|
155
|
+
violationType: "async_function_constructor",
|
|
156
|
+
strategy: "throw",
|
|
157
|
+
reason: "AsyncFunction constructor allows arbitrary async code execution"
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
} catch {
|
|
161
|
+
}
|
|
162
|
+
try {
|
|
163
|
+
const GeneratorFunction = Object.getPrototypeOf(
|
|
164
|
+
function* () {
|
|
165
|
+
}
|
|
166
|
+
).constructor;
|
|
167
|
+
if (GeneratorFunction && GeneratorFunction !== Function) {
|
|
168
|
+
globals.push({
|
|
169
|
+
prop: "constructor",
|
|
170
|
+
target: Object.getPrototypeOf(function* () {
|
|
171
|
+
}),
|
|
172
|
+
violationType: "generator_function_constructor",
|
|
173
|
+
strategy: "throw",
|
|
174
|
+
reason: "GeneratorFunction constructor allows arbitrary generator code execution"
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
} catch {
|
|
178
|
+
}
|
|
179
|
+
try {
|
|
180
|
+
const AsyncGeneratorFunction = Object.getPrototypeOf(
|
|
181
|
+
async function* () {
|
|
182
|
+
}
|
|
183
|
+
).constructor;
|
|
184
|
+
if (AsyncGeneratorFunction && AsyncGeneratorFunction !== Function && AsyncGeneratorFunction !== Object.getPrototypeOf(async () => {
|
|
185
|
+
}).constructor) {
|
|
186
|
+
globals.push({
|
|
187
|
+
prop: "constructor",
|
|
188
|
+
target: Object.getPrototypeOf(async function* () {
|
|
189
|
+
}),
|
|
190
|
+
violationType: "async_generator_function_constructor",
|
|
191
|
+
strategy: "throw",
|
|
192
|
+
reason: "AsyncGeneratorFunction constructor allows arbitrary async generator code execution"
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
} catch {
|
|
196
|
+
}
|
|
197
|
+
return globals.filter((g) => {
|
|
198
|
+
try {
|
|
199
|
+
return g.target[g.prop] !== void 0;
|
|
200
|
+
} catch {
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// src/security/defense-in-depth-box.ts
|
|
207
|
+
var IS_BROWSER = typeof __BROWSER__ !== "undefined" && __BROWSER__;
|
|
208
|
+
var AsyncLocalStorageClass = null;
|
|
209
|
+
if (!IS_BROWSER) {
|
|
210
|
+
try {
|
|
211
|
+
const { createRequire } = await import("node:module");
|
|
212
|
+
const require2 = createRequire(import.meta.url);
|
|
213
|
+
const asyncHooks = require2("node:async_hooks");
|
|
214
|
+
AsyncLocalStorageClass = asyncHooks.AsyncLocalStorage;
|
|
215
|
+
} catch (e) {
|
|
216
|
+
console.debug(
|
|
217
|
+
"[DefenseInDepthBox] AsyncLocalStorage not available, defense-in-depth disabled:",
|
|
218
|
+
e instanceof Error ? e.message : e
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
var executionContext = !IS_BROWSER && AsyncLocalStorageClass ? new AsyncLocalStorageClass() : null;
|
|
223
|
+
|
|
224
|
+
// src/security/worker-defense-in-depth.ts
|
|
225
|
+
var DEFENSE_IN_DEPTH_NOTICE = "\n\nThis is a defense-in-depth measure and indicates a bug in just-bash. Please report this at security@vercel.com";
|
|
226
|
+
var WorkerSecurityViolationError = class extends Error {
|
|
227
|
+
constructor(message, violation) {
|
|
228
|
+
super(message + DEFENSE_IN_DEPTH_NOTICE);
|
|
229
|
+
this.violation = violation;
|
|
230
|
+
this.name = "WorkerSecurityViolationError";
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
var MAX_STORED_VIOLATIONS = 1e3;
|
|
234
|
+
function generateExecutionId() {
|
|
235
|
+
if (typeof crypto !== "undefined" && crypto.randomUUID) {
|
|
236
|
+
return crypto.randomUUID();
|
|
237
|
+
}
|
|
238
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
239
|
+
const r = Math.random() * 16 | 0;
|
|
240
|
+
const v = c === "x" ? r : r & 3 | 8;
|
|
241
|
+
return v.toString(16);
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
var WorkerDefenseInDepth = class {
|
|
245
|
+
config;
|
|
246
|
+
isActivated = false;
|
|
247
|
+
originalDescriptors = [];
|
|
248
|
+
violations = [];
|
|
249
|
+
executionId;
|
|
250
|
+
/**
|
|
251
|
+
* Original Proxy constructor, captured before patching.
|
|
252
|
+
* This is captured at instance creation time to ensure we get the unpatched version.
|
|
253
|
+
*/
|
|
254
|
+
originalProxy;
|
|
255
|
+
/**
|
|
256
|
+
* Recursion guard to prevent infinite loops when proxy traps trigger
|
|
257
|
+
* code that accesses the same proxied object (e.g., process.env).
|
|
258
|
+
*/
|
|
259
|
+
inTrap = false;
|
|
260
|
+
/**
|
|
261
|
+
* Create and activate the worker defense layer.
|
|
262
|
+
*
|
|
263
|
+
* @param config - Configuration for the defense layer
|
|
264
|
+
*/
|
|
265
|
+
constructor(config) {
|
|
266
|
+
this.originalProxy = Proxy;
|
|
267
|
+
this.config = config;
|
|
268
|
+
this.executionId = generateExecutionId();
|
|
269
|
+
if (config.enabled !== false) {
|
|
270
|
+
this.activate();
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Get statistics about the defense layer.
|
|
275
|
+
*/
|
|
276
|
+
getStats() {
|
|
277
|
+
return {
|
|
278
|
+
violationsBlocked: this.violations.length,
|
|
279
|
+
violations: [...this.violations],
|
|
280
|
+
isActive: this.isActivated
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Clear stored violations. Useful for testing.
|
|
285
|
+
*/
|
|
286
|
+
clearViolations() {
|
|
287
|
+
this.violations = [];
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Get the execution ID for this worker.
|
|
291
|
+
*/
|
|
292
|
+
getExecutionId() {
|
|
293
|
+
return this.executionId;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Deactivate the defense layer and restore original globals.
|
|
297
|
+
* Typically only needed for testing.
|
|
298
|
+
*/
|
|
299
|
+
deactivate() {
|
|
300
|
+
if (!this.isActivated) {
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
this.restorePatches();
|
|
304
|
+
this.isActivated = false;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Activate the defense layer by applying patches.
|
|
308
|
+
*/
|
|
309
|
+
activate() {
|
|
310
|
+
if (this.isActivated) {
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
this.applyPatches();
|
|
314
|
+
this.isActivated = true;
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Get a human-readable path for a target object and property.
|
|
318
|
+
*/
|
|
319
|
+
getPathForTarget(target, prop) {
|
|
320
|
+
if (target === globalThis) {
|
|
321
|
+
return `globalThis.${prop}`;
|
|
322
|
+
}
|
|
323
|
+
if (typeof process !== "undefined" && target === process) {
|
|
324
|
+
return `process.${prop}`;
|
|
325
|
+
}
|
|
326
|
+
if (target === Error) {
|
|
327
|
+
return `Error.${prop}`;
|
|
328
|
+
}
|
|
329
|
+
if (target === Function.prototype) {
|
|
330
|
+
return `Function.prototype.${prop}`;
|
|
331
|
+
}
|
|
332
|
+
if (target === Object.prototype) {
|
|
333
|
+
return `Object.prototype.${prop}`;
|
|
334
|
+
}
|
|
335
|
+
return `<object>.${prop}`;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Record a violation and invoke the callback.
|
|
339
|
+
* In worker context, blocking always happens (no audit mode context check).
|
|
340
|
+
*/
|
|
341
|
+
recordViolation(type, path, message) {
|
|
342
|
+
const violation = {
|
|
343
|
+
timestamp: Date.now(),
|
|
344
|
+
type,
|
|
345
|
+
message,
|
|
346
|
+
path,
|
|
347
|
+
stack: new Error().stack,
|
|
348
|
+
executionId: this.executionId
|
|
349
|
+
};
|
|
350
|
+
if (this.violations.length < MAX_STORED_VIOLATIONS) {
|
|
351
|
+
this.violations.push(violation);
|
|
352
|
+
}
|
|
353
|
+
if (this.config.onViolation) {
|
|
354
|
+
try {
|
|
355
|
+
this.config.onViolation(violation);
|
|
356
|
+
} catch (e) {
|
|
357
|
+
console.debug(
|
|
358
|
+
"[WorkerDefenseInDepth] onViolation callback threw:",
|
|
359
|
+
e instanceof Error ? e.message : e
|
|
360
|
+
);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
return violation;
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Create a blocking proxy for a function.
|
|
367
|
+
* In worker context, always blocks (no context check needed).
|
|
368
|
+
*/
|
|
369
|
+
// @banned-pattern-ignore: intentional use of Function type for security proxy
|
|
370
|
+
createBlockingProxy(original, path, violationType) {
|
|
371
|
+
const self = this;
|
|
372
|
+
const auditMode = this.config.auditMode;
|
|
373
|
+
return new this.originalProxy(original, {
|
|
374
|
+
apply(target, thisArg, args) {
|
|
375
|
+
const message = `${path} is blocked in worker context`;
|
|
376
|
+
const violation = self.recordViolation(violationType, path, message);
|
|
377
|
+
if (!auditMode) {
|
|
378
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
379
|
+
}
|
|
380
|
+
return Reflect.apply(target, thisArg, args);
|
|
381
|
+
},
|
|
382
|
+
construct(target, args, newTarget) {
|
|
383
|
+
const message = `${path} constructor is blocked in worker context`;
|
|
384
|
+
const violation = self.recordViolation(violationType, path, message);
|
|
385
|
+
if (!auditMode) {
|
|
386
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
387
|
+
}
|
|
388
|
+
return Reflect.construct(target, args, newTarget);
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Create a blocking proxy for an object (blocks all property access).
|
|
394
|
+
*/
|
|
395
|
+
createBlockingObjectProxy(original, path, violationType) {
|
|
396
|
+
const self = this;
|
|
397
|
+
const auditMode = this.config.auditMode;
|
|
398
|
+
return new this.originalProxy(original, {
|
|
399
|
+
get(target, prop, receiver) {
|
|
400
|
+
if (self.inTrap) {
|
|
401
|
+
return Reflect.get(target, prop, receiver);
|
|
402
|
+
}
|
|
403
|
+
self.inTrap = true;
|
|
404
|
+
try {
|
|
405
|
+
const fullPath = `${path}.${String(prop)}`;
|
|
406
|
+
const message = `${fullPath} is blocked in worker context`;
|
|
407
|
+
const violation = self.recordViolation(
|
|
408
|
+
violationType,
|
|
409
|
+
fullPath,
|
|
410
|
+
message
|
|
411
|
+
);
|
|
412
|
+
if (!auditMode) {
|
|
413
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
414
|
+
}
|
|
415
|
+
return Reflect.get(target, prop, receiver);
|
|
416
|
+
} finally {
|
|
417
|
+
self.inTrap = false;
|
|
418
|
+
}
|
|
419
|
+
},
|
|
420
|
+
set(target, prop, value, receiver) {
|
|
421
|
+
if (self.inTrap) {
|
|
422
|
+
return Reflect.set(target, prop, value, receiver);
|
|
423
|
+
}
|
|
424
|
+
self.inTrap = true;
|
|
425
|
+
try {
|
|
426
|
+
const fullPath = `${path}.${String(prop)}`;
|
|
427
|
+
const message = `${fullPath} modification is blocked in worker context`;
|
|
428
|
+
const violation = self.recordViolation(
|
|
429
|
+
violationType,
|
|
430
|
+
fullPath,
|
|
431
|
+
message
|
|
432
|
+
);
|
|
433
|
+
if (!auditMode) {
|
|
434
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
435
|
+
}
|
|
436
|
+
return Reflect.set(target, prop, value, receiver);
|
|
437
|
+
} finally {
|
|
438
|
+
self.inTrap = false;
|
|
439
|
+
}
|
|
440
|
+
},
|
|
441
|
+
ownKeys(target) {
|
|
442
|
+
if (self.inTrap) {
|
|
443
|
+
return Reflect.ownKeys(target);
|
|
444
|
+
}
|
|
445
|
+
self.inTrap = true;
|
|
446
|
+
try {
|
|
447
|
+
const message = `${path} enumeration is blocked in worker context`;
|
|
448
|
+
const violation = self.recordViolation(violationType, path, message);
|
|
449
|
+
if (!auditMode) {
|
|
450
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
451
|
+
}
|
|
452
|
+
return Reflect.ownKeys(target);
|
|
453
|
+
} finally {
|
|
454
|
+
self.inTrap = false;
|
|
455
|
+
}
|
|
456
|
+
},
|
|
457
|
+
getOwnPropertyDescriptor(target, prop) {
|
|
458
|
+
if (self.inTrap) {
|
|
459
|
+
return Reflect.getOwnPropertyDescriptor(target, prop);
|
|
460
|
+
}
|
|
461
|
+
self.inTrap = true;
|
|
462
|
+
try {
|
|
463
|
+
const fullPath = `${path}.${String(prop)}`;
|
|
464
|
+
const message = `${fullPath} descriptor access is blocked in worker context`;
|
|
465
|
+
const violation = self.recordViolation(
|
|
466
|
+
violationType,
|
|
467
|
+
fullPath,
|
|
468
|
+
message
|
|
469
|
+
);
|
|
470
|
+
if (!auditMode) {
|
|
471
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
472
|
+
}
|
|
473
|
+
return Reflect.getOwnPropertyDescriptor(target, prop);
|
|
474
|
+
} finally {
|
|
475
|
+
self.inTrap = false;
|
|
476
|
+
}
|
|
477
|
+
},
|
|
478
|
+
has(target, prop) {
|
|
479
|
+
if (self.inTrap) {
|
|
480
|
+
return Reflect.has(target, prop);
|
|
481
|
+
}
|
|
482
|
+
self.inTrap = true;
|
|
483
|
+
try {
|
|
484
|
+
const fullPath = `${path}.${String(prop)}`;
|
|
485
|
+
const message = `${fullPath} existence check is blocked in worker context`;
|
|
486
|
+
const violation = self.recordViolation(
|
|
487
|
+
violationType,
|
|
488
|
+
fullPath,
|
|
489
|
+
message
|
|
490
|
+
);
|
|
491
|
+
if (!auditMode) {
|
|
492
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
493
|
+
}
|
|
494
|
+
return Reflect.has(target, prop);
|
|
495
|
+
} finally {
|
|
496
|
+
self.inTrap = false;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* Apply security patches to dangerous globals.
|
|
503
|
+
*/
|
|
504
|
+
applyPatches() {
|
|
505
|
+
const blockedGlobals = getBlockedGlobals();
|
|
506
|
+
const excludeTypes = new Set(this.config.excludeViolationTypes ?? []);
|
|
507
|
+
for (const blocked of blockedGlobals) {
|
|
508
|
+
if (excludeTypes.has(blocked.violationType)) {
|
|
509
|
+
continue;
|
|
510
|
+
}
|
|
511
|
+
this.applyPatch(blocked);
|
|
512
|
+
}
|
|
513
|
+
if (!excludeTypes.has("function_constructor")) {
|
|
514
|
+
this.protectConstructorChain(excludeTypes);
|
|
515
|
+
}
|
|
516
|
+
if (!excludeTypes.has("error_prepare_stack_trace")) {
|
|
517
|
+
this.protectErrorPrepareStackTrace();
|
|
518
|
+
}
|
|
519
|
+
if (!excludeTypes.has("module_load")) {
|
|
520
|
+
this.protectModuleLoad();
|
|
521
|
+
}
|
|
522
|
+
if (!excludeTypes.has("process_main_module")) {
|
|
523
|
+
this.protectProcessMainModule();
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* Protect against .constructor.constructor escape vector.
|
|
528
|
+
* @param excludeTypes - Set of violation types to skip
|
|
529
|
+
*/
|
|
530
|
+
protectConstructorChain(excludeTypes) {
|
|
531
|
+
let AsyncFunction = null;
|
|
532
|
+
let GeneratorFunction = null;
|
|
533
|
+
let AsyncGeneratorFunction = null;
|
|
534
|
+
try {
|
|
535
|
+
AsyncFunction = Object.getPrototypeOf(async () => {
|
|
536
|
+
}).constructor;
|
|
537
|
+
} catch {
|
|
538
|
+
}
|
|
539
|
+
try {
|
|
540
|
+
GeneratorFunction = Object.getPrototypeOf(function* () {
|
|
541
|
+
}).constructor;
|
|
542
|
+
} catch {
|
|
543
|
+
}
|
|
544
|
+
try {
|
|
545
|
+
AsyncGeneratorFunction = Object.getPrototypeOf(
|
|
546
|
+
async function* () {
|
|
547
|
+
}
|
|
548
|
+
).constructor;
|
|
549
|
+
} catch {
|
|
550
|
+
}
|
|
551
|
+
this.patchPrototypeConstructor(
|
|
552
|
+
Function.prototype,
|
|
553
|
+
"Function.prototype.constructor",
|
|
554
|
+
"function_constructor"
|
|
555
|
+
);
|
|
556
|
+
if (!excludeTypes.has("async_function_constructor") && AsyncFunction && AsyncFunction !== Function) {
|
|
557
|
+
this.patchPrototypeConstructor(
|
|
558
|
+
AsyncFunction.prototype,
|
|
559
|
+
"AsyncFunction.prototype.constructor",
|
|
560
|
+
"async_function_constructor"
|
|
561
|
+
);
|
|
562
|
+
}
|
|
563
|
+
if (!excludeTypes.has("generator_function_constructor") && GeneratorFunction && GeneratorFunction !== Function) {
|
|
564
|
+
this.patchPrototypeConstructor(
|
|
565
|
+
GeneratorFunction.prototype,
|
|
566
|
+
"GeneratorFunction.prototype.constructor",
|
|
567
|
+
"generator_function_constructor"
|
|
568
|
+
);
|
|
569
|
+
}
|
|
570
|
+
if (!excludeTypes.has("async_generator_function_constructor") && AsyncGeneratorFunction && AsyncGeneratorFunction !== Function && AsyncGeneratorFunction !== AsyncFunction) {
|
|
571
|
+
this.patchPrototypeConstructor(
|
|
572
|
+
AsyncGeneratorFunction.prototype,
|
|
573
|
+
"AsyncGeneratorFunction.prototype.constructor",
|
|
574
|
+
"async_generator_function_constructor"
|
|
575
|
+
);
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* Protect Error.prepareStackTrace from being set.
|
|
580
|
+
*/
|
|
581
|
+
protectErrorPrepareStackTrace() {
|
|
582
|
+
const self = this;
|
|
583
|
+
const auditMode = this.config.auditMode;
|
|
584
|
+
try {
|
|
585
|
+
const originalDescriptor = Object.getOwnPropertyDescriptor(
|
|
586
|
+
Error,
|
|
587
|
+
"prepareStackTrace"
|
|
588
|
+
);
|
|
589
|
+
this.originalDescriptors.push({
|
|
590
|
+
target: Error,
|
|
591
|
+
prop: "prepareStackTrace",
|
|
592
|
+
descriptor: originalDescriptor
|
|
593
|
+
});
|
|
594
|
+
let currentValue = originalDescriptor?.value;
|
|
595
|
+
Object.defineProperty(Error, "prepareStackTrace", {
|
|
596
|
+
get() {
|
|
597
|
+
return currentValue;
|
|
598
|
+
},
|
|
599
|
+
set(value) {
|
|
600
|
+
const message = "Error.prepareStackTrace modification is blocked in worker context";
|
|
601
|
+
const violation = self.recordViolation(
|
|
602
|
+
"error_prepare_stack_trace",
|
|
603
|
+
"Error.prepareStackTrace",
|
|
604
|
+
message
|
|
605
|
+
);
|
|
606
|
+
if (!auditMode) {
|
|
607
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
608
|
+
}
|
|
609
|
+
currentValue = value;
|
|
610
|
+
},
|
|
611
|
+
configurable: true
|
|
612
|
+
});
|
|
613
|
+
} catch {
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* Patch a prototype's constructor property.
|
|
618
|
+
*
|
|
619
|
+
* Returns a proxy that allows reading properties (like .name) but blocks
|
|
620
|
+
* calling the constructor as a function (which would allow code execution).
|
|
621
|
+
*/
|
|
622
|
+
patchPrototypeConstructor(prototype, path, violationType) {
|
|
623
|
+
const self = this;
|
|
624
|
+
const auditMode = this.config.auditMode;
|
|
625
|
+
try {
|
|
626
|
+
const originalDescriptor = Object.getOwnPropertyDescriptor(
|
|
627
|
+
prototype,
|
|
628
|
+
"constructor"
|
|
629
|
+
);
|
|
630
|
+
this.originalDescriptors.push({
|
|
631
|
+
target: prototype,
|
|
632
|
+
prop: "constructor",
|
|
633
|
+
descriptor: originalDescriptor
|
|
634
|
+
});
|
|
635
|
+
const originalValue = originalDescriptor?.value;
|
|
636
|
+
const constructorProxy = originalValue && typeof originalValue === "function" ? new this.originalProxy(originalValue, {
|
|
637
|
+
apply(_target, _thisArg, _args) {
|
|
638
|
+
const message = `${path} invocation is blocked in worker context`;
|
|
639
|
+
const violation = self.recordViolation(
|
|
640
|
+
violationType,
|
|
641
|
+
path,
|
|
642
|
+
message
|
|
643
|
+
);
|
|
644
|
+
if (!auditMode) {
|
|
645
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
646
|
+
}
|
|
647
|
+
return void 0;
|
|
648
|
+
},
|
|
649
|
+
construct(_target, _args, _newTarget) {
|
|
650
|
+
const message = `${path} construction is blocked in worker context`;
|
|
651
|
+
const violation = self.recordViolation(
|
|
652
|
+
violationType,
|
|
653
|
+
path,
|
|
654
|
+
message
|
|
655
|
+
);
|
|
656
|
+
if (!auditMode) {
|
|
657
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
658
|
+
}
|
|
659
|
+
return {};
|
|
660
|
+
},
|
|
661
|
+
// Allow all property access (like .name, .prototype, etc.)
|
|
662
|
+
get(target, prop, receiver) {
|
|
663
|
+
return Reflect.get(target, prop, receiver);
|
|
664
|
+
},
|
|
665
|
+
getPrototypeOf(target) {
|
|
666
|
+
return Reflect.getPrototypeOf(target);
|
|
667
|
+
},
|
|
668
|
+
has(target, prop) {
|
|
669
|
+
return Reflect.has(target, prop);
|
|
670
|
+
},
|
|
671
|
+
ownKeys(target) {
|
|
672
|
+
return Reflect.ownKeys(target);
|
|
673
|
+
},
|
|
674
|
+
getOwnPropertyDescriptor(target, prop) {
|
|
675
|
+
return Reflect.getOwnPropertyDescriptor(target, prop);
|
|
676
|
+
}
|
|
677
|
+
}) : originalValue;
|
|
678
|
+
Object.defineProperty(prototype, "constructor", {
|
|
679
|
+
get() {
|
|
680
|
+
return constructorProxy;
|
|
681
|
+
},
|
|
682
|
+
set(value) {
|
|
683
|
+
const message = `${path} modification is blocked in worker context`;
|
|
684
|
+
const violation = self.recordViolation(violationType, path, message);
|
|
685
|
+
if (!auditMode) {
|
|
686
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
687
|
+
}
|
|
688
|
+
Object.defineProperty(this, "constructor", {
|
|
689
|
+
value,
|
|
690
|
+
writable: true,
|
|
691
|
+
configurable: true
|
|
692
|
+
});
|
|
693
|
+
},
|
|
694
|
+
configurable: true
|
|
695
|
+
});
|
|
696
|
+
} catch {
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
/**
|
|
700
|
+
* Protect process.mainModule from being accessed or set.
|
|
701
|
+
*
|
|
702
|
+
* The attack vector is:
|
|
703
|
+
* ```
|
|
704
|
+
* process.mainModule.require('child_process').execSync('whoami')
|
|
705
|
+
* process.mainModule.constructor._load('vm')
|
|
706
|
+
* ```
|
|
707
|
+
*
|
|
708
|
+
* process.mainModule may be undefined in ESM contexts but could exist in
|
|
709
|
+
* CommonJS workers. We block both reading and setting.
|
|
710
|
+
*/
|
|
711
|
+
protectProcessMainModule() {
|
|
712
|
+
if (typeof process === "undefined") return;
|
|
713
|
+
const self = this;
|
|
714
|
+
const auditMode = this.config.auditMode;
|
|
715
|
+
try {
|
|
716
|
+
const originalDescriptor = Object.getOwnPropertyDescriptor(
|
|
717
|
+
process,
|
|
718
|
+
"mainModule"
|
|
719
|
+
);
|
|
720
|
+
this.originalDescriptors.push({
|
|
721
|
+
target: process,
|
|
722
|
+
prop: "mainModule",
|
|
723
|
+
descriptor: originalDescriptor
|
|
724
|
+
});
|
|
725
|
+
const currentValue = originalDescriptor?.value;
|
|
726
|
+
if (currentValue !== void 0) {
|
|
727
|
+
Object.defineProperty(process, "mainModule", {
|
|
728
|
+
get() {
|
|
729
|
+
const message = "process.mainModule access is blocked in worker context";
|
|
730
|
+
const violation = self.recordViolation(
|
|
731
|
+
"process_main_module",
|
|
732
|
+
"process.mainModule",
|
|
733
|
+
message
|
|
734
|
+
);
|
|
735
|
+
if (!auditMode) {
|
|
736
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
737
|
+
}
|
|
738
|
+
return currentValue;
|
|
739
|
+
},
|
|
740
|
+
set(value) {
|
|
741
|
+
const message = "process.mainModule modification is blocked in worker context";
|
|
742
|
+
const violation = self.recordViolation(
|
|
743
|
+
"process_main_module",
|
|
744
|
+
"process.mainModule",
|
|
745
|
+
message
|
|
746
|
+
);
|
|
747
|
+
if (!auditMode) {
|
|
748
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
749
|
+
}
|
|
750
|
+
Object.defineProperty(process, "mainModule", {
|
|
751
|
+
value,
|
|
752
|
+
writable: true,
|
|
753
|
+
configurable: true
|
|
754
|
+
});
|
|
755
|
+
},
|
|
756
|
+
configurable: true
|
|
757
|
+
});
|
|
758
|
+
}
|
|
759
|
+
} catch {
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
/**
|
|
763
|
+
* Protect Module._load from being called.
|
|
764
|
+
*
|
|
765
|
+
* The attack vector is:
|
|
766
|
+
* ```
|
|
767
|
+
* module.constructor._load('child_process')
|
|
768
|
+
* require.main.constructor._load('vm')
|
|
769
|
+
* ```
|
|
770
|
+
*
|
|
771
|
+
* We access the Module class and replace _load with a blocking proxy.
|
|
772
|
+
*/
|
|
773
|
+
protectModuleLoad() {
|
|
774
|
+
const self = this;
|
|
775
|
+
const auditMode = this.config.auditMode;
|
|
776
|
+
try {
|
|
777
|
+
let ModuleClass = null;
|
|
778
|
+
if (typeof process !== "undefined") {
|
|
779
|
+
const mainModule = process.mainModule;
|
|
780
|
+
if (mainModule && typeof mainModule === "object") {
|
|
781
|
+
ModuleClass = mainModule.constructor;
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
if (!ModuleClass && typeof __require !== "undefined" && typeof __require.main !== "undefined") {
|
|
785
|
+
ModuleClass = __require.main.constructor;
|
|
786
|
+
}
|
|
787
|
+
if (!ModuleClass || typeof ModuleClass._load !== "function") {
|
|
788
|
+
return;
|
|
789
|
+
}
|
|
790
|
+
const original = ModuleClass._load;
|
|
791
|
+
const descriptor = Object.getOwnPropertyDescriptor(ModuleClass, "_load");
|
|
792
|
+
this.originalDescriptors.push({
|
|
793
|
+
target: ModuleClass,
|
|
794
|
+
prop: "_load",
|
|
795
|
+
descriptor
|
|
796
|
+
});
|
|
797
|
+
const path = "Module._load";
|
|
798
|
+
const proxy = new this.originalProxy(original, {
|
|
799
|
+
apply(_target, _thisArg, _args) {
|
|
800
|
+
const message = `${path} is blocked in worker context`;
|
|
801
|
+
const violation = self.recordViolation("module_load", path, message);
|
|
802
|
+
if (!auditMode) {
|
|
803
|
+
throw new WorkerSecurityViolationError(message, violation);
|
|
804
|
+
}
|
|
805
|
+
return Reflect.apply(_target, _thisArg, _args);
|
|
806
|
+
}
|
|
807
|
+
});
|
|
808
|
+
Object.defineProperty(ModuleClass, "_load", {
|
|
809
|
+
value: proxy,
|
|
810
|
+
writable: true,
|
|
811
|
+
configurable: true
|
|
812
|
+
});
|
|
813
|
+
} catch {
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
/**
|
|
817
|
+
* Apply a single patch to a blocked global.
|
|
818
|
+
*/
|
|
819
|
+
applyPatch(blocked) {
|
|
820
|
+
const { target, prop, violationType, strategy } = blocked;
|
|
821
|
+
try {
|
|
822
|
+
const original = target[prop];
|
|
823
|
+
if (original === void 0) {
|
|
824
|
+
return;
|
|
825
|
+
}
|
|
826
|
+
const descriptor = Object.getOwnPropertyDescriptor(target, prop);
|
|
827
|
+
this.originalDescriptors.push({ target, prop, descriptor });
|
|
828
|
+
if (strategy === "freeze") {
|
|
829
|
+
if (typeof original === "object" && original !== null) {
|
|
830
|
+
Object.freeze(original);
|
|
831
|
+
}
|
|
832
|
+
} else {
|
|
833
|
+
const path = this.getPathForTarget(target, prop);
|
|
834
|
+
const proxy = typeof original === "function" ? this.createBlockingProxy(
|
|
835
|
+
original,
|
|
836
|
+
path,
|
|
837
|
+
violationType
|
|
838
|
+
) : this.createBlockingObjectProxy(
|
|
839
|
+
original,
|
|
840
|
+
path,
|
|
841
|
+
violationType
|
|
842
|
+
);
|
|
843
|
+
Object.defineProperty(target, prop, {
|
|
844
|
+
value: proxy,
|
|
845
|
+
writable: true,
|
|
846
|
+
configurable: true
|
|
847
|
+
});
|
|
848
|
+
}
|
|
849
|
+
} catch {
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
/**
|
|
853
|
+
* Restore all original values.
|
|
854
|
+
*/
|
|
855
|
+
restorePatches() {
|
|
856
|
+
for (let i = this.originalDescriptors.length - 1; i >= 0; i--) {
|
|
857
|
+
const { target, prop, descriptor } = this.originalDescriptors[i];
|
|
858
|
+
try {
|
|
859
|
+
if (descriptor) {
|
|
860
|
+
Object.defineProperty(target, prop, descriptor);
|
|
861
|
+
} else {
|
|
862
|
+
delete target[prop];
|
|
863
|
+
}
|
|
864
|
+
} catch {
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
this.originalDescriptors = [];
|
|
868
|
+
}
|
|
869
|
+
};
|
|
870
|
+
|
|
5
871
|
// src/commands/python3/protocol.ts
|
|
6
872
|
var OpCode = {
|
|
7
873
|
NOOP: 0,
|
|
@@ -831,6 +1697,7 @@ class _JbHttpResponse:
|
|
|
831
1697
|
def __init__(self, data):
|
|
832
1698
|
self.status_code = data.get('status', 0)
|
|
833
1699
|
self.reason = data.get('statusText', '')
|
|
1700
|
+
# @banned-pattern-ignore: Python code, not JavaScript
|
|
834
1701
|
self.headers = data.get('headers', {})
|
|
835
1702
|
self.text = data.get('body', '')
|
|
836
1703
|
self.url = data.get('url', '')
|
|
@@ -1339,18 +2206,51 @@ except SystemExit as e:
|
|
|
1339
2206
|
return { success: true };
|
|
1340
2207
|
}
|
|
1341
2208
|
}
|
|
2209
|
+
var defense = null;
|
|
2210
|
+
async function initializeWithDefense() {
|
|
2211
|
+
await getPyodide();
|
|
2212
|
+
defense = new WorkerDefenseInDepth({
|
|
2213
|
+
excludeViolationTypes: [
|
|
2214
|
+
"proxy",
|
|
2215
|
+
"setImmediate",
|
|
2216
|
+
// 3. SharedArrayBuffer/Atomics: Used by sync-fs-backend.ts for synchronous
|
|
2217
|
+
// filesystem communication between Pyodide's WASM thread and the main thread.
|
|
2218
|
+
// Without this, Pyodide cannot perform synchronous file I/O operations.
|
|
2219
|
+
"shared_array_buffer",
|
|
2220
|
+
"atomics"
|
|
2221
|
+
],
|
|
2222
|
+
onViolation: (v) => {
|
|
2223
|
+
parentPort?.postMessage({ type: "security-violation", violation: v });
|
|
2224
|
+
}
|
|
2225
|
+
});
|
|
2226
|
+
}
|
|
1342
2227
|
if (parentPort) {
|
|
1343
2228
|
if (workerData) {
|
|
1344
|
-
runPython(workerData).then((result) => {
|
|
2229
|
+
initializeWithDefense().then(() => runPython(workerData)).then((result) => {
|
|
2230
|
+
result.defenseStats = defense?.getStats();
|
|
1345
2231
|
parentPort?.postMessage(result);
|
|
2232
|
+
}).catch((e) => {
|
|
2233
|
+
parentPort?.postMessage({
|
|
2234
|
+
success: false,
|
|
2235
|
+
error: e.message,
|
|
2236
|
+
defenseStats: defense?.getStats()
|
|
2237
|
+
});
|
|
1346
2238
|
});
|
|
1347
2239
|
}
|
|
1348
2240
|
parentPort.on("message", async (input) => {
|
|
1349
2241
|
try {
|
|
2242
|
+
if (!defense) {
|
|
2243
|
+
await initializeWithDefense();
|
|
2244
|
+
}
|
|
1350
2245
|
const result = await runPython(input);
|
|
2246
|
+
result.defenseStats = defense?.getStats();
|
|
1351
2247
|
parentPort?.postMessage(result);
|
|
1352
2248
|
} catch (e) {
|
|
1353
|
-
parentPort?.postMessage({
|
|
2249
|
+
parentPort?.postMessage({
|
|
2250
|
+
success: false,
|
|
2251
|
+
error: e.message,
|
|
2252
|
+
defenseStats: defense?.getStats()
|
|
2253
|
+
});
|
|
1354
2254
|
}
|
|
1355
2255
|
});
|
|
1356
2256
|
}
|