Description
Each scheme named in Swagger 2.0 security must match a key in securityDefinitions.
Potential impact
An unresolved name can fail validation or leave a generated client without the credentials it needs to send.
Remediation
Define the scheme the server requires or fix its reference. For OAuth2, check the flow, URLs and scopes against the authorization server, then validate the document and compare each operation’s permissions.
Examples
The first example defines only api_key but requires petstore_auth. The second defines petstore_auth with the accessCode flow. Supply the real authorization and token URLs and check whether GET / needs both write:pets and read:pets.
Before
json
{
"swagger": "2.0",
"paths": {
"/": {
"get": {
"responses": {
"200": {
"description": "ok"
}
}
}
}
},
"security": [
{
"petstore_auth": [
"write:pets",
"read:pets"
]
}
],
"securityDefinitions": {
"api_key": {
"type": "apiKey",
"name": "api_key",
"in": "header"
}
},
"info": {
"title": "Simple API overview",
"version": "1.0.0"
}
}
After
json
{
"swagger": "2.0",
"paths": {
"/": {
"get": {
"responses": {
"200": {
"description": "ok"
}
}
}
}
},
"security": [
{
"petstore_auth": [
"write:pets",
"read:pets"
]
}
],
"securityDefinitions": {
"petstore_auth": {
"type": "oauth2",
"flow": "accessCode",
"authorizationUrl": "https://example.com/oauth/authorize",
"tokenUrl": "https://example.com/oauth/token",
"scopes": {
"write:pets": "modify pets in your account",
"read:pets": "read your pets"
}
}
},
"info": {
"title": "Simple API overview",
"version": "1.0.0"
}
}