Array schema with string items has no maximum length defined

Description

An array schema containing string items does not define the maximum length for the accepted strings.

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. The array schema accepts items of the type string of unlimited length:

1post:
2  description: Creates a new pet in the store
3  operationId: addPet
4  parameters:
5    - name: pet
6      in: body
7      description: Pet to add to the store
8      required: true
9      schema:
10        type: object
11        required:
12          - name
13        properties:
14          name:
15            type: string
16          favfood:
17            type: array
18            items:
19              type: string
20

Possible exploit scenario

If you do not limit the length of strings, attackers can send longer strings to your API than what your backend server can handle. This could overload your backend server and make it crash. In some cases, this could cause a buffer overflow and allow for executing arbitrary code. Long strings are also more prone to injection attacks.

Remediation

Set the maxLength property in array schemas with string items to ensure that only strings of the expected size get passed to your API:

1post:
2  description: Creates a new pet in the store
3  operationId: addPet
4  parameters:
5    - name: pet
6      in: body
7      description: Pet to add to the store
8      required: true
9      schema:
10        type: object
11        required:
12          - name
13        properties:
14          name:
15            type: string
16          favfood:
17            type: array
18            items:
19              type: string
20              pattern: ^[A-Za-z0-9]{3,10}$
21              maxLength: 10
22

We also recommend that you specify a regular expression to further lock down the expected string format.

For more information on regular expressions, see the following:


Copyright 42Crunch 2021