@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.
82 lines (81 loc) • 6.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.withoutIdorProtection = exports.enableIdorProtection = exports.setTenantId = exports.shutdown = exports.setRateLimitGroup = exports.addRestifyMiddleware = exports.addKoaMiddleware = exports.fastifyHook = exports.addFastifyHook = exports.addHapiMiddleware = exports.addHonoMiddleware = exports.addExpressMiddleware = exports.shouldBlockRequest = exports.markUnsafe = exports.setUser = void 0;
const isFirewallSupported_1 = require("./helpers/isFirewallSupported");
const shouldEnableFirewall_1 = require("./helpers/shouldEnableFirewall");
const user_1 = require("./agent/context/user");
Object.defineProperty(exports, "setUser", { enumerable: true, get: function () { return user_1.setUser; } });
const markUnsafe_1 = require("./agent/context/markUnsafe");
Object.defineProperty(exports, "markUnsafe", { enumerable: true, get: function () { return markUnsafe_1.markUnsafe; } });
const shouldBlockRequest_1 = require("./middleware/shouldBlockRequest");
Object.defineProperty(exports, "shouldBlockRequest", { enumerable: true, get: function () { return shouldBlockRequest_1.shouldBlockRequest; } });
const express_1 = require("./middleware/express");
Object.defineProperty(exports, "addExpressMiddleware", { enumerable: true, get: function () { return express_1.addExpressMiddleware; } });
const hono_1 = require("./middleware/hono");
Object.defineProperty(exports, "addHonoMiddleware", { enumerable: true, get: function () { return hono_1.addHonoMiddleware; } });
const hapi_1 = require("./middleware/hapi");
Object.defineProperty(exports, "addHapiMiddleware", { enumerable: true, get: function () { return hapi_1.addHapiMiddleware; } });
const fastify_1 = require("./middleware/fastify");
Object.defineProperty(exports, "addFastifyHook", { enumerable: true, get: function () { return fastify_1.addFastifyHook; } });
Object.defineProperty(exports, "fastifyHook", { enumerable: true, get: function () { return fastify_1.fastifyHook; } });
const koa_1 = require("./middleware/koa");
Object.defineProperty(exports, "addKoaMiddleware", { enumerable: true, get: function () { return koa_1.addKoaMiddleware; } });
const isNewHookSystemUsed_1 = require("./agent/isNewHookSystemUsed");
const restify_1 = require("./middleware/restify");
Object.defineProperty(exports, "addRestifyMiddleware", { enumerable: true, get: function () { return restify_1.addRestifyMiddleware; } });
const isESM_1 = require("./helpers/isESM");
const indexImportGuard_1 = require("./helpers/indexImportGuard");
const group_1 = require("./ratelimiting/group");
Object.defineProperty(exports, "setRateLimitGroup", { enumerable: true, get: function () { return group_1.setRateLimitGroup; } });
const shutdown_1 = require("./agent/shutdown");
Object.defineProperty(exports, "shutdown", { enumerable: true, get: function () { return shutdown_1.shutdown; } });
const isLibBundled_1 = require("./helpers/isLibBundled");
const tenantId_1 = require("./agent/context/tenantId");
Object.defineProperty(exports, "setTenantId", { enumerable: true, get: function () { return tenantId_1.setTenantId; } });
const idorProtection_1 = require("./agent/idorProtection");
Object.defineProperty(exports, "enableIdorProtection", { enumerable: true, get: function () { return idorProtection_1.enableIdorProtection; } });
const withoutIdorProtection_1 = require("./agent/context/withoutIdorProtection");
Object.defineProperty(exports, "withoutIdorProtection", { enumerable: true, get: function () { return withoutIdorProtection_1.withoutIdorProtection; } });
const colorText_1 = require("./helpers/colorText");
const warnBox_1 = require("./helpers/warnBox");
const isPreloaded_1 = require("./helpers/isPreloaded");
const warnIfEntrypointIsModule_1 = require("./helpers/warnIfEntrypointIsModule");
// Prevent logging twice / trying to start agent twice
if (!(0, isNewHookSystemUsed_1.isNewHookSystemUsed)()) {
const supported = (0, isFirewallSupported_1.default)();
const shouldEnable = (0, shouldEnableFirewall_1.default)();
const notAlreadyImported = (0, indexImportGuard_1.checkIndexImportGuard)();
if (supported && shouldEnable && notAlreadyImported) {
if ((0, isESM_1.isESM)() === true) {
// oxlint-disable-next-line no-console
console.warn((0, colorText_1.colorText)("red", (0, warnBox_1.warnBox)("Zen is NOT protecting your application. Your app runs in ESM mode, which requires the new hook system. Setup instructions: https://github.com/AikidoSec/firewall-node/blob/main/docs/esm.md")));
}
if ((0, isLibBundled_1.isLibBundled)()) {
// oxlint-disable-next-line no-console
console.warn((0, colorText_1.colorText)("red", (0, warnBox_1.warnBox)("Zen is NOT protecting your application. Your app uses a bundler without externalizing Zen and the packages it needs to protect. See https://github.com/AikidoSec/firewall-node/blob/main/docs/bundler.md")));
}
if ((0, isPreloaded_1.isPreloaded)()) {
(0, warnIfEntrypointIsModule_1.warnIfEntrypointIsModule)();
}
require("./agent/protect").protect();
}
}
// Required for ESM / TypeScript default export support
// e.g. import Zen from '@aikidosec/firewall'; would not work without this, as Zen.setUser would be undefined
exports.default = {
setUser: user_1.setUser,
markUnsafe: markUnsafe_1.markUnsafe,
shouldBlockRequest: shouldBlockRequest_1.shouldBlockRequest,
addExpressMiddleware: express_1.addExpressMiddleware,
addHonoMiddleware: hono_1.addHonoMiddleware,
addHapiMiddleware: hapi_1.addHapiMiddleware,
addFastifyHook: fastify_1.addFastifyHook,
fastifyHook: fastify_1.fastifyHook,
addKoaMiddleware: koa_1.addKoaMiddleware,
addRestifyMiddleware: restify_1.addRestifyMiddleware,
setRateLimitGroup: group_1.setRateLimitGroup,
shutdown: shutdown_1.shutdown,
setTenantId: tenantId_1.setTenantId,
enableIdorProtection: idorProtection_1.enableIdorProtection,
withoutIdorProtection: withoutIdorProtection_1.withoutIdorProtection,
};