We can easily break CSRF of ZF2. If we remove the string after the hyphen(-
) the CsrfValidator
does not give any error and the token is successfully submitted.
For example CSRF token = 245454547kck-kjhjh2454dh
after editing the token token = 245454547kck-
ZF2 successfully submits the form, but it must give an error.
Can anyone check this and let me know if there is a solution for this issue.
For above scenario we use:
$csrfValidator = new CsrfValidator(array(
'name'=> 'token_name',//(here i used 'csrf' also)
'salt'=> 'test_salt',
));
$csrf = new CsrfElement('token_name');
$csrf->setCsrfValidator($csrfValidator);
$this->add($csrf);
$this->csrf = $csrf;
validator :
$inputFilter->add(
$factory->createInput(array(
'name' => 'token_name',
'required' => true,
'validators' => array(
$this->csrf->getCsrfValidator()
)
))
);
Please provide a solution.