Skip to content

Commit 727503d

Browse files
p0pr0ck5gelanivishal
authored andcommitted
Use constant time string comparison in FormKey validator
1 parent 92044eb commit 727503d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lib/internal/Magento/Framework/Data/Form/FormKey/Validator.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
*/
66
namespace Magento\Framework\Data\Form\FormKey;
77

8+
use Magento\Framework\Encryption\Helper\Security;
9+
10+
/**
11+
* @api
12+
*/
813
class Validator
914
{
1015
/**
@@ -29,9 +34,11 @@ public function __construct(\Magento\Framework\Data\Form\FormKey $formKey)
2934
public function validate(\Magento\Framework\App\RequestInterface $request)
3035
{
3136
$formKey = $request->getParam('form_key', null);
32-
if (!$formKey || $formKey !== $this->_formKey->getFormKey()) {
37+
38+
if (!$formKey) {
3339
return false;
3440
}
35-
return true;
41+
42+
return Security::compareStrings($formKey, $this->_formKey->getFormKey());
3643
}
3744
}

0 commit comments

Comments
 (0)