Feature API accepts whitespace and control characters as user_id, and has no length limit

Aperta Adatta ai principianti
#40 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
66/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
fastapi, python, redis
Ambito
api, backend

Direzione di ricerca

Inizia con l'handler GET /features/{user_id} e il modello di richiesta POST /features/batch, che dichiara min_length=1, poi segui l'id dentro user_key(). Riproduci i casi di whitespace con i comandi curl nell'issue. Fatto significa che gli id composti solo da whitespace vengono gestiti allo stesso modo su entrambe le route (strip and reject, oppure strip and accept, come decide il maintainer) e che gli id oltre 255 caratteri vengono limitati, con i test di #39 aggiornati di conseguenza.

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

Descrizione

Follow-up from #39 (the new tests pin current behaviour; this is the part that looks like a bug).

What happens

GET /features/{user_id} declares the parameter as str and passes it straight to user_key() → HGETALL. Nothing trims or validates it, so:

request result
GET /features/%20 404, no features for user ' ' — a space is treated as a real key
GET /features/%09 404, tab is a real key
GET /features/%0A 404, newline is a real key
GET /features/<1024 chars> 404 — no length limit anywhere
POST /features/batch with "" 422 (min_length=1)
POST /features/batch with " " 200, then a normal miss

So the two endpoints disagree about what an empty id is, and on the path route a caller can create distinct Redis keys such as eddy:user: and eddy:user:\t simply by requesting them with a write-side call later (or by any producer that copies the id through).

Why it matters

  • Two users, or one user and one script, can be split across keys that differ only by invisible characters — silent cache misses and duplicated features.
  • No upper bound on the id length means one request can write an arbitrarily long key.

Reproduction

# after the service is up
curl -s -o /dev/null -w '%{http_code}\n' 'http://localhost:8000/features/%20'
curl -s -o /dev/null -w '%{http_code}\n' -X POST 'http://localhost:8000/features/batch' \
  -H 'content-type: application/json' -d '{"user_ids": ["   "]}'

Expected instead: strip or reject ids that are empty after .strip(), and cap the length (e.g. 255) consistently on both routes.

The tests added in #39 assert today's behaviour deliberately, so they will need updating once this is fixed.

Lingua principale
Python
Stelle
2
Fork
4
Merge medio
6h 43m
PR unite (30g)
2

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 midhunsomu/Feature_Store

Tutte le issue di midhunsomu/Feature_Store

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.