Description
In OpenAPI 3.0 security, use an empty array [] for apiKey and http schemes. List required scopes on oauth2 or openIdConnect schemes.
Potential impact
Listing scopes for an unsupported scheme can fail validation or prompt clients to request nonexistent permissions.
Remediation
Verify that each alternative matches the credentials and permissions the API accepts. For clients using the OAuth2 authorization code flow, use PKCE.
Examples
The document declares api_key and petstore_auth as alternative authentication schemes. The API key has no scopes. The OAuth2 alternative still requires both write:pets and read:pets.
Before
json
{
"openapi": "3.0.0",
"info": {
"title": "Simple API Overview",
"version": "1.0.0"
},
"security": [
{
"api_key": [
"write:api",
"read:api"
]
},
{
"petstore_auth": [
"write:pets",
"read:pets"
]
}
],
"paths": {},
"components": {
"securitySchemes": {
"api_key": {
"type": "apiKey",
"name": "api_key",
"in": "header"
},
"petstore_auth": {
"type": "oauth2",
"flows": {
"authorizationCode": {
"authorizationUrl": "https://example.org/api/oauth/dialog",
"tokenUrl": "https://example.org/api/oauth/token",
"scopes": {
"write:pets": "modify pets in your account",
"read:pets": "read your pets"
}
}
}
}
}
}
}
After
json
{
"openapi": "3.0.0",
"info": {
"title": "Simple API Overview",
"version": "1.0.0"
},
"security": [
{
"api_key": []
},
{
"petstore_auth": [
"write:pets",
"read:pets"
]
}
],
"paths": {},
"components": {
"securitySchemes": {
"api_key": {
"type": "apiKey",
"name": "api_key",
"in": "header"
},
"petstore_auth": {
"type": "oauth2",
"flows": {
"authorizationCode": {
"authorizationUrl": "https://example.org/api/oauth/dialog",
"tokenUrl": "https://example.org/api/oauth/token",
"scopes": {
"write:pets": "modify pets in your account",
"read:pets": "read your pets"
}
}
}
}
}
}
}