fix: address findings from full security/functionality audit (Gitea #17)

Rate-limiting on messages.send, reports.create, reactions.toggle,
follows.create, reposts.create. Unique constraints on Report to stop
report-flooding. Mux webhook now fails hard in production without a
signing secret instead of skipping verification. Admin-panel outline
buttons fixed on 4 more pages (same white-on-dark bug as the Users page).
Timing-safe comparison for ADMIN_SECRET/CRON_SECRET. Fixed duplicate HSTS
header (Cloudflare's stronger one was being shadowed by the app's own).
tRPC now returns clean JSON 401s instead of HTML redirects when
unauthenticated, and no longer blocks public procedures for logged-out
visitors. 14 previously-silent catch blocks now log to GlitchTip.
invite/page.tsx and EmergencyVetSection.tsx fully localized (were 100%
hardcoded German). Stale TODO comments removed, auth.test.ts scaffold
rewritten to match the actual lazy-upsert pattern instead of a Clerk
webhook flow that was never built.
This commit is contained in:
admin committed 2026-08-13 12:42:49 +02:00
1 parent 2b52345c66
commit b4a49f8ed3
28 files changed
+258 -107

No files matched your search

+2 -1
View File
@@ -1,12 +1,13 @@
import { NextResponse } from "next/server";
import { prisma } from "@/lib/prisma";
import { timingSafeStringEqual } from "@/lib/timing-safe-compare";
// Vercel cron sends `Authorization: Bearer <CRON_SECRET>`.
// Set CRON_SECRET in your Vercel environment variables.
function authorized(req: Request): boolean {
const secret = process.env.CRON_SECRET;
if (!secret) return false;
return req.headers.get("authorization") === `Bearer ${secret}`;
return timingSafeStringEqual(req.headers.get("authorization") ?? "", `Bearer ${secret}`);
}
export async function GET(req: Request) {
+2 -1
View File
@@ -2,13 +2,14 @@ import { NextResponse } from "next/server";
import { prisma } from "@/lib/prisma";
import { redis } from "@/lib/redis";
import { trimFeed } from "@/lib/feed-helpers";
import { timingSafeStringEqual } from "@/lib/timing-safe-compare";
// Vercel cron sends `Authorization: Bearer <CRON_SECRET>`.
// Set CRON_SECRET in your Vercel environment variables.
function authorized(req: Request): boolean {
const secret = process.env.CRON_SECRET;
if (!secret) return false;
return req.headers.get("authorization") === `Bearer ${secret}`;
return timingSafeStringEqual(req.headers.get("authorization") ?? "", `Bearer ${secret}`);
}
/**
+8 -3
View File
@@ -20,8 +20,13 @@ export async function POST(req: NextRequest) {
const body = await req.text();
const signature = req.headers.get("mux-signature") ?? "";
// Verify signature — skip verification in dev if secret not set
if (MUX_WEBHOOK_SECRET) {
// Verify signature. In production a missing secret must fail hard, not
// silently accept unsigned events — dev-only convenience skip.
if (!MUX_WEBHOOK_SECRET) {
if (process.env.NODE_ENV === "production") {
return NextResponse.json({ error: "Webhook not configured" }, { status: 500 });
}
} else {
try {
mux.webhooks.verifySignature(body, req.headers as never, MUX_WEBHOOK_SECRET);
} catch {
@@ -84,7 +89,7 @@ export async function POST(req: NextRequest) {
videoPost.post.petId,
videoPost.post.createdAt,
prisma
).catch(() => {});
).catch((err) => console.error("[mux-webhook] fanOutPost failed", err));
break;
}