Format of a string schema is unknown

Description

The format you have defined for a string schema does not match formats defined in either the OpenAPI Specification (OAS) or JSON Schema Specification. Unknown formats cannot be enforced to protect your API, so it is like you had not defined a format at all.

For more details, see the OpenAPI Specification and JSON Schema Validation.

Example

The following is an example of how this type of risk could look in your API definition. The format mail for the property userName is unknown and therefore does not restrict the accepted values:

1post:
2  description: Creates a new user
3  operationId: addUser
4  parameters:
5    - name: user
6      in: body
7      description: User to add
8      required: true
9      schema:
10        type: object
11        additionalProperties: false
12        required:
13          - name
14          - userName
15        properties:
16          name:
17            type: string
18          userName:
19            type: string
20            format: mail
21

Possible exploit scenario

If you do not define a known format for strings, no restrictions can be enforced and any string is accepted as the input. This could open your backend server to various attacks, such as SQL injection.

Using your internal, company-specific formats is not currently supported.

Remediation

Make sure that you only use known formats for strings. This ensures that only parameters of the expected format get passed to the backend.

1post:
2  description: Creates a new user
3  operationId: addUser
4  parameters:
5    - name: user
6      in: body
7      description: User to add
8      required: true
9      schema:
10        type: object
11        additionalProperties: false
12        required:
13          - name
14          - userName
15        properties:
16          name:
17            type: string
18          userName:
19            type: string
20            format: email
21

If you want to use your internal, company-specific format, make sure to also use properties like maximum, minimum, pattern, and maxLenght to constrain the accepted values.


Copyright 42Crunch 2021