Skip to content

Commit 6e1beda

Browse files
p0pr0ck5gelanivishal
authored andcommitted
Use constant time string comparison in FormKey validator
CSRF tokens should be considered sensitive strings. While the risk of a malicious actor attempting gleam the form key via a timing attack is very low, we should still follow best practices in verifying this token.
1 parent 2375461 commit 6e1beda

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

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

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

8+
use Magento\Framework\Encryption\Helper\Security;
9+
810
/**
911
* @api
1012
*/
@@ -32,9 +34,11 @@ public function __construct(\Magento\Framework\Data\Form\FormKey $formKey)
3234
public function validate(\Magento\Framework\App\RequestInterface $request)
3335
{
3436
$formKey = $request->getParam('form_key', null);
35-
if (!$formKey || $formKey !== $this->_formKey->getFormKey()) {
37+
38+
if (!$formKey) {
3639
return false;
3740
}
38-
return true;
41+
42+
return Security::compareStrings($formKey, $this->_formKey->getFormKey());
3943
}
4044
}

0 commit comments

Comments
 (0)