Operation security requirement references an undefined scheme

Make operation-level security requirements refer to the correct scheme.

Description

An operation’s security overrides the API’s global requirement. Define each name it references in components.securitySchemes.

Potential impact

Clients may send requests without the credentials the operation needs if they cannot resolve the scheme.

Remediation

Match the scheme and required scopes to what the server enforces for this operation. Use an empty scope list ([]) for types other than OAuth2 and OpenID Connect.

Examples

The example defines petstore_auth for GET /. Supply your provider’s HTTPS endpoints and configure PKCE in the client and authorization server. The pet scopes are illustrative. Require only the scopes each operation needs.

Before

json
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API overview",
    "version": "1.0.0"
  },
  "paths": {
    "/": {
      "get": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "security": [
          {
            "petstore_auth": [
              "write:pets",
              "read:pets"
            ]
          }
        ],
        "responses": {
          "200": {
            "description": "200 response",
            "content": {
              "application/json": {
                "examples": {
                  "foo": {
                    "value": {
                      "versions": [
                        {
                          "status": "CURRENT",
                          "updated": "2011-01-21T11:33:21Z",
                          "id": "v2.0",
                          "links": [
                            {
                              "href": "http://127.0.0.1:8774/v2/",
                              "rel": "self"
                            }
                          ]
                        }
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

After

json
{
  "openapi": "3.0.0",
  "info": {
    "title": "Simple API overview",
    "version": "1.0.0"
  },
  "paths": {
    "/": {
      "get": {
        "operationId": "listVersionsv2",
        "summary": "List API versions",
        "security": [
          {
            "petstore_auth": [
              "write:pets",
              "read:pets"
            ]
          }
        ],
        "responses": {
          "200": {
            "description": "200 response",
            "content": {
              "application/json": {
                "examples": {
                  "foo": {
                    "value": {
                      "versions": [
                        {
                          "status": "CURRENT",
                          "updated": "2011-01-21T11:33:21Z",
                          "id": "v2.0",
                          "links": [
                            {
                              "href": "http://127.0.0.1:8774/v2/",
                              "rel": "self"
                            }
                          ]
                        }
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "regularSecurity": {
        "type": "http",
        "scheme": "basic"
      },
      "petstore_auth": {
        "type": "oauth2",
        "flows": {
          "authorizationCode": {
            "scopes": {
              "write:pets": "modify pets in your account",
              "read:pets": "read your pets"
            },
            "authorizationUrl": "https://example.org/api/oauth/dialog",
            "tokenUrl": "https://example.org/api/oauth/token"
          }
        }
      }
    }
  }
}

References