No default response defined for the operation

Issue ID: response-default-undefined

Average severity: Medium

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 in the OpenAPI definition. It can also be used to cover undeclared responses.

For more details, see the OpenAPI Specification.

Example

The following is an example of how this type of risk could look in your API definition:

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

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": "#/definitions/Pets"
                }
        },
        "default": {
            "description": "unexpected error",
            "schema": {
                "$ref": "#/definitions/Error"
            }
        }
    }
}