OAuth徹底入門(1)

3.2.2. Processing the authorization responseにおけるredirect_uriの理解

初めてこのセクションを読んだ際、redirect_uriに関するコメントの意味が理解できませんでした。ので、ちょっと調べてみました。

本文中のコメント:

As an aside, why do we include the redirect_uri in this call? We’re not redirecting anything, after all. According to the OAuth specification, if the redirect URI is specified in the authorization request, that same URI must also be included in the token request. This practice prevents an attacker from using a compromised redirect URI with an otherwise well-meaning client by injecting an authorization code from one session into another. We’ll look at the server-side implementation of this check in chapter 9.

var form_data = qs.stringify({
  grant_type: 'authorization_code',
  code: code,
  redirect_uri: client.redirect_uris[0]
});

調査内容

redirect_uriの役割

リダイレクトURIをこの呼び出しに含める理由は、OAuthの仕様に基づくものです。認可リクエストでリダイレクトURIが指定されている場合、トークンリクエストにも同じURIを指定する必要があります。この手段は、攻撃者が意図的なクライアントと共に危険なリダイレクトURIを使用し、あるセッションから別のセッションへ認可コードを注入するのを防ぐためのものです。

redirect_uriの本質

OAuth 2.0の認証フローにおいて、redirect_uriは認証完了後のユーザーのリダイレクト先を指定するURLです。しかし、なぜトークンリクエストでredirect_uriを再度指定するのかというと、それはセキュリティ上の理由からです。この手順により、攻撃者が不正なコードやトークンを注入することを防ぎます。

学習教材

関連記事