Patch React2Shell RCE and harden auth, uploads and containers
Deploy Vault CMS / deploy (push) Successful in 2m23s

- Upgrade next 16.0.3 -> 16.3.5 and react/react-dom 19.2.0 -> 19.3.0
  (CVE-2025-55182 / CVE-2025-66478 unauthenticated RCE), next-auth -> 4.24.15
- Require admin role on /api/users, /api/courses and /api/enrollments,
  which were unauthenticated
- Replace ALLOWED_ADMINS checks that allowed any signed-in user when the
  variable was empty with the role-based requireAdmin
- Sanitize upload filenames, restrict thumbnail extensions, store edited
  thumbnails in UPLOADS_DIR, tighten traversal checks in file routes
- Dockerfile: Node 22, pinned pnpm, non-root user, critical audit gate
- Compose: read-only rootfs, dropped caps, no-new-privileges, Postgres
  password from env
- Exclude .env from Docker build context; add security headers
- Deploy with git reset --hard instead of git pull
- Remove stale package-lock.json

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
twotalesanimation
2026-09-15 11:52:33 +02:00
parent a863a5cbf3
commit 08b6e58b8e
21 changed files with 974 additions and 10406 deletions
+25 -6
View File
@@ -5,6 +5,16 @@ import { authOptions } from '@/lib/auth-options';
import { prisma } from '@/lib/prisma';
import { writeFile, mkdir } from 'fs/promises';
import { join } from 'path';
import { randomUUID } from 'crypto';
const UPLOADS_DIR = process.env.UPLOADS_DIR || '/uploads';
const THUMBNAIL_EXTS: Record<string, string> = {
'image/jpeg': '.jpg',
'image/png': '.png',
'image/webp': '.webp',
'image/gif': '.gif',
};
export async function PATCH(req: Request) {
try {
@@ -93,18 +103,27 @@ export async function POST(req: Request) {
// Handle thumbnail upload if provided
if (thumbnail && thumbnail.size > 0) {
// extension comes from an allowlist, never from client-supplied strings
const ext = THUMBNAIL_EXTS[thumbnail.type];
if (!ext) {
return NextResponse.json(
{ error: 'Thumbnail must be a JPEG, PNG, WebP or GIF image' },
{ status: 400 }
);
}
const bytes = await thumbnail.arrayBuffer();
const buffer = Buffer.from(bytes);
// Save to public/thumbnails
const uploadDir = join(process.cwd(), 'public', 'thumbnails');
// Save with the upload route's thumbnails; the app directory itself is
// read-only in production
const uploadDir = join(UPLOADS_DIR, 'thumbnails');
await mkdir(uploadDir, { recursive: true });
const filename = `${videoId}-${Date.now()}.${thumbnail.type.split('/')[1] || 'jpg'}`;
const filepath = join(uploadDir, filename);
await writeFile(filepath, buffer);
const filename = `${Date.now()}-${randomUUID()}${ext}`;
await writeFile(join(uploadDir, filename), buffer);
updateData.thumbnail = `/thumbnails/${filename}`;
updateData.thumbnail = `/api/thumbnails/${filename}`;
}
if (Object.keys(updateData).length === 0 && !thumbnail && restrictedCourseIds === null) {