説明
OpenAPI 3.0 の操作で Basic 認証を使うと、ユーザー名とパスワードが Base64 で符号化されて送られます。通信は HTTPS で保護してください。
想定される影響
HTTP で送ると、通信経路でパスワードが読み取られ、再利用されるおそれがあります。
対処方法
操作のサーバー URL を HTTPS にし、クライアントで証明書を検証してください。権限委任のため OAuth2 に移行する場合は、クライアントと認可サーバーで PKCE を使う認可コードフローを設定し、API でトークンと必要なスコープを検証します。
例
変更後の GET / は HTTPS を使い、OAuth2 の read スコープだけを要求します。
変更前
json
{
"openapi": "3.0.0",
"components": {
"securitySchemes": {
"regularSecurity": {
"type": "http",
"scheme": "basic"
}
}
},
"paths": {
"/": {
"get": {
"servers": [
{
"url": "http://myapi.com/"
}
],
"security": [
{
"regularSecurity": []
}
]
}
}
}
}
変更後
json
{
"openapi": "3.0.0",
"components": {
"securitySchemes": {
"OAuth2": {
"type": "oauth2",
"flows": {
"authorizationCode": {
"authorizationUrl": "https://myapi.com/oauth/authorize",
"tokenUrl": "https://myapi.com/oauth/token",
"scopes": {
"write": "modify objects",
"read": "read objects"
}
}
}
}
}
},
"paths": {
"/": {
"get": {
"servers": [
{
"url": "https://myapi.com/"
}
],
"security": [
{
"OAuth2": [
"read"
]
}
]
}
}
}
}