String parameter has no maximum length defined

Average severity: Medium

Description

Some string parameters in your API do not have the maximum length specified.

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:

{
  "parameters": {
     "in": "query",
     "name": "id",
     "type": "string",
     "description": "Identifier of the object to be extracted."
  }
}

Possible exploit scenario

If you do not limit the length of string parameters, 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 parameter to ensure that only strings of the expected size get passed to your API:

{
  "parameters": {
     "in": "query",
     "name": "id",
     "type": "string",
     "maxLength": "8",
     "description": "Identifier of the object to be extracted."
  }
}

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


Get API Security news directly in your Inbox.

By clicking Subscribe you agree to our Data Policy