我有一个关于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相同的形式加载在页面上。当我提交大型表单时,令牌无法再次验证。 –