Description
A pattern such as .* accepts any string, including an empty one.
Potential impact
If the server applies the same pattern, it may store a malformed code or pass it to a lookup that fails.
Remediation
Specify the permitted characters and length. Use ^ and $ to match the entire field when required. Apply the same rule on the server.
Examples
The example changes only code. Both fields now expect exactly 15 lowercase ASCII letters or digits.
Before
json
{
"openapi": "3.0.0",
"components": {
"schemas": {
"GeneralError": {
"type": "object",
"properties": {
"code": {
"type": "string",
"maxLength": 15,
"pattern": ".*"
},
"message": {
"type": "string",
"maxLength": 15,
"pattern": "^[0-9a-z]{15}$"
}
}
}
}
}
}
After
json
{
"openapi": "3.0.0",
"components": {
"schemas": {
"GeneralError": {
"type": "object",
"properties": {
"code": {
"type": "string",
"maxLength": 15,
"pattern": "^[0-9a-z]{15}$"
},
"message": {
"type": "string",
"maxLength": 15,
"pattern": "^[0-9a-z]{15}$"
}
}
}
}
}
}