400 response should be defined

Issue ID: response-400

Average severity: Medium

Description

One or more operations in your API are missing 400 responses. Because client-side errors cannot be excluded, all operations except HEAD operation should have 400 responses defined.

For more details, see RFC 7231.

Example

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

{
    "responses": {
        "200": {
            "description": "pet response",
            "schema": {
                "$ref": "#/definitions/Pet"
            }
        }
    }
}

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 400 responses for all operations except HEAD operations.

{
    "responses": {
        "200": {
            "description": "pet response",
            "schema": {
                "$ref": "#/definitions/Pet"
            }
        },
        // ...
        "400": {
            "description": "Bad request",
            "schema": {
                "$ref": "#/definitions/400"
            }           
        }
    }
}