@aikidosec/firewall
Version:
Zen by Aikido is an embedded Web Application Firewall that autonomously protects Node.js apps against common and critical attacks
22 lines (21 loc) • 740 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getRateLimitedEndpoint = getRateLimitedEndpoint;
function getRateLimitedEndpoint(context, config) {
const matches = config
.getEndpoints(context)
.filter((m) => m.rateLimiting && m.rateLimiting.enabled);
if (matches.length === 0) {
return undefined;
}
const exact = matches.find((m) => m.route === context.route);
if (exact) {
return exact;
}
matches.sort((a, b) => {
const aRate = a.rateLimiting.maxRequests / a.rateLimiting.windowSizeInMS;
const bRate = b.rateLimiting.maxRequests / b.rateLimiting.windowSizeInMS;
return aRate - bRate;
});
return matches[0];
}