Security fixes pass #1

This commit is contained in:
2026-04-19 14:59:20 +01:00
parent cb5126c947
commit 3b26292124
3 changed files with 47 additions and 11 deletions
+25 -5
View File
@@ -68,16 +68,16 @@ export default async function ({ req }: Params): Promise<Response> {
const config = module.config as BunextServerRouteConfig | undefined;
const maxBodyBytes = config?.max_request_body_mb
? config.max_request_body_mb * MBInBytes
: ServerDefaultRequestBodyLimitBytes;
const contentLength = req.headers.get("content-length");
if (contentLength) {
const size = parseInt(contentLength, 10);
if (
(config?.max_request_body_mb &&
size > config.max_request_body_mb * MBInBytes) ||
size > ServerDefaultRequestBodyLimitBytes
) {
if (size > maxBodyBytes) {
return Response.json(
{
success: false,
@@ -91,6 +91,26 @@ export default async function ({ req }: Params): Promise<Response> {
},
);
}
} else if (req.method !== "GET" && req.method !== "HEAD") {
const body = await req.arrayBuffer();
if (body.byteLength > maxBodyBytes) {
return Response.json(
{
success: false,
msg: "Request Body Too Large!",
},
{
status: 413,
headers: {
"Content-Type": "application/json",
},
},
);
}
routeParams.body = JSON.parse(
new TextDecoder().decode(body) || "{}",
);
}
const target_module = (module["default"] ||