Format of a numeric schema in a request is unknown
Issue ID: v3-schema-request-numerical-unknown-format
Average severity: Low
Description
The format you have defined for a numeric 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 property age
is set to be integer
but there is a typo in the format, rendering it unknown:
{
"post": {
"description": "Creates a new pet in the store",
"operationId": "addPet",
"requestBody": {
"description": "Pet to add to the store",
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/NewPet"
}
}
}
}
},
// ...
"NewPet": {
"type": "object",
"description": "JSON defining a Pet object",
"additionalProperties": false,
"required": [
"name"
],
"properties": {
"name": {
"type": "string"
},
"age": {
"type": "integer",
"format": "int3"
}
}
}
}
Possible exploit scenario
If you do not specify an enforceable format of numeric values, attackers can try to send unexpected input to your backend server. This may cause the backend server to fail in an unexpected way and open the door to further attacks.
For example, the backend server could throw an exception and return a stack trace on the error. The trace could contain information on the exact software stack used in the implementation. This enables the attacker to launch an attack on specific vulnerabilities known in that stack.
Using your internal, company-specific formats is not currently supported.
Remediation
Define a known format
for numeric properties in schemas. This ensures that only parameters of the expected format get passed to the backend.
Numeric parameters type integer
can have the format int32
or int64
. Numeric parameters type number
can have the format float
or double
.
{
"post": {
"description": "Creates a new pet in the store",
"operationId": "addPet",
"requestBody": {
"description": "Pet to add to the store",
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/NewPet"
}
}
}
}
},
// ...
"NewPet": {
"type": "object",
"description": "JSON defining a Pet object",
"additionalProperties": false,
"required": [
"name"
],
"properties": {
"name": {
"type": "string"
},
"age": {
"type": "integer",
"minimum": 0,
"maximum": 100,
"format": "int32"
}
}
}
}
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.