説明
OpenAPI 2.0 の accessCode など、トークンエンドポイントを使う OAuth2 フローでは、tokenUrl がトークンの要求先です。implicit フローではこのエンドポイントを使いません。
想定される影響
宛先が誤っているとトークンを取得できません。HTTP や誤った接続先を使うと、認証情報やトークンが漏れるおそれがあります。
対処方法
securityDefinitions の該当フローで、tokenUrl にプロバイダーの公式 HTTPS トークンエンドポイントを指定します。フラグメント(# 以降)を含めず、クライアントが想定したサーバーに接続して証明書を検証することを確認してください。
例
例で変更するのは accessCode の tokenUrl だけです。ユーザーのログイン先は authorizationUrl に指定します。
変更前
yaml
swagger: "2.0"
securityDefinitions:
petstore_auth:
type: oauth2
flow: accessCode
authorizationUrl: https://api.my.company.com/oauth/authorize
tokenUrl: http://example.com#@evil.com/
scopes:
write:pets: modify pets
read:pets: read pets
変更後
yaml
swagger: "2.0"
securityDefinitions:
petstore_auth:
type: oauth2
flow: accessCode
authorizationUrl: https://api.my.company.com/oauth/authorize
tokenUrl: https://api.my.company.com/oauth/token
scopes:
write:pets: modify pets
read:pets: read pets