mirror of
https://github.com/Elysola/WebHooker.git
synced 2026-11-21 01:23:40 +00:00
fix(bot): reject oversized callback bodies
Reject declared oversized bot callbacks before reading their bodies. This keeps unauthenticated requests from wasting worker resources.
This commit is contained in:
1 parent
c641a8c1c5
commit
6535126ae0
4 files changed
+19
-3
No files matched your search
@@ -56,3 +56,16 @@ export function headersFrom(event: H3Event): Record<string, string> {
|
||||
});
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Largest body the bot callback routes read (each handler checks it again). */
|
||||
export const MAX_CALLBACK_BODY = 1024 * 1024;
|
||||
|
||||
/**
|
||||
* A body declared larger than `max` bytes: answered 413 before the route
|
||||
* reads (and copies) it. Bodies without a declared length are still checked
|
||||
* by the handler once read.
|
||||
*/
|
||||
export function declaresBodyOver(event: H3Event, max = MAX_CALLBACK_BODY): boolean {
|
||||
const length = Number(event.headers.get("content-length"));
|
||||
return Number.isFinite(length) && length > max;
|
||||
}
|
||||
Reference in new issue
Block a user