Skip to content

Commit f3cd742

Browse files
committed
fix(upload): enforce strict mp4 validation
The inline check accepted application/octet-stream (any file) and used an unanchored regex so substring MIME types like text/video/mp4 passed. Route through the existing mediaTypeForUpload helper which does exact Object.hasOwn matching and extension fallback. Fixes #53
1 parent c30ca23 commit f3cd742

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

app/api/upload/route.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import path from "node:path";
44
import { readSession, authConfigured, SESSION_COOKIE } from "@/lib/session";
55
import { findOrCreateAccountByEmail, ownsParkedDomain, getTenantConfig, upsertTenant } from "@/lib/db";
66
import { safeDomain } from "@/lib/config";
7-
import { ffmpegPoster } from "@/lib/media";
7+
import { ffmpegPoster, mediaTypeForUpload } from "@/lib/media";
88

99
export const runtime = "nodejs";
1010
export const dynamic = "force-dynamic";
@@ -36,8 +36,7 @@ export async function POST(req: NextRequest) {
3636
try { form = await req.formData(); } catch { return NextResponse.json({ error: "Bad upload." }, { status: 400 }); }
3737
const file = form.get("file");
3838
if (!(file instanceof File)) return NextResponse.json({ error: "No file." }, { status: 400 });
39-
const isMp4 = /\.mp4$/i.test(file.name) || /video\/mp4|application\/octet-stream/.test(file.type);
40-
if (!isMp4) return NextResponse.json({ error: "MP4 files only." }, { status: 400 });
39+
if (!mediaTypeForUpload(file.name, file.type)) return NextResponse.json({ error: "MP4 files only." }, { status: 400 });
4140
if (file.size > MAX_BYTES) return NextResponse.json({ error: "Too big — 100 MB max." }, { status: 413 });
4241

4342
const dir = path.join(VIDEO_DIR, domSlug(dn));

0 commit comments

Comments
 (0)