🛡️ Sentinel: [CRITICAL] Fix rate limit DoS vulnerability (#136)

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
This commit is contained in:
Ralksta
2026-04-24 22:12:42 +02:00
committed by GitHub
parent 93ac1c20e8
commit f18d9ae3d9
4 changed files with 16 additions and 13 deletions

View File

@@ -10,16 +10,13 @@ import { getConfig } from '@/lib/config';
import { imageUrl } from '@/lib/urls';
import { isAuthenticated } from '@/lib/auth';
import { getMapData } from '@/lib/mapService';
import { checkRateLimit } from '@/lib/rate-limit';
import { checkRateLimit, getClientIp } from '@/lib/rate-limit';
export const dynamic = 'force-dynamic';
export async function GET(request: NextRequest) {
// Rate limit: 120 requests/minute per IP (map data is cached client-side; this guards against abuse)
const ip =
request.headers.get('x-forwarded-for')?.split(',')[0].trim() ??
request.headers.get('x-real-ip') ??
'127.0.0.1';
const ip = getClientIp(request);
const rl = checkRateLimit(ip, 120);
if (!rl.success) {
return NextResponse.json(