Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/api/upload/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import path from "node:path";
import { readSession, authConfigured, SESSION_COOKIE } from "@/lib/session";
import { findOrCreateAccountByEmail, ownsParkedDomain, getTenantConfig, upsertTenant } from "@/lib/db";
import { safeDomain } from "@/lib/config";
import { ffmpegPoster } from "@/lib/media";
import { ffmpegPoster, mediaTypeForUpload } from "@/lib/media";

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

Expand Down
6 changes: 6 additions & 0 deletions tests/media-upload-type.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ test("media upload type rejects empty or generic non-video names", () => {
assert.equal(mediaTypeForUpload("payload", "application/octet-stream"), null);
assert.equal(mediaTypeForUpload("clip.gif", "application/octet-stream"), null);
});

test("media upload type rejects substring MIME matches", () => {
assert.equal(mediaTypeForUpload("payload.bin", "application/octet-stream-extra"), null);
assert.equal(mediaTypeForUpload("payload.bin", "text/video/mp4"), null);
assert.equal(mediaTypeForUpload("payload.bin", "application/json; video/mp4"), null);
});
Loading