mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 05:49:16 +01:00
feat(api): ✨ Add safeguard when using formdata without a boundary
This commit is contained in:
parent
3f9ec0bc80
commit
67bee695e6
3 changed files with 45 additions and 0 deletions
18
middlewares/boundary-check.ts
Normal file
18
middlewares/boundary-check.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import { errorResponse } from "@response";
|
||||
import { createMiddleware } from "hono/factory";
|
||||
|
||||
export const boundaryCheck = createMiddleware(async (context, next) => {
|
||||
// Checks that FormData boundary is present
|
||||
const contentType = context.req.header("content-type");
|
||||
|
||||
if (contentType?.includes("multipart/form-data")) {
|
||||
if (!contentType.includes("boundary")) {
|
||||
return errorResponse(
|
||||
"You are sending a request with a multipart/form-data content type but without a boundary. Please include a boundary in the Content-Type header. For more information, visit https://stackoverflow.com/questions/3508338/what-is-the-boundary-in-multipart-form-data",
|
||||
400,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
await next();
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue