From 68399d9cda2240b913f906481bb1a39d76eab962 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20K=C3=B6ssler?= Date: Fri, 26 Jul 2024 16:35:29 +0200 Subject: [PATCH] Check if built in module is available --- library/agent/applyHooks.ts | 4 ++++ library/sinks/NodeSqlite.ts | 5 ----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/library/agent/applyHooks.ts b/library/agent/applyHooks.ts index 3b19c780c..54d3e466e 100644 --- a/library/agent/applyHooks.ts +++ b/library/agent/applyHooks.ts @@ -20,6 +20,7 @@ import { Package } from "./hooks/Package"; import { WrappableFile } from "./hooks/WrappableFile"; import { WrappableSubject } from "./hooks/WrappableSubject"; import { MethodResultInterceptor } from "./hooks/MethodResultInterceptor"; +import { isPackageInstalled } from "../helpers/isPackageInstalled"; /** * Hooks allows you to register packages and then wrap specific methods on @@ -125,6 +126,9 @@ function wrapBuiltInModule( subjects: WrappableSubject[], agent: Agent ) { + if (!isPackageInstalled(module.getName())) { + return; + } const exports = require(module.getName()); subjects.forEach( diff --git a/library/sinks/NodeSqlite.ts b/library/sinks/NodeSqlite.ts index ae17a32f9..93a4f871e 100644 --- a/library/sinks/NodeSqlite.ts +++ b/library/sinks/NodeSqlite.ts @@ -2,7 +2,6 @@ import { getContext } from "../agent/Context"; import { Hooks } from "../agent/hooks/Hooks"; import { InterceptorResult } from "../agent/hooks/MethodInterceptor"; import { Wrapper } from "../agent/Wrapper"; -import { isPackageInstalled } from "../helpers/isPackageInstalled"; import { checkContextForSqlInjection } from "../vulnerabilities/sql-injection/checkContextForSqlInjection"; import type { SQLDialect } from "../vulnerabilities/sql-injection/dialects/SQLDialect"; import { SQLDialectSQLite } from "../vulnerabilities/sql-injection/dialects/SQLDialectSQLite"; @@ -11,10 +10,6 @@ export class NodeSQLite implements Wrapper { private readonly dialect: SQLDialect = new SQLDialectSQLite(); wrap(hooks: Hooks) { - if (!isPackageInstalled("node:sqlite")) { - return; - } - const database = hooks .addBuiltinModule("node:sqlite") .addSubject((exports) => {