Description
An empty object ({}) in the global security array makes anonymous access an option, even alongside other authentication schemes.
Potential impact
Clients see authentication as optional for operations that inherit this setting.
Remediation
If authentication is mandatory, remove {} from the array and reference the scheme the server requires. Keep security as an array. A bare security: {} is invalid.
Examples
The revised requirement calls for the X-API-Key header defined by exampleSecurity.
Before
json
{
"openapi": "3.0.0",
"paths": {
"/": {
"get": {
"responses": {
"200": {
"description": "ok"
}
}
}
}
},
"security": [
{}
],
"info": {
"title": "Simple API overview",
"version": "1.0.0"
},
"components": {
"securitySchemes": {
"exampleSecurity": {
"type": "apiKey",
"in": "header",
"name": "X-API-Key"
}
}
}
}
After
json
{
"openapi": "3.0.0",
"paths": {
"/": {
"get": {
"responses": {
"200": {
"description": "ok"
}
}
}
}
},
"security": [
{
"exampleSecurity": []
}
],
"info": {
"title": "Simple API overview",
"version": "1.0.0"
},
"components": {
"securitySchemes": {
"exampleSecurity": {
"type": "apiKey",
"in": "header",
"name": "X-API-Key"
}
}
}
}