Skip to content

Commit 8aadc27

Browse files
committed
AC-1271: Add rate limiting for payment information endpoint and mutation
1 parent 5fa0df6 commit 8aadc27

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

lib/internal/Magento/Framework/App/Request/BackpressureValidator.php

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
use Magento\Framework\Exception\LocalizedException;
2020

2121
/**
22-
* Enforces backpressure for non-webAPI requests.
22+
* Enforces backpressure for non-webAPI requests
2323
*/
2424
class BackpressureValidator implements ValidatorInterface
2525
{
@@ -55,20 +55,12 @@ public function __construct(
5555

5656
/**
5757
* @inheritDoc
58+
* @throws LocalizedException
5859
*/
5960
public function validate(RequestInterface $request, ActionInterface $action): void
6061
{
61-
try {
62-
$areaCode = $this->appState->getAreaCode();
63-
} catch (LocalizedException $exception) {
64-
$areaCode = null;
65-
}
6662
if ($request instanceof HttpRequest
67-
&& in_array(
68-
$areaCode,
69-
[Area::AREA_FRONTEND, Area::AREA_ADMINHTML],
70-
true
71-
)
63+
&& in_array($this->getAreaCode(), [Area::AREA_FRONTEND, Area::AREA_ADMINHTML], true)
7264
) {
7365
$context = $this->contextFactory->create($action);
7466
if ($context) {
@@ -80,4 +72,18 @@ public function validate(RequestInterface $request, ActionInterface $action): vo
8072
}
8173
}
8274
}
75+
76+
/**
77+
* Returns area code
78+
*
79+
* @return string|null
80+
*/
81+
private function getAreaCode(): ?string
82+
{
83+
try {
84+
return $this->appState->getAreaCode();
85+
} catch (LocalizedException $exception) {
86+
return null;
87+
}
88+
}
8389
}

0 commit comments

Comments
 (0)