Make device codes single-use

オープン
#11,873 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
56/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
rust, sql

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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).

主要言語
Rust
スター
630
フォーク
110
平均マージ
2日 2時間
マージ済み PR(30日)
160

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

oxidecomputer/omicron のほかの issue

oxidecomputer/omicron の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。