Numeric schema in a request has no maximum defined
Issue ID: v3-schema-request-numerical-max
Average severity: Medium
Description
A numeric schema has no maximum value 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. The property type
is set to integer
but the maximum value is not specified:
{
"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"
}
}
}
}
Possible exploit scenario
If you do not limit the range of accepted values for numeric parameters, 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.
Remediation
Set both the minimum
and maximum
values for numeric parameters to limit the accepted values to the range that works for your application:
{
"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"
}
}
}
}