Removing env vars to disable isolated-vm usage.

This commit is contained in:
mike12345567 2024-02-19 17:55:04 +00:00
parent 865e9ac111
commit 87d60ca5f2
3 changed files with 9 additions and 23 deletions

View File

@ -4,11 +4,12 @@ import { context } from "@budibase/backend-core"
import tracer from "dd-trace"
import { BuiltInVM, IsolatedVM } from "./vm"
const USE_ISOLATED_VM = true
export function init() {
setJSRunner((js: string, ctx: Record<string, any>) => {
return tracer.trace("runJS", {}, span => {
const useIsolatedVm = env.ISOLATEDVM_JS_RUNNER
if (!useIsolatedVm) {
if (!USE_ISOLATED_VM) {
const vm = new BuiltInVM(ctx, span)
return vm.execute(js)
}
@ -31,8 +32,7 @@ export function init() {
bbCtx.vm = vm
}
const result = vm.execute(js)
return result
return vm.execute(js)
} catch (error: any) {
if (error.message === "Script execution timed out.") {
throw new JsErrorTimeout()

View File

@ -1,7 +1,4 @@
import vm from "vm"
import { validate as isValidUUID } from "uuid"
import { processStringSync, encodeJSBinding } from "@budibase/string-templates"
const { runJsHelpersTests } = require("@budibase/string-templates/test/utils")
@ -9,19 +6,13 @@ const { runJsHelpersTests } = require("@budibase/string-templates/test/utils")
import tk from "timekeeper"
import { init } from ".."
import TestConfiguration from "../../tests/utilities/TestConfiguration"
import environment from "../../environment"
tk.freeze("2021-01-21T12:00:00")
describe.each([
["vm", false],
["isolated-vm", true],
])("jsRunner (using %s)", (_, useIsolatedVM) => {
describe("jsRunner (using isolated-vm)", () => {
const config = new TestConfiguration()
beforeAll(async () => {
environment._set("ISOLATEDVM_JS_RUNNER", useIsolatedVM)
// Register js runner
init()
await config.init()
@ -51,13 +42,7 @@ describe.each([
const output = await processJS(
`return this.constructor.constructor("return process.env")()`
)
if (useIsolatedVM) {
expect(output).toBe("Error while executing JS")
} else {
// This was not an issue without isolated-vm
expect(output).not.toBe("Error while executing JS")
expect(output).toEqual(process.env)
}
expect(output).toBe("Error while executing JS")
})
describe("helpers", () => {

View File

@ -18,7 +18,8 @@ import { Datasource, Query, SourceName, VM } from "@budibase/types"
import { isSQL } from "../integrations/utils"
import { interpolateSQL } from "../integrations/queries/sql"
import environment from "../environment"
const USE_ISOLATED_VM = true
class QueryRunner {
datasource: Datasource
@ -129,7 +130,7 @@ class QueryRunner {
// transform as required
if (transformer) {
let runner: VM
if (!environment.ISOLATEDVM_QUERY_TRANSFORMERS) {
if (!USE_ISOLATED_VM) {
runner = new VM2({
data: rows,
params: enrichedParameters,