2017-02-20 173 views
0

我在Zend Framework 2上有應用程序基礎。我有一個CSRF字段的表單。如果填寫表格並在大約5分鐘後提交,則會給我The form submitted did not originate from the expected site驗證錯誤。Zend Framework 2 CSRF驗證

所以我認爲這可能是會話配置的一些問題。然後,我添加選項SessionConfigmodule.config.phpfollows

'session' => array(
    'remember_me_seconds' => 2419200, 
    'use_cookies' => true, 
    'cookie_httponly' => true, 
    'cookie_lifetime' => '2419200', 
    'gc_maxlifetime' => '2419200' 
), 

但問題依然存在。你知道如何解決這個問題嗎?

--Update--

我的表單類包含CSRF要素如下,

$this->add(array(
     'type' => 'Zend\Form\Element\Csrf', 
     'name' => 'security', 
     'options' => array(
      'csrf_options' => array(
       'timeout' => 20000 
      ) 
     ) 
    )); 

這些都不似乎工作。

回答

1

ZendFramework下的跨站請求僞造系統配置從存儲在timeout項下的跨站請求僞造元件的結構參數中的會話持續時間,如圖以下示例:

$form->add([ 
    'type' => Element\Csrf::class, 
    'name' => 'csrf', 
    'options' => [ 
     'csrf_options' => [ 
      'timeout' => 600, 
     ], 
    ], 
]); 
+0

逸岸我已經這樣做了。我會更新這個問題。即使超時它也有問題。 – Ruwantha