406 response should be defined for all GET, POST, PUT, PATCH, and DELETE operations

Description

One or more operations in your API are missing 406 responses. Operations should have 406 or default response defined if they do both of the following:

  • The operation defines a response that is not a 204 response.
  • The operation constrains the MIME type of the response.

For more details, see RFC 7231.

Example

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

1responses:
2  "200":
3    description: pet response
4    content:
5      application/json:
6        schema:
7          $ref: "#/components/schemas/Pet"
8

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

Make sure that all operations that define a response that is not 204 and that constrain the MIME type of the response have the 406 response defined too.

1responses:
2  "200":
3    description: pet response
4    content:
5      application/json:
6        schema:
7          $ref: "#/components/schemas/Pet"
8  # ...
9  "406":
10    description: Not Acceptable
11    content:
12      application/json:
13        schema:
14          $ref: "#/components/responses/406"
15

Copyright 42Crunch 2021