2012-07-11 111 views
2

Mozilla能夠恢復我的Java EE銀行應用程序的會話(關於崩潰,恢復會話選項)。防止mozilla會話恢復

有沒有辦法通過編寫代碼來阻止mozilla恢復會話? 還是有可能確定出現在會話恢復中的請求,並強制用戶再次登錄?

回答

0

如果您需要的是無效的網頁瀏覽器崩潰後,你應該使用驅動緩存行爲的HTTP標頭:

<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE"> 
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE"> 
<META HTTP-EQUIV="EXPIRES" CONTENT="0"> 

M.

+0

謝謝,但即使添加上面的頭後,Firefox可以在崩潰後恢復會話。 – SunilGiri 2012-07-12 05:03:41

0

看起來像這樣還不存在(如2013年3月4日的)。希望瀏覽器開發人員能夠理解會話恢復會帶來安全漏洞。

2

我正在調查相同的問題。

正如我認爲讓瀏覽器恢復舊會話通常是一個壞主意。 然而,我嘗試了幾件事情,例如設置緩存控制標題,但這不適用於我。

所以我的確在考慮在腳本中解決這個問題。

但是,我看到不同的解決方案的問題。

1)刪除在瀏覽器關閉 餅乾 - >問題:你應該用JavaScript添加漏洞做到這一點,因爲http_only應該從0(當瀏覽器關閉設置爲false

2)設置cookie_lifetime)至例如3600(1小時)。 - >問題:將此設置爲高並且安全性丟失並將其設置爲低會給用戶提供'會話過期'錯誤消息,這意味着他們必須重新登錄。

3)添加第二個帶有效日期的cookie。如果cookie在那裏一切正常。 - >問題:是(幾乎)與2)相同,只有在設置cookie之後才能更改到期日期時,此功能纔有效。在這種情況下,用戶應保持活動至少XX分鐘,否則他會放鬆會話(對我來說似乎是正確的)。

我自己會看看後面的一個。

因此,在這種情況下,我使用PHP(不是Java),但我想總的想法是一樣的:

//create expiration cookie 
private function setExpireCookie(){ 

    //expire cookie: name, value, expiration in seconds, path, domain, https, http-only 
    setcookie("Test_Expire", "Expire", time()+3600, "/test", null, false, true); 
} 

//check if expiration cookie exits 
private function expireExists() { 

    return isset($_COOKIE['Test_Expire']); 

} 

//set the session check for expiration cookie 
private function getSession() { 

    //does the session cookie exists and the expiration cookie doesnt? 
    if (!$this->expireExists() && isset($_COOKIE['Test_Cookie'])) { 

     //to remove the cookie by setting the expiration time before now 
     setcookie("Test_Cookie", $_COOKIE['Test_Cookie'], time()-3600, "/test"); 
    } 

    //now we can set the new expiration cookies en start the new session 
    $this->setExpireCookie(); 

    //set cookie params: lifetime, path, domain, https, http-only 
    session_set_cookie_params(0, "/api", null, false, true); 

    session_name('Test_Cookie'); 

    //start session 
    session_start(); 
} 

此作品脫穎而出我。所以希望你可以申請這個在Java

+0

嘿! ;)沒有理由拒絕投票。我創建了一個工作:-) – BonifatiusK 2013-03-25 12:03:24

+0

感謝您的編輯,現在它已被撤消。 – 2013-03-25 15:52:29