No default response defined for the operation

Description

One or more operations in your API have no default response defined.

OpenAPI Specification (OAS) defines the default response as optional. It can be used as the default response object for all HTTP codes that are not covered individually by the API definition. It can also be used to cover undeclared responses.

For more details, see the OAS v2 or OAS v3.

Example

The following is an example of an API definition without the default section:

"responses": {
  "200": {
    "description": "Expected response to a valid request",
    "schema": {
      "$ref": "#/components/schemas/Pets"
    }
  }
}

Reusable components are referenced from #/definitions/ (OAS v2) or  #/components/ (OAS v3) sections.

Possible exploit scenario

Attackers strive to make your APIs behave in an unexpected way to learn more about your system or to cause a data breach. We highly recommend that you minimize any risks and clearly specify the data that your API operations can return for each possible response code.

Remediation

Define default responses for all API operations:

"responses": {
  "200": {
    "description": "Expected response to a valid request",
    "schema": {
      "$ref": "#/components/schemas/Pets"
    }
  },
  "default": {
    "description": "unexpected error",
    "schema": {
      "$ref": "#/components/schemas/Error"
    }
  }
}

Get API Security news directly in your Inbox.

By clicking Subscribe you agree to our Data Policy