説明
個別の操作のsecurity: []は全体の認証要件を解除し、その操作には認証が不要であると宣言します。公開する操作には有効ですが、保護すべき操作に誤って設定すると、仕様書と意図したポリシーが一致しなくなります。
想定される影響
全体の認証ポリシーだけを確認すると、個別の操作にある公開例外を見落とすおそれがあります。仕様書に従うクライアントが、その操作に認証情報を送信しない場合もあります。
対処方法
全体のポリシーを継承させるには、操作の空のsecurity項目を削除してください。異なる要件が必要なら、操作のsecurityに定義済みの方式と必要なスコープを指定してください。空の配列は意図的に公開する操作にだけ残し、サーバーのポリシーも確認してください。
例
次の例では、読み取り操作の空の配列を、OAuth2のreadスコープを要求する設定に変更します。例のOAuth2 URLは、実際のプロバイダーのURLに置き換えてください。
変更前
json
{
"openapi": "3.0.0",
"paths": {
"/": {
"get": {
"security": [],
"responses": {
"200": {
"description": "ok"
}
}
}
}
},
"security": [
{
"OAuth2": [
"read"
]
}
],
"info": {
"title": "Simple API overview",
"version": "1.0.0"
},
"components": {
"securitySchemes": {
"OAuth2": {
"type": "oauth2",
"flows": {
"authorizationCode": {
"authorizationUrl": "https://example.com/oauth/authorize",
"tokenUrl": "https://example.com/oauth/token",
"scopes": {
"read": "Read API versions"
}
}
}
}
}
}
}
変更後
json
{
"openapi": "3.0.0",
"paths": {
"/": {
"get": {
"security": [
{
"OAuth2": [
"read"
]
}
],
"responses": {
"200": {
"description": "ok"
}
}
}
}
},
"security": [
{
"OAuth2": [
"read"
]
}
],
"info": {
"title": "Simple API overview",
"version": "1.0.0"
},
"components": {
"securitySchemes": {
"OAuth2": {
"type": "oauth2",
"flows": {
"authorizationCode": {
"authorizationUrl": "https://example.com/oauth/authorize",
"tokenUrl": "https://example.com/oauth/token",
"scopes": {
"read": "Read API versions"
}
}
}
}
}
}
}