我有一個關於CSRF安全性和登錄表單的問題。該表單的工作原理如下:如何CSRF保護張貼到另一個頁面的表單?
在主佈局中,視圖助手創建登錄表單,稍後還會在用戶通過身份驗證時顯示用戶特定的菜單。
// User menu viewhelper
public function authentication()
{
// Check if user is authenticated or not
$auth = Zend_Auth::getInstance();
if(!$auth->hasIdentity())
{
$form = new Application_Form_Login();
$form->setAction($this->_view->url(array('action' => 'login'), 'ucp', true));
return $form;
}
else
{
// return user specific menu
}
}
形式職位,以包含所有用戶的控制面板的邏輯,諸如進/出記錄和顯示用戶的特定信息的UcpController。
// loginAction in UcpController
public function loginAction()
{
if(Zend_Auth::getInstance()->hasIdentity())
{
$this->_redirect('/');
return;
}
$request = $this->getRequest();
$form = new Application_Form_Login();
if($request->isPost())
{
if($form->isValid($post = $request->getPost()))
{
// Do authentication stuff here.
}
}
$this->view->form = $form;
}
可悲的是,這種CSRF令牌無法匹配,我無能爲力的如何解決這個問題。我在這裏錯過了什麼嗎?我應該一起去除CSRF驗證嗎?提前
// The CSRF protection element as added to the login form
$this->addElement('hash', 'csrf',
array(
'ignore' => true
)
);
謝謝你的幫助是極大的讚賞:)
偉大的現在我遇到了一個問題,當我張貼小表單和憑據不正確,大表單加載導致2相同的形式加載在頁面上。當我提交大型表單時,令牌無法再次驗證。 –