Pattern for string header is too loose

Description

The pattern for a string header is too loosely defined. It does not actually limit what can be included in the response header.

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 defined pattern is so loose that the response header can effectively include any string of any size and value:

"responses": {
  "200": {
    "description": "OK",
    "headers": {
      "x-ids": {
        "schema": {
          "type": "string",
          "pattern": ".*"
          }
        }
      }
    }
  }
}

Possible exploit scenario

Your API has been designed to return specific data. If you define too loose pattern for strings, you do not actually limit what can be included in response headers.

Attackers typically want to make the API to change its behavior and return different data than it is supposed to. A particular API failure might leak some other data, such as records or stack trace.

Locking down the pattern of strings in your response headers helps reduce this risk.

Remediation

Set a well-defined regular expression in the pattern field of the string header. This ensures that only strings matching the pattern can be included in the response header.

For example, the API below only accepts UUIDs that are compliant with RFC 4122:

"responses": {
  "200": {
    "description": "OK",
    "headers": {
      "x-ids": {
        "schema": {
          "type": "string",
          "pattern": "/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89AB][0-9a-f]{3}-[0-9a-f]{12}$/i"
          }
        }
      }
    }
  }
}