`
sillycat
  • 浏览: 2552540 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Session Fixation Security Issue(2)Session Lost Problem

    博客分类:
  • JAVA
 
阅读更多
Session Fixation Security Issue(2)Session Lost Problem

1. First Problem.
When we click back space button, our browser will go from HTTPS to HTTP. And the sesssion created in HTTPS will not share with HTTP. So our session get lost here.
We can fix this problem, details are here http://sillycat.iteye.com/blog/1562131.

But from the official website of spring security, it suggest us not to do that, just let this problem there:
http://static.springsource.org/spring-security/site/faq.html#faq-tomcat-https-session

2. How can we face the 'repeat submit' problem

I go over the latest spring security 3.1.0 source codes, in this strategy, the related classes are here:
org.springframework.security.web.authentication.session.SessionFixationProtectionStrategy
org.springframework.security.web.session.SessionManagementFilter

I use these thread sleep codes in my action, the "repeat submit" problem will reproduce very easily.
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
log.error(e);
}

Log from my server:
06-26 09:59:16 [DEBUG] com.sillycat.easywebflow.filter.SessionFixationProtectionFilter.doFilter(SessionFixationProtectionFilter.java:71) - http-bio-443-exec-1 filter count = 1 sessionId_fromCookie=D79D7D2BFA59B418AFCE9988C7B940AF
06-26 09:59:16 [DEBUG] com.sillycat.easywebflow.filter.SessionFixationProtectionFilter.doFilter(SessionFixationProtectionFilter.java:112) - http-bio-443-exec-1 Invalidating session with Id D79D7D2BFA59B418AFCE9988C7B940AF start!
06-26 09:59:16 [DEBUG] com.sillycat.easywebflow.filter.SessionFixationProtectionFilter.doFilter(SessionFixationProtectionFilter.java:117) - http-bio-443-exec-1Invalidating session with Id D79D7D2BFA59B418AFCE9988C7B940AF end!
06-26 09:59:16 [DEBUG] com.sillycat.easywebflow.filter.SessionFixationProtectionFilter.doFilter(SessionFixationProtectionFilter.java:125) - http-bio-443-exec-1Started new session: B7A65024778B407FFAB964FCC69A6D03
06-26 09:59:16 [DEBUG] com.sillycat.easywebflow.filter.SessionFixationProtectionFilter.doFilter(SessionFixationProtectionFilter.java:129) - http-bio-443-exec-1getting session value from map: D79D7D2BFA59B418AFCE9988C7B940AF
GET username = null password = null sessionId = B7A65024778B407FFAB964FCC69A6D03
06-26 09:59:38 [DEBUG] com.sillycat.easywebflow.filter.SessionFixationProtectionFilter.doFilter(SessionFixationProtectionFilter.java:71) - http-bio-443-exec-2 filter count = 2 sessionId_fromCookie=B7A65024778B407FFAB964FCC69A6D03
06-26 09:59:38 [DEBUG] com.sillycat.easywebflow.filter.SessionFixationProtectionFilter.doFilter(SessionFixationProtectionFilter.java:112) - http-bio-443-exec-2 Invalidating session with Id B7A65024778B407FFAB964FCC69A6D03 start!
06-26 09:59:38 [DEBUG] com.sillycat.easywebflow.filter.SessionFixationProtectionFilter.doFilter(SessionFixationProtectionFilter.java:117) - http-bio-443-exec-2Invalidating session with Id B7A65024778B407FFAB964FCC69A6D03 end!
06-26 09:59:38 [DEBUG] com.sillycat.easywebflow.filter.SessionFixationProtectionFilter.doFilter(SessionFixationProtectionFilter.java:125) - http-bio-443-exec-2Started new session: AA6C79D5794A3E312B1AC679EA0E20D9
06-26 09:59:38 [DEBUG] com.sillycat.easywebflow.filter.SessionFixationProtectionFilter.doFilter(SessionFixationProtectionFilter.java:129) - http-bio-443-exec-2getting session value from map: B7A65024778B407FFAB964FCC69A6D03
GET username = null password = null sessionId = AA6C79D5794A3E312B1AC679EA0E20D9
06-26 09:59:38 [DEBUG] com.sillycat.easywebflow.filter.SessionFixationProtectionFilter.doFilter(SessionFixationProtectionFilter.java:71) - http-bio-443-exec-3 filter count = 3 sessionId_fromCookie=B7A65024778B407FFAB964FCC69A6D03
06-26 09:59:38 [DEBUG] com.sillycat.easywebflow.filter.SessionFixationProtectionFilter.doFilter(SessionFixationProtectionFilter.java:81) - http-bio-443-exec-3 how did this happen, there is no session!!!!!!!!!!!! + sessionId_fromCookie=B7A65024778B407FFAB964FCC69A6D03
GET username = null password = null sessionId = 0DCB304D4CC459BBF8D27B598D260DA7
06-26 09:59:38 [DEBUG] com.sillycat.easywebflow.filter.SessionFixationProtectionFilter.doFilter(SessionFixationProtectionFilter.java:71) - http-bio-443-exec-4 filter count = 4 sessionId_fromCookie=B7A65024778B407FFAB964FCC69A6D03
06-26 09:59:38 [DEBUG] com.sillycat.easywebflow.filter.SessionFixationProtectionFilter.doFilter(SessionFixationProtectionFilter.java:81) - http-bio-443-exec-4 how did this happen, there is no session!!!!!!!!!!!! + sessionId_fromCookie=B7A65024778B407FFAB964FCC69A6D03
GET username = null password = null sessionId = 3B97E2391A371BF696760570DEB3801C
06-26 09:59:39 [DEBUG] com.sillycat.easywebflow.filter.SessionFixationProtectionFilter.doFilter(SessionFixationProtectionFilter.java:71) - http-bio-443-exec-5 filter count = 5 sessionId_fromCookie=B7A65024778B407FFAB964FCC69A6D03
06-26 09:59:39 [DEBUG] com.sillycat.easywebflow.filter.SessionFixationProtectionFilter.doFilter(SessionFixationProtectionFilter.java:81) - http-bio-443-exec-5 how did this happen, there is no session!!!!!!!!!!!! + sessionId_fromCookie=B7A65024778B407FFAB964FCC69A6D03
GET username = null password = null sessionId = 05322091B48BD8E096B12E077B7602C6

We can easily find that, there are multi requests from the browser with the same old jsessionid, certainly, the first thread will invalidate the session with that old jsessionid. And the other requests, precisely the latest thread will lost all value/data, because it will go no where to find these value/data. The getSession(false) API will return null at that moment. And the browser will only remember the latest request.

We can go through the log message.
http-bio-443-exec-3 how did this happen, there is no session!!!!!!!!!!!! + sessionId_fromCookie=B7A65024778B407FFAB964FCC69A6D03

The thread exec-3 is executing with cookie value JSESSIONID=B7A65024778B407FFAB964FCC69A6D03, but this session is invalidated by exec-2. And the latest thread exec-5
http-bio-443-exec-5 how did this happen, there is no session!!!!!!!!!!!! + sessionId_fromCookie=B7A65024778B407FFAB964FCC69A6D03

exec-5 is doing the same thing as exec-3, certainly, empty session and null=session is what we get from getSession(false).

There is 2 ways to fix this problem if we really need to keep our session id changing strategy.
1. Avoid 'repeat submit' at server side. I just use the client side codes, but the end user can press the fresh button:
<script language="javascript">
    var submit=0;
    function CheckIsRepeat()
    {
        if (++submit>1)
        {
            return false;
        }
        var form = document.getElementById("loadingForm");
        form.submit();
        return true;
    }
&lt;/script&gt;<form action="../order/fetchprice.do" id="loadingForm">
</form>
<a href="###" class="button_refresh"></a>

This client side strategy is refused by QA, because they verify this by pressing the refresh button.

If I choose the server side way, when 'repeat submit' happen, I will redirect the end user to an error page to say 'Do not submit repeatly'. And there is really plenty work to do to generate token, store token in session, compare the token.

2. Another way is to make a local cache to store the session data, key is the session id, value is the session value map. And we need to refresh the map depend on time. If one value is not visited more than 5 seconds, I will remove that from local cache. This can solve our problem from my testing, but it is really wired. It seems that I am using a complex way to deal with session instead of web container.

3. Change to Deal with fixation session issue with other strategy.
Verify that additional information is consistent throughout session
if($_SERVER['REMOTE_ADDR'] != $_SESSION['PREV_REMOTEADDR']) {
   session_destroy(); // destroy all data in session
}
session_regenerate_id(); // generate a new session identifier
$_SESSION['PREV_REMOTEADDR'] = $_SERVER['REMOTE_ADDR'];

User Agent
if ($_SERVER['HTTP_USER_AGENT'] != $_SESSION['PREV_USERAGENT']) {
   session_destroy(); // destroy all data in session
}
session_regenerate_id(); // generate a new session identifier
$_SESSION['PREV_USERAGENT'] = $_SERVER['HTTP_USER_AGENT'];

references:
http://stackoverflow.com/questions/10637497/spring-security-session-management-session-fixation-protection-not-working
http://stackoverflow.com/questions/9004878/spring-security-3-1-0-cannot-switch-from-https-to-http
http://static.springsource.org/spring-security/site/docs/3.1.x/reference/springsecurity-single.html
http://static.springsource.org/spring-security/site/docs/3.1.x/reference/springsecurity-single.html#session-mgmt
http://static.springsource.org/spring-security/site/faq.html#faq-tomcat-https-session

http://www.blogjava.net/zhip/archive/2007/06/12/123510.html
http://my.oschina.net/CoderAJ/blog/16079

https://jira.springsource.org/browse/SEC-1462

分享到:
评论

相关推荐

    Session Fixation Test:安全会话固定测试-开源

    **会话固定攻击(Session Fixation)** 会话固定攻击是一种网络安全性问题,攻击者通过在用户登录前预先设定一个已知的会话ID(Session ID),然后在用户登录后继续使用这个固定的会话ID,从而能够控制或劫持用户的...

    spring security 3.x session-management 会话管理失效

    在Spring Security中,会话管理主要涉及到会话固定防护(Session Fixation Protection)和会话超时(Session Timeout)。 2. **会话固定防护** - 会话固定攻击是一种常见的安全威胁,攻击者通过获取用户的会话ID来...

    php session操作类

    2. **设置Session值**:类可能会提供一个`set_session_data`方法,接收键值对参数,将数据存储到Session中。这通常涉及到`$_SESSION`全局数组的使用。 3. **获取Session值**:为了读取已存储的Session数据,类可能...

    跨域共享session (实现http跳转https 共享session)

    2. **防止Session Fixation**:在用户成功登录后,重新生成session ID,避免攻击者利用预先知道的session ID进行攻击。 3. **定期刷新session**:设置合理的session超时时间,并在用户活动时更新session的最后活跃...

    spring security 2 配置说明

    标题与描述均提到了“Spring Security 2 配置说明”,这表明文章旨在阐述Spring Security 2版本的配置细节,尤其是对于那些希望深入了解并正确应用该框架的安全特性开发者们。以下将基于给定的部分内容,深入解析...

    Session实现用户存储

    在Web开发中,Session是一种非常...在实际开发中,还需要考虑到Session的过期策略、安全性(防止Session Hijacking和Session Fixation攻击)以及性能优化(如Session的持久化存储和集群环境下的Session共享)等问题。

    Spring Security2中设置Cookie的保存时间

    在Spring Security 2中,配置Cookie的保存时间是一项重要的任务,因为这关乎到用户的会话持久性和安全性。Cookie是Web应用程序中用于存储用户状态的一种机制,例如登录信息、个性化设置等。正确设置Cookie的生命周期...

    Spring Security 2 中文参考文档(chm)

    Spring Security提供了一套全面的会话管理机制,防止会话固定攻击(Session Fixation)和会话劫持(Session Hijacking)。它可以监控和控制会话创建、超时、复制和销毁。例如,SessionManagementConfigurer可以配置...

    session共享插件

    6. **安全性考虑**:使用memcached共享session时,需要注意安全问题,例如防止session hijacking(会话劫持)和session fixation攻击。可以使用HTTPS、定期刷新session ID、限制session的有效范围等方式增强安全性。...

    session过期问题

    5. **安全防护**:防止Session Hijacking(会话劫持)和Session Fixation(会话固定)攻击,定期更新Session ID,避免预测和重用。 综上所述,Session过期问题是Web开发中的重要环节,涉及到用户身份验证、用户体验...

    spring security和oauth2整合开发资料汇总

    3. **会话管理**:防止Session Fixation和Session Hijacking。 4. **过滤器链**:自定义的过滤器可以处理HTTP请求,执行认证和授权过程。 5. **CSRF防护**:防止跨站请求伪造攻击。 6. **表达式式访问控制**:使用...

    spring security2配置

    5. **会话管理**:Spring Security 还提供了会话管理功能,可以防止会话固定攻击(session fixation)和会话超时。通过`http.sessionManagement()`,我们可以设置会话策略,如`maximumSessionMax(1)`限制用户只能...

    Session登录注销

    在IT行业中,尤其是在Web开发领域,...在实际开发中,还需要考虑其他因素,如防止`session hijacking`(会话劫持)和`session fixation`(会话固定)攻击,以及优化`session`管理,避免过多的`session`占用服务器资源。

    springmvc session

    5. **Session Fixation Protection**: 为了防止 Session 固定攻击,Spring MVC 提供了自动的 Session 固定保护,当用户登录成功后,会自动创建一个新的 Session 并替换原有的 Session ID,避免恶意用户利用未过期的...

    J2EE的13种核心技术.pdf

    Java从最初的浏览器脚本语言逐渐进化成为服务器端开发的主流技术,其中J2EE(Java 2 Platform, Enterprise Edition)平台扮演了至关重要的角色。J2EE由一系列服务、APIs和协议组成,为基于Web的多层应用开发提供了...

    spring-security-oauth2与spring-security-web 3.1.2 源码

    3. **Session Management**: 提供了会话管理策略,如防止会话固定攻击(session fixation)、会话超时检测以及单点登录(Single Sign-On, SSO)支持。 4. **CSRF Protection**: 为了防止跨站请求伪造(Cross-Site ...

    Session

    - Session安全:防止Session Hijacking(会话劫持)和Session Fixation(会话固定)等攻击,需要确保Session ID的安全传输,避免被第三方截取或预测。 标签 "源码" 暗示了我们将深入到Session的实现代码层面。理解...

    spring spring security2.5 jar

    4. **会话管理**:Spring Security提供了会话管理功能,可以防止会话固定攻击(Session Fixation)、实现会话超时以及单点登录(Single Sign-On, SSO)。 5. **异常处理**:当安全规则不满足时,Spring Security会...

    spring-security-2.0.5.jar2

    1. 会话固定攻击防护:Spring Security提供防止Session Fixation的机制,当用户成功登录后,会生成新的会话ID,以确保会话的安全性。 2. 会话超时:可以通过配置设置会话的超时时间,过期后自动注销用户。 六、...

    spring-session-1.3.1.RELEASE.zip

    1.3.1.RELEASE 可能包含了针对会话固定攻击(Session Fixation)和其他会话相关的安全威胁的防护措施。同时,它也可能提供了更丰富的会话超时和过期策略,以防止非法会话的持续存在。 4. **性能优化**:针对大型高...

Global site tag (gtag.js) - Google Analytics