String array item has no pattern defined

Average severity: Medium

Description

One or more arrays containing strings do not define any pattern for the accepted strings. This means that they do not limit the values that get passed to the API.

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 accepts items of the type string but their pattern is not defined:

{
  "parameters": [
  {
    "name": "ids",
    "in": "query",
    "description": "IDs to filter by",
    "required": true,
    "type": "array",
    "items": {
       "type": "string"
     }
  }
}

Possible exploit scenario

If you do not define a pattern for strings, any string is accepted as the input. This could open your backend server to various attacks, such as SQL injection.

Remediation

Set a well-defined regular expression in the pattern field of array items. This ensures that only arrays of strings matching the pattern get passed to your API.

For example, the API below only accepts IDs that are 6-digit values:

{
  "parameters": [
  {
    "name": "ids",
    "in": "query",
    "description": "IDs to filter by",
    "required": true,
    "type": "array",
    "items": {
       "type": "string",
       "pattern": "\d{6}"
     }
  }
}

Get API Security news directly in your Inbox.

By clicking Subscribe you agree to our Data Policy