@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.
20 lines (19 loc) • 667 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.convertRequestBodyToString = convertRequestBodyToString;
const isPlainObject_1 = require("./isPlainObject");
function convertRequestBodyToString(body, maxLength = 16384) {
if (typeof body === "string") {
return body.length > maxLength ? body.slice(0, maxLength) : body;
}
if ((0, isPlainObject_1.isPlainObject)(body)) {
try {
const serialized = JSON.stringify(body, null, 2);
return convertRequestBodyToString(serialized, maxLength);
}
catch {
return undefined;
}
}
return undefined;
}