From c57ccbc04641dc7b3f8b61dd5b083fba276471b7 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 8 Feb 2024 13:51:36 +0100 Subject: [PATCH] Fix adding to context --- packages/server/src/jsRunner/index.ts | 7 ++++++- packages/server/src/jsRunner/vm/index.ts | 6 ++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/server/src/jsRunner/index.ts b/packages/server/src/jsRunner/index.ts index 20a48916c8..67d5111ea6 100644 --- a/packages/server/src/jsRunner/index.ts +++ b/packages/server/src/jsRunner/index.ts @@ -13,11 +13,16 @@ export function init() { let { vm } = bbCtx if (!vm) { + // Can't copy the native helpers into the isolate. We just ignore them as they are handled properly from the helpersSource + const { helpers, ...ctxToPass } = ctx + vm = new IsolatedVM({ memoryLimit: env.JS_RUNNER_MEMORY_LIMIT, timeout: env.JS_PER_EXECUTION_TIME_LIMIT_MS, perRequestLimit: env.JS_PER_REQUEST_TIME_LIMIT_MS, - }).withHelpers() + }) + .withContext(ctxToPass) + .withHelpers() bbCtx.vm = vm } diff --git a/packages/server/src/jsRunner/vm/index.ts b/packages/server/src/jsRunner/vm/index.ts index 673bb767af..3e33abf99e 100644 --- a/packages/server/src/jsRunner/vm/index.ts +++ b/packages/server/src/jsRunner/vm/index.ts @@ -185,10 +185,12 @@ export class IsolatedVM implements VM { private addToContext(context: Record) { for (let key in context) { + const value = context[key] this.jail.setSync( key, - context[key] - //new ivm.ExternalCopy(context[key]).copyInto({ release: true }) + typeof value === "function" + ? value + : new ivm.ExternalCopy(value).copyInto({ release: true }) ) } }