UNPKG

@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.

37 lines (36 loc) 2.06 kB
"use strict"; /* oxlint-disable no-console */ Object.defineProperty(exports, "__esModule", { value: true }); const mod = require("node:module"); const shouldEnableFirewall_1 = require("../helpers/shouldEnableFirewall"); const isFirewallSupported_1 = require("../helpers/isFirewallSupported"); const protect_1 = require("../agent/protect"); const isNewHookSystemUsed_1 = require("../agent/isNewHookSystemUsed"); const indexImportGuard_1 = require("../helpers/indexImportGuard"); const node_worker_threads_1 = require("node:worker_threads"); const isESM_1 = require("../helpers/isESM"); const isPreloaded_1 = require("../helpers/isPreloaded"); const colorText_1 = require("../helpers/colorText"); const warnBox_1 = require("../helpers/warnBox"); (0, isNewHookSystemUsed_1.setIsNewHookSystemUsed)(true); const isSupported = (0, isFirewallSupported_1.default)(); const shouldEnable = (0, shouldEnableFirewall_1.default)(); const notAlreadyImported = (0, indexImportGuard_1.checkIndexImportGuard)(); function start() { if (!isSupported || !shouldEnable || !notAlreadyImported) { return; } if (!("registerHooks" in mod) || typeof mod.registerHooks !== "function") { console.error((0, colorText_1.colorText)("red", (0, warnBox_1.warnBox)("Zen is NOT protecting your application. Your Node.js version does not support module.registerHooks. Upgrade Node.js and see https://github.com/AikidoSec/firewall-node/blob/main/docs/esm.md"))); return; } if (!node_worker_threads_1.isMainThread) { console.warn("AIKIDO: Zen does not instrument worker threads. Zen will only be active in the main thread."); return; } if ((0, isESM_1.isESM)() === true && !(0, isPreloaded_1.isPreloaded)()) { console.error((0, colorText_1.colorText)("red", (0, warnBox_1.warnBox)("Zen is NOT protecting your application. Your ESM app needs the library preloaded with --require. See https://github.com/AikidoSec/firewall-node/blob/main/docs/esm.md"))); } (0, protect_1.protectWithNewInstrumentation)(); } start();