diff --git a/library/agent/protect.ts b/library/agent/protect.ts index c045e57c..45f94094 100644 --- a/library/agent/protect.ts +++ b/library/agent/protect.ts @@ -47,7 +47,6 @@ import { Postgresjs } from "../sinks/Postgresjs"; import { Fastify } from "../sources/Fastify"; import { Koa } from "../sources/Koa"; import { ClickHouse } from "../sinks/ClickHouse"; -import { Eval } from "../sinks/Eval"; import { Function } from "../sinks/Function"; function getLogger(): Logger { @@ -138,7 +137,6 @@ export function getWrappers() { new Fastify(), new Koa(), new ClickHouse(), - new Eval(), new Function(), ]; } diff --git a/library/sinks/Eval.test.ts b/library/sinks/Eval.test.ts deleted file mode 100644 index 2c5beb05..00000000 --- a/library/sinks/Eval.test.ts +++ /dev/null @@ -1,75 +0,0 @@ -import * as t from "tap"; -import { runWithContext, type Context } from "../agent/Context"; -import { createTestAgent } from "../helpers/createTestAgent"; -import { Eval } from "./Eval"; - -const dangerousContext: Context = { - remoteAddress: "::1", - method: "POST", - url: "http://localhost:4000", - query: {}, - headers: {}, - body: { - calc: "1 + 1; console.log('hello')", - }, - cookies: {}, - routeParams: {}, - source: "express", - route: "/posts/:id", -}; - -const safeContext: Context = { - remoteAddress: "::1", - method: "POST", - url: "http://localhost:4000/", - query: {}, - headers: {}, - body: { - calc: "1+ 1", - }, - cookies: {}, - routeParams: {}, - source: "express", - route: "/posts/:id", -}; - -t.test("it detects JS injections using Eval", async (t) => { - const agent = createTestAgent(); - agent.start([new Eval()]); - - t.same(eval("1 + 1"), 2); - t.same(eval("1 + 1; console.log('hello')"), undefined); - t.same(eval("const x = 1 + 1; x"), 2); - - runWithContext(dangerousContext, () => { - t.same(eval("1 + 1"), 2); - t.same(eval("const x = 1 + 1; x"), 2); - - const error = t.throws(() => eval("1 + 1; console.log('hello')")); - t.ok(error instanceof Error); - if (error instanceof Error) { - t.same( - error.message, - "Zen has blocked a JavaScript injection: eval(...) originating from body.calc" - ); - } - - const error2 = t.throws(() => - eval("const test = 1 + 1; console.log('hello')") - ); - t.ok(error2 instanceof Error); - if (error2 instanceof Error) { - t.same( - error2.message, - "Zen has blocked a JavaScript injection: eval(...) originating from body.calc" - ); - } - }); - - runWithContext(safeContext, () => { - t.same(eval("1 + 1"), 2); - t.same(eval("const x = 1 + 1; x"), 2); - t.same(eval("1 + 1; console.log('hello')"), undefined); - t.same(eval("const test = 1 + 1; console.log('hello')"), undefined); - }); -}); diff --git a/library/sinks/Eval.ts b/library/sinks/Eval.ts deleted file mode 100644 index c6a63368..00000000 --- a/library/sinks/Eval.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { getContext } from "../agent/Context"; -import { Hooks } from "../agent/hooks/Hooks"; -import { Wrapper } from "../agent/Wrapper"; -import { checkContextForJsInjection } from "../vulnerabilities/js-injection/checkContextForJsInjection"; - -export class Eval implements Wrapper { - private inspectEval(args: any[]) { - const context = getContext(); - - if (!context) { - return undefined; - } - - if (args.length === 1 && typeof args[0] === "string") { - return checkContextForJsInjection({ - js: args[0], - operation: "eval", - context, - }); - } - - return undefined; - } - - wrap(hooks: Hooks) { - hooks.addGlobal("eval", { - inspectArgs: this.inspectEval, - }); - } -}