@aikidosec/firewall
Version:
Zen by Aikido is an embedded Web Application Firewall that autonomously protects Node.js apps against common and critical attacks
78 lines (77 loc) • 2.99 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MariaDB = void 0;
const Context_1 = require("../agent/Context");
const wrapExport_1 = require("../agent/hooks/wrapExport");
const isPlainObject_1 = require("../helpers/isPlainObject");
const checkContextForSqlInjection_1 = require("../vulnerabilities/sql-injection/checkContextForSqlInjection");
const SQLDialectMySQL_1 = require("../vulnerabilities/sql-injection/dialects/SQLDialectMySQL");
class MariaDB {
constructor() {
this.dialect = new SQLDialectMySQL_1.SQLDialectMySQL();
}
inspectQuery(args, operation) {
const context = (0, Context_1.getContext)();
if (!context) {
return undefined;
}
if (args.length > 0 && typeof args[0] === "string" && args[0].length > 0) {
const sql = args[0];
return (0, checkContextForSqlInjection_1.checkContextForSqlInjection)({
sql: sql,
context: context,
operation: `mariadb.${operation}`,
dialect: this.dialect,
});
}
if (args.length > 0 &&
(0, isPlainObject_1.isPlainObject)(args[0]) &&
args[0].sql &&
typeof args[0].sql === "string") {
const sql = args[0].sql;
return (0, checkContextForSqlInjection_1.checkContextForSqlInjection)({
sql: sql,
context: context,
operation: `mariadb.${operation}`,
dialect: this.dialect,
});
}
return undefined;
}
wrapConnection(exports, pkgInfo) {
const functions = ["query", "execute", "prepare", "batch", "queryStream"];
for (const fn of functions) {
(0, wrapExport_1.wrapExport)(exports.prototype, fn, pkgInfo, {
kind: "sql_op",
inspectArgs: (args) => this.inspectQuery(args, fn),
});
}
}
wrapPool(exports, pkgInfo) {
const functions = ["query", "execute", "batch"];
for (const fn of functions) {
(0, wrapExport_1.wrapExport)(exports.prototype, fn, pkgInfo, {
kind: "sql_op",
inspectArgs: (args) => this.inspectQuery(args, fn),
});
}
}
wrap(hooks) {
hooks
.addPackage("mariadb")
.withVersion("^3.0.0")
.onFileRequire("lib/connection-promise.js", (exports, pkgInfo) => {
this.wrapConnection(exports, pkgInfo);
})
.onFileRequire("lib/connection-callback.js", (exports, pkgInfo) => {
this.wrapConnection(exports, pkgInfo);
})
.onFileRequire("lib/pool-promise.js", (exports, pkgInfo) => {
this.wrapPool(exports, pkgInfo);
})
.onFileRequire("lib/pool-callback.js", (exports, pkgInfo) => {
this.wrapPool(exports, pkgInfo);
});
}
}
exports.MariaDB = MariaDB;