Make device codes single-use

Aperta
#11,873 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
56/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust, sql

Direzione di ricerca

Read the device_access_token_fetch documentation and trace the POST /device/token handler to the query that fetches the token from device_access_token. Add a nullable time_device_code_used column and make token retrieval set it only when it is still null, so concurrent polls cannot both succeed. Check the repository’s migration and endpoint test patterns; done when the first exchange succeeds and a second or concurrent use returns invalid_grant.

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

Descrizione

Followup to #11872. With that PR, POST /device/token returns expired_token once a device_code is more than 5 minutes old, but within those 5 minutes it returns the bearer token on every call. Anyone who gets the device_code in that window (from a log or a terminal recording, say) can fetch the token too. Not a huge deal given the 5 minute window, but ideally we would delete or invalidate the code the first time it's used.

RFC 8628 doesn't require single use. It only gives the code a lifetime (expires_in, §3.2). RFC 6749 requires it for authorization codes in the authorization code grant (§4.1.2). Our doc comment on device_access_token_fetch also calls the device code "a single-use high-entropy random token".

The token and the device_code are in one device_access_token row, so we can't delete the row after the exchange. The simplest design I can see is a nullable time_device_code_used column that POST /device/token sets in the query that fetches the token (UPDATE ... WHERE time_device_code_used IS NULL ... RETURNING), so two concurrent polls can't both get it. A second attempt to use the code could return invalid_grant (RFC 6749 §5.2).

Existing rows don't need the column backfilled because their codes expire in 5 minutes anyway (and a system upgrade takes longer than that).

Lingua principale
Rust
Stelle
630
Fork
110
Merge medio
2g 2h
PR unite (30g)
160

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 oxidecomputer/omicron

Tutte le issue di oxidecomputer/omicron

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.