@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.
30 lines (29 loc) • 1.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.registerNodeHooks = registerNodeHooks;
const loadHook_1 = require("./loadHook");
const mod = require("node:module");
const processGetBuiltin_1 = require("./processGetBuiltin");
const checkHooks_1 = require("./checkHooks");
let hooksRegistered = false;
function registerNodeHooks() {
if (!("registerHooks" in mod) || typeof mod.registerHooks !== "function") {
throw new Error("This Node.js version is not supported");
}
// Do not register hooks multiple times
if (hooksRegistered) {
return;
}
hooksRegistered = true;
// Hook into the ESM & CJS module loading process
// Types are required because official Node.js typings are not up-to-date
mod.registerHooks({
load(url, context, nextLoad) {
const result = nextLoad(url, context);
return (0, loadHook_1.onModuleLoad)(url, context, result);
},
});
(0, processGetBuiltin_1.patchProcessGetBuiltinModule)();
// Run a self-check that prints a warning on failure
(0, checkHooks_1.checkHooks)();
}