Limites par IP non contournables (tmdb, ratings)
deploy / deploy (push) Successful in 1m2s

La plateforme transmet tel quel un en-tête X-Forwarded-For fourni par le
client (vérifié dans les journaux Supabase) : en changeant sa valeur à
chaque appel, un robot échappait à la limite par adresse IP des
fonctions tmdb et ratings. clientIp() n'utilise plus que les en-têtes
posés par la plateforme (cf-connecting-ip, puis x-real-ip).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YVo1qxKoBQCaMd7Ue8PGbe
This commit is contained in:
Claude committed 2026-12-01 18:52:13 +00:00
1 parent 3179d83850
commit 291132196a
4 files changed
+17 -9

No files matched your search

+2 -3
View File
@@ -6,7 +6,7 @@
// Une note plus ancienne est renvoyée tout de suite et rafraîchie en arrière-plan ; la correspondance
// TMDB → Trakt est gardée pour toujours (une seule requête à Trakt au lieu de deux).
import { corsHeaders, getUserId, json, rateLimited } from '../_shared/auth.ts'
import { clientIp, corsHeaders, getUserId, json, rateLimited } from '../_shared/auth.ts'
const TRAKT_KEY = Deno.env.get('TRAKT_CLIENT_ID') ?? ''
const SUPABASE_URL = Deno.env.get('SUPABASE_URL') ?? ''
@@ -127,8 +127,7 @@ Deno.serve(async (req) => {
if (userId) {
if (rateLimited('ratings:' + userId, 300, 10 * 60_000)) return json(req, 429, { error: 'rate' })
} else {
const ip = (req.headers.get('x-forwarded-for') ?? '').split(',')[0].trim() || req.headers.get('cf-connecting-ip') || 'inconnu'
if (rateLimited(`ratings-ip:${ip.slice(0, 64)}`, 400, 10 * 60_000)) return json(req, 429, { error: 'rate' })
if (rateLimited(`ratings-ip:${clientIp(req)}`, 400, 10 * 60_000)) return json(req, 429, { error: 'rate' })
}
const respond = (row: Row) =>