💋

RFC6749 の 10.6. Authorization Code Redirection URI Manipulation について

2021/07/18に公開

RFC6749(The OAuth 2.0 Authorization Framework)10.6. Authorization Code Redirection URI Manipulationについて整理しました。

認可コードフロー


認可リクエストで指定した redirect_uri に認可レスポンスが返ってくる。クライアントは認可レスポンスに含まれる認可コードを使ってアクセストークンを取得する。

10.6. Authorization Code Redirection URI Manipulation

引用はすべて 10.6. Authorization Code Redirection URI Manipulation のものとなります。

攻撃の詳細

An attacker can create an account at a legitimate client and initiate the authorization flow. When the attacker's user-agent is sent to the authorization server to grant access, the attacker grabs the authorization URI provided by the legitimate client and replaces the client's redirection URI with a URI under the control of the attacker.

攻撃者はクライアントのアカウントを作成する。認可フローを開始し、クライアントが生成した認可リクエストの URI を取得する。攻撃者は取得した認可リクエストのリダイレクト URI を自身の管理する URI と入れ替えた認可リクエストを作成する。

The attacker then tricks the victim into following the manipulated link to authorize access to the legitimate client.

Once at the authorization server, the victim is prompted with a normal, valid request on behalf of a legitimate and trusted client, and authorizes the request. The victim is then redirected to an endpoint under the control of the attacker with the authorization code.

攻撃者は作成した URI を被害者に踏ませる。リダイレクト URI が入れ替えられているので認可レスポンスが認可コードとともに攻撃者の URI に送信される。

The attacker completes the authorization flow by sending the authorization code to the client using the original redirection URI provided by the client. The client exchanges the authorization code with an access token and links it to the attacker's client account, which can now gain access to the protected resources authorized by the victim (via the client).

攻撃者は攻撃者の管理する URI に送信された被害者に紐づく認可コードを、認可レスポンスとしてクライアントに送信する。クライアントは認可コードを使ってアクセストークンを取得するが、このアクセストークンは被害者のアクセストークンとなる。

この時点でクライアントは攻撃者のアカウントと被害者のアクセストークンを紐付けるため、攻撃者の操作によってクライアントがリソースサーバーに何かを操作すると、間接的に攻撃者が被害者のリソースを操作することができる。例えばクライアントがリソースサーバーから個人情報を取得して画面に表示した場合、攻撃者は被害者の個人情報を参照できる。

対策について

In order to prevent such an attack, the authorization server MUST ensure that the redirection URI used to obtain the authorization code is identical to the redirection URI provided when exchanging the authorization code for an access token. The authorization server MUST require public clients and SHOULD require confidential clients to register their redirection URIs. If a redirection URI is provided in the request, the authorization server MUST validate it against the registered value.

認可サーバーは認可コードを得るのに利用したリダイレクト URI と認可コードとアクセストークンを引き換える際に渡すリダイレクト URI が同じであることを確認しなければならない


クライアントは redirect_uri が攻撃者の URI になることを想定していないため、トークンリクエストで redirect_uri がミスマッチとなる。

認可サーバーへのパブリッククライアントのリダイレクト URI の登録を必須とし、コンフィデンシャルクライアントのリダイレクト URI の登録を推奨する。リダイレクト URI がクライアントから提供された場合、認可サーバーは事前に登録された値でその URI を検証しなければならない

攻撃者が redirect_uri を入れ替えた認可リクエストを認可サーバーが受け入れない。

GitHubで編集を提案

Discussion