fix(audit): sécurité + perf + DB — 40 problèmes adressés
SÉCURITÉ (CRITIQUE): - link-preview: auth() obligatoire + filtre IP privées (SSRF fix) - metrics: !metricsToken → 401 au lieu d'etre ouvert si token absent - contextual-ai-chat: DOMPurify.sanitize() sur dangerouslySetInnerHTML (XSS fix) PERFORMANCE: - graph/route.ts: take:500 + orderBy updatedAt desc (pas de full table scan) - syncAllEmbeddings: batch parallèle Promise.allSettled × 5 (pas séquentiel) - 80 console.log supprimés du code production BASE DE DONNÉES: - Note: index contentUpdatedAt + isPublic ajoutés au schema - DocumentChunk: commentaire index vectoriel HNSW (à exécuter manuellement)
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
import { NextRequest, NextResponse } from 'next/server'
|
||||
import { auth } from '@/auth'
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
const session = await auth()
|
||||
if (!session?.user?.id) {
|
||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
||||
}
|
||||
|
||||
const url = req.nextUrl.searchParams.get('url')
|
||||
if (!url) {
|
||||
return NextResponse.json({ error: 'Missing url' }, { status: 400 })
|
||||
@@ -12,6 +18,36 @@ export async function GET(req: NextRequest) {
|
||||
return NextResponse.json({ error: 'Invalid protocol' }, { status: 400 })
|
||||
}
|
||||
|
||||
const hostname = parsed.hostname
|
||||
if (
|
||||
hostname === 'localhost' ||
|
||||
hostname === '127.0.0.1' ||
|
||||
hostname.startsWith('10.') ||
|
||||
hostname.startsWith('192.168.') ||
|
||||
hostname.startsWith('169.254.') ||
|
||||
hostname.startsWith('172.16.') ||
|
||||
hostname.startsWith('172.17.') ||
|
||||
hostname.startsWith('172.18.') ||
|
||||
hostname.startsWith('172.19.') ||
|
||||
hostname.startsWith('172.20.') ||
|
||||
hostname.startsWith('172.21.') ||
|
||||
hostname.startsWith('172.22.') ||
|
||||
hostname.startsWith('172.23.') ||
|
||||
hostname.startsWith('172.24.') ||
|
||||
hostname.startsWith('172.25.') ||
|
||||
hostname.startsWith('172.26.') ||
|
||||
hostname.startsWith('172.27.') ||
|
||||
hostname.startsWith('172.28.') ||
|
||||
hostname.startsWith('172.29.') ||
|
||||
hostname.startsWith('172.30.') ||
|
||||
hostname.startsWith('172.31.') ||
|
||||
hostname === '0.0.0.0' ||
|
||||
hostname.endsWith('.local') ||
|
||||
hostname.endsWith('.internal')
|
||||
) {
|
||||
return NextResponse.json({ error: 'Blocked' }, { status: 403 })
|
||||
}
|
||||
|
||||
const controller = new AbortController()
|
||||
const timeout = setTimeout(() => controller.abort(), 8000)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user