説明
全体の security で API キーを要求する場合は、キーを送るすべてのリクエストに HTTPS を使います。
想定される影響
平文 HTTP では通信中にキーが漏れるおそれがあります。キーを URL に含めると、HTTPS でもログに残る場合があります。
対処方法
サーバーとクライアントで HTTPS を必須にし、キーはヘッダーで送ってログではマスクしてください。OpenAPI 3.0 は servers に HTTPS の URL、2.0 は schemes に https を指定します。
例
変更後の例では OAuth2 の read スコープに切り替えています。API キーを使い続ける場合にも同じ HTTPS 設定が必要です。
変更前
json
{
"openapi": "3.0.0",
"servers": [{"url": "http://api.example.com"}],
"security": [
{
"apiKeyAuth": []
}
],
"components": {
"securitySchemes": {
"apiKeyAuth": {
"type": "apiKey",
"name": "X-API-Key",
"in": "query"
}
}
}
}
変更後
json
{
"openapi": "3.0.0",
"servers": [{"url": "https://api.example.com"}],
"security": [
{
"OAuth2": [
"read"
]
}
],
"components": {
"securitySchemes": {
"OAuth2": {
"type": "oauth2",
"flows": {
"authorizationCode": {
"authorizationUrl": "https://example.com/oauth/authorize",
"tokenUrl": "https://example.com/oauth/token",
"scopes": {
"read": "read objects in your account"
}
}
}
}
}
}
}