@aikidosec/firewall
Version:
Zen by Aikido is an embedded Application Firewall that autonomously protects Node.js apps against common and critical attacks, provides rate limiting, detects malicious traffic (including bots), and more.
38 lines (37 loc) • 1.09 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isPreloaded = isPreloaded;
/**
* Checks whever the args include --require / -r or --import @aikidosec/firewall
* Also checks NODE_OPTIONS.
*/
function isPreloaded() {
const processArgs = process.execArgv;
if (checkArgsForPreload(processArgs)) {
return true;
}
const nodeOptions = process.env.NODE_OPTIONS;
if (nodeOptions) {
const nodeOptionsArgs = nodeOptions.split(" ");
if (checkArgsForPreload(nodeOptionsArgs)) {
return true;
}
}
return false;
}
function checkArgsForPreload(args) {
for (const arg of args) {
if (arg !== "--require" && arg !== "-r" && arg !== "--import") {
continue;
}
const index = args.indexOf(arg);
if (index === -1 || index === args.length - 1) {
continue;
}
const moduleName = args[index + 1];
if (moduleName && moduleName.includes("@aikidosec/firewall")) {
return true;
}
}
return false;
}