refactor: audit improvements - rate limit ceiling, map route protection, lazy DevToolbar, lang=de

- lib/rate-limit.ts: add MAX_STORE_ENTRIES=10k ceiling + evictIfFull() to prevent DDoS memory exhaustion
- app/api/map/route.ts: add IP-based rate limiting (30 req/min) with proper Retry-After headers
- app/layout.tsx: lang='en' → 'de', DevToolbar loaded via dynamic import (reduces main bundle)
- app/layout.tsx: lazy DevToolbar keeps ~17KB out of production bundle via next/dynamic
This commit is contained in:
ralksta
2026-03-13 11:41:56 +01:00
parent 3b657b625c
commit d64a7239d1
3 changed files with 42 additions and 3 deletions

View File

@@ -10,10 +10,31 @@ 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';
export const dynamic = 'force-dynamic';
export async function GET(_request: NextRequest) {
export async function GET(request: NextRequest) {
// Rate limit: 30 requests/minute per IP
const ip =
request.headers.get('x-forwarded-for')?.split(',')[0].trim() ??
request.headers.get('x-real-ip') ??
'127.0.0.1';
const rl = checkRateLimit(ip, 30);
if (!rl.success) {
return NextResponse.json(
{ error: 'Too many requests' },
{
status: 429,
headers: {
'Retry-After': String(Math.ceil((rl.resetAt - Date.now()) / 1000)),
'X-RateLimit-Limit': '30',
'X-RateLimit-Remaining': '0',
},
},
);
}
const config = getConfig();
if (!config.map) {