Description
Top-level security: [] leaves the API without a default authentication requirement. Individual operations can supply one.
Potential impact
Clients following this default may call a protected operation without credentials.
Remediation
If authentication is shared, reference a defined scheme in global security. Reserve exceptions for public operations and check that the server enforces the same policy.
Examples
security: [{exampleSecurity: []}] requires the exampleSecurity API key. The inner [] is its scope list, which is empty for API keys.
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"
}
}
}
}