🐛(Bug) AI user rate limit can be bypassed by spoofing X-Forwarded-For

Aperta
#3,047 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 3 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
django, python
Ambito
security

Direzione di ricerca

The bypass is in the custom get_ident used by the three AI throttle classes in src/backend/core/api/utils.py, which trusts the first X-Forwarded-For address and ignores NUM_PROXIES. Read how DRF's default get_ident uses NUM_PROXIES, then check the AI_ALLOW_REACH_FROM=public path that makes anonymous AI calls reachable. Done means the classes move to core/api/throttling.py, the custom get_ident is removed, and a test shows that changing X-Forwarded-For does not reset the anonymous AI quota.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

AI generated backend security

AIUserRateThrottle keys anonymous requests on the first X-Forwarded-For address, which the client controls: varying the header gives a new AI quota each time, and NUM_PROXIES (added by #3005) is ignored.
https://github.com/suitenumerique/docs/blob/c474db77245aba67600135e0cafd85fe80267994/src/backend/core/api/utils.py#L191-L198
It is only reachable anonymously with AI_ALLOW_REACH_FROM=public (not the default), and the per-document limit still applies.
Suggested fix: move the three AI throttle classes to core/api/throttling.py with no behaviour change, then delete the custom get_ident so that DRF's version honours NUM_PROXIES, which deployments must set for the fix to hold.
Keep this throttle keyed on the IP address: the anonymous cookie of #3005 can be renewed by the client, and these are paid LLM calls.

Lingua principale
TypeScript
Stelle
17k
Fork
705
Merge medio
4g 13h
PR unite (30g)
47

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di suitenumerique/docs

Tutte le issue di suitenumerique/docs

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.