fix(api): reject unparsable bodies and screen non-form ones (#2503)

This commit is contained in:
Hampus authored and GitHub committed 2026-09-06 15:29:04 +02:00
1 parent f8a04b8985
commit f06d65db54
5 files changed
+72 -3

No files matched your search

@@ -1,5 +1,7 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
import {ValidationErrorCodes} from '@fluxer/constants/src/ValidationErrorCodes';
import {InputValidationError} from '@fluxer/errors/src/domains/core/InputValidationError';
import type {HonoRequest} from 'hono';
import {parseJsonPreservingLargeIntegers} from './LosslessJsonParser';
@@ -24,3 +26,11 @@ export async function readRequestJsonBody(req: HonoRequest): Promise<RequestJson
bodyCache.set(raw, body);
return body;
}
export async function requireRequestJsonBody(req: HonoRequest): Promise<unknown> {
const body = await readRequestJsonBody(req);
if (!body.parsed) {
throw InputValidationError.fromCode('body', ValidationErrorCodes.INVALID_FORMAT);
}
return body.value;
}