Skip to content

Commit

Permalink
Merge pull request #306 from AikidoSec/check-wrap-builtin
Browse files Browse the repository at this point in the history
Check if built in module is available
  • Loading branch information
hansott authored Jul 29, 2024
2 parents ce8f12b + 68399d9 commit 73333f4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
4 changes: 4 additions & 0 deletions library/agent/applyHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -125,6 +126,9 @@ function wrapBuiltInModule(
subjects: WrappableSubject[],
agent: Agent
) {
if (!isPackageInstalled(module.getName())) {
return;
}
const exports = require(module.getName());

subjects.forEach(
Expand Down
5 changes: 0 additions & 5 deletions library/sinks/NodeSqlite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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) => {
Expand Down

0 comments on commit 73333f4

Please sign in to comment.