Describe your bug or feature request.
The `QuantityWidget` does not appear to properly validate that the submitted quantity is a numeric value.
Although the widget uses Drupal's number element (`#type = number`), client-side HTML validation can easily be bypassed by submitting a crafted HTTP POST request directly.
We are observing automated requests targeting Drupal Commerce cart forms with malformed quantity values, for example:
```text
[quantity][0][value] = 1),'."(abcd
```
These values reach order item processing and price calculations, where they cause unhandled exceptions and errors.
This is not an exploitable issue by any means, but does fill up error logs unnecessarily.
If a bug, provide steps to reproduce it from a clean install.
Setup drupal, commerce and a product to sell.
1. Add a product to the cart using the standard Commerce add-to-cart form, but before submitting:
2. Open the brower console, change the quantity field to a text field and remove step/max/min properties
3. Replace the quantity value with a malformed string, for example `non-numeric-value`.
4. Submit the cart form.
5. Observe a fatal error being generated.
Expected behaviour:
Non-numeric quantity values should be rejected by server-side validation in the `QuantityWidget`, and give a form error instead of being passed down.
Proposed resolution
Add explicit server-side numeric validation to:
```php
public static function validateElement(array $element, FormStateInterface $form_state)
```
The validation should reject non-numeric quantity values before they are processed further.
Perhaps this is even a core number field widget issue?
| Comment | File | Size | Author |
|---|---|---|---|
| validate-quantity-field.patch | 886 bytes | weseze |
Comments