Skip to content

Commit 1c21e31

Browse files
author
hwyu@adobe.com
committed
MC-36035: Prevent input based resource allocation
- Removed min page size validation.
1 parent 535b9ef commit 1c21e31

File tree

6 files changed

+18
-67
lines changed

6 files changed

+18
-67
lines changed

app/etc/di.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,7 +1943,6 @@
19431943
</type>
19441944
<type name="Magento\Framework\Webapi\Validator\SearchCriteriaValidator">
19451945
<arguments>
1946-
<argument name="minimumPageSize" xsi:type="number">10</argument>
19471946
<argument name="maximumPageSize" xsi:type="number">300</argument>
19481947
</arguments>
19491948
</type>
@@ -1957,7 +1956,6 @@
19571956
</type>
19581957
<type name="Magento\Framework\GraphQl\Query\Resolver\Argument\Validator\SearchCriteriaValidator">
19591958
<arguments>
1960-
<argument name="minPageSize" xsi:type="number">10</argument>
19611959
<argument name="maxPageSize" xsi:type="number">300</argument>
19621960
</arguments>
19631961
</type>

lib/internal/Magento/Framework/GraphQl/Query/Resolver/Argument/Validator/SearchCriteriaValidator.php

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,16 @@
1717
*/
1818
class SearchCriteriaValidator implements ValidatorInterface
1919
{
20-
/**
21-
* @var int
22-
*/
23-
private $minPageSize;
24-
2520
/**
2621
* @var int
2722
*/
2823
private $maxPageSize;
2924

3025
/**
31-
* @param int $minPageSize
3226
* @param int $maxPageSize
3327
*/
34-
public function __construct(int $minPageSize, int $maxPageSize)
28+
public function __construct(int $maxPageSize)
3529
{
36-
$this->minPageSize = $minPageSize;
3730
$this->maxPageSize = $maxPageSize;
3831
}
3932

@@ -42,17 +35,10 @@ public function __construct(int $minPageSize, int $maxPageSize)
4235
*/
4336
public function validate(Field $field, $args): void
4437
{
45-
if (isset($args['pageSize'])) {
46-
if ($args['pageSize'] < $this->minPageSize) {
47-
throw new GraphQlInputException(
48-
__("Minimum pageSize is %min", ['min' => $this->minPageSize])
49-
);
50-
}
51-
if ($args['pageSize'] > $this->maxPageSize) {
52-
throw new GraphQlInputException(
53-
__("Maximum pageSize is %max", ['max' => $this->maxPageSize])
54-
);
55-
}
38+
if (isset($args['pageSize']) && $args['pageSize'] > $this->maxPageSize) {
39+
throw new GraphQlInputException(
40+
__("Maximum pageSize is %max", ['max' => $this->maxPageSize])
41+
);
5642
}
5743
}
5844
}

lib/internal/Magento/Framework/GraphQl/Test/Unit/Query/Resolver/Argument/Validator/SearchCriteriaValidatorTest.php

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,18 @@ class SearchCriteriaValidatorTest extends TestCase
2323
*/
2424
public function testValidValue()
2525
{
26-
$validator = new SearchCriteriaValidator(1, 3);
26+
$validator = new SearchCriteriaValidator(3);
2727
$field = self::getMockBuilder(Field::class)
2828
->disableOriginalConstructor()
2929
->getMock();
30-
$validator->validate($field, ['pageSize' => 1]);
31-
$validator->validate($field, ['pageSize' => 2]);
3230
$validator->validate($field, ['pageSize' => 3]);
3331
}
3432

35-
public function testValidInvalidMinValue()
36-
{
37-
$this->expectException(GraphQlInputException::class);
38-
$this->expectExceptionMessage("Minimum pageSize is 1");
39-
$validator = new SearchCriteriaValidator(1, 3);
40-
$field = self::getMockBuilder(Field::class)
41-
->disableOriginalConstructor()
42-
->getMock();
43-
$validator->validate($field, ['pageSize' => 0]);
44-
}
45-
4633
public function testValidInvalidMaxValue()
4734
{
4835
$this->expectException(GraphQlInputException::class);
4936
$this->expectExceptionMessage("Maximum pageSize is 3");
50-
$validator = new SearchCriteriaValidator(1, 3);
37+
$validator = new SearchCriteriaValidator(3);
5138
$field = self::getMockBuilder(Field::class)
5239
->disableOriginalConstructor()
5340
->getMock();

lib/internal/Magento/Framework/Webapi/ServiceInputProcessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public function __construct(
135135
$this->customAttributePreprocessors = $customAttributePreprocessors;
136136
$this->serviceInputValidator = $serviceInputValidator
137137
?: ObjectManager::getInstance()->get(ServiceInputValidatorInterface::class);
138-
$this->defaultPageSize = $defaultPageSize;
138+
$this->defaultPageSize = $defaultPageSize >= 10 ? $defaultPageSize : 10;
139139
}
140140

141141
/**

lib/internal/Magento/Framework/Webapi/Test/Unit/Validator/SearchCriteriaValidatorTest.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,16 @@ class SearchCriteriaValidatorTest extends TestCase
2424
public function testAllowsPageSizeWhenAboveMinLimitAndBelowMaxLimit()
2525
{
2626
$searchCriteria = new SearchCriteria();
27-
$validator = new SearchCriteriaValidator(1, 3);
27+
$validator = new SearchCriteriaValidator(3);
2828
$validator->validateEntityValue($searchCriteria, 'pageSize', 2);
2929
}
3030

31-
public function testFailsPageSizeWhenBelowMinLimit()
32-
{
33-
$this->expectException(InvalidArgumentException::class);
34-
$this->expectErrorMessage('Minimum SearchCriteria pageSize is 1');
35-
$searchCriteria = new SearchCriteria();
36-
$validator = new SearchCriteriaValidator(1, 3);
37-
$validator->validateEntityValue($searchCriteria, 'pageSize', 0);
38-
}
39-
4031
public function testFailsPageSizeWhenAboveMaxLimit()
4132
{
4233
$this->expectException(InvalidArgumentException::class);
4334
$this->expectErrorMessage('Maximum SearchCriteria pageSize is 3');
4435
$searchCriteria = new SearchCriteria();
45-
$validator = new SearchCriteriaValidator(1, 3);
36+
$validator = new SearchCriteriaValidator(3);
4637
$validator->validateEntityValue($searchCriteria, 'pageSize', 4);
4738
}
4839
}

lib/internal/Magento/Framework/Webapi/Validator/SearchCriteriaValidator.php

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,16 @@
1616
*/
1717
class SearchCriteriaValidator implements ServiceInputValidatorInterface
1818
{
19-
/**
20-
* @var int
21-
*/
22-
private $minimumPageSize;
23-
2419
/**
2520
* @var int
2621
*/
2722
private $maximumPageSize;
2823

2924
/**
30-
* @param int $minimumPageSize
3125
* @param int $maximumPageSize
3226
*/
33-
public function __construct(int $minimumPageSize, int $maximumPageSize)
27+
public function __construct(int $maximumPageSize)
3428
{
35-
$this->minimumPageSize = $minimumPageSize;
3629
$this->maximumPageSize = $maximumPageSize;
3730
}
3831

@@ -49,17 +42,13 @@ public function validateComplexArrayType(string $className, array $items): void
4942
*/
5043
public function validateEntityValue(object $entity, string $propertyName, $value): void
5144
{
52-
if ($entity instanceof SearchCriteriaInterface && $propertyName === 'pageSize') {
53-
if ($value < $this->minimumPageSize) {
54-
throw new InvalidArgumentException(
55-
__('Minimum SearchCriteria pageSize is %min', ['min' => $this->minimumPageSize])
56-
);
57-
}
58-
if ($value > $this->maximumPageSize) {
59-
throw new InvalidArgumentException(
60-
__('Maximum SearchCriteria pageSize is %max', ['max' => $this->maximumPageSize])
61-
);
62-
}
45+
if ($entity instanceof SearchCriteriaInterface
46+
&& $propertyName === 'pageSize'
47+
&& $value > $this->maximumPageSize
48+
) {
49+
throw new InvalidArgumentException(
50+
__('Maximum SearchCriteria pageSize is %max', ['max' => $this->maximumPageSize])
51+
);
6352
}
6453
}
6554
}

0 commit comments

Comments
 (0)