Operation sets security to an empty object

Distinguish an empty authentication requirement from an invalid security value and declare the intended policy.

Description

An operation’s security must be an array. security: {} is invalid. In OpenAPI 3.0, security: [{}] permits anonymous access.

Potential impact

The wrong type can fail validation. An unintended anonymous option can lead clients to omit credentials for a protected operation.

Remediation

For a protected operation, list its scheme and required scopes in the array. Omit the operation’s security field to inherit a suitable global policy. Use security: [] to document an operation that requires no authentication.

Examples

The example fixes GET / by requiring the OAuth2 read scope. Replace the sample OAuth2 URLs with your provider’s endpoints.

Before

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"
            }
          }
        }
      }
    }
  }
}

After

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"
            }
          }
        }
      }
    }
  }
}

References