feat(progress): add validation for progress and duration to ensure they are non-negative finite numbers within a reasonable range

This commit is contained in:
Yusuf İpek
2026-04-10 21:51:18 +03:00
parent c6f06627f2
commit db1c594fae
+4 -2
View File
@@ -85,11 +85,13 @@ export async function POST(request: NextRequest, { params }: RouteParams) {
const body = await request.json();
const { progress, duration, versionId } = body;
if (typeof progress !== 'number' || !isFinite(progress) || progress < 0) {
const MAX_VIDEO_SECONDS = 86_400; // 24 hours — reasonable upper bound for any video
if (typeof progress !== 'number' || !isFinite(progress) || progress < 0 || progress > MAX_VIDEO_SECONDS) {
return apiErrors.badRequest('Invalid progress value');
}
if (duration !== undefined && (typeof duration !== 'number' || !isFinite(duration) || duration < 0)) {
if (duration !== undefined && (typeof duration !== 'number' || !isFinite(duration) || duration < 0 || duration > MAX_VIDEO_SECONDS)) {
return apiErrors.badRequest('Invalid duration value');
}