My program uses Zend Framework, and I wanted to protect users from CSRF using Zend_Form_Element_Hash. But It doesn't seem to work.
For example, my code for Logout Form is
$exithash = new Zend_Form_Element_Hash('hihacker', array('salt' => 'exitsalt'));
$this->addElement($exithash);
In my Auth plugin for Controller I do
$exitForm = new R00_Form_Exit();
if ($exitForm->isValid($_POST)) {
R00_Auth::logout(); // a wrapper for Zend_Auth::getInstance()->clearIdentity();
Zend_Registry::get('Log')->info('User has logged out');
$this->setRedirect($request); // redirect to the current page
}
And in my layout
echo new R00_Form_Exit();
Okay. But it doesn't work, I click on submit button of the form, the page reloads but the identity still exists.
As I realized, Zend_Form_Element_Hash generates new hash value for each time form creates and сompares hash from user with the hash from session - the last generated hash! It's very strange. Even if I try, for example, create only one R00_Form_Exit in my application, store it in Registry and echo from it, opening a page from my site "in a new tab" will cause all such csrf-protected forms to stop working.
So, how do I protect?