Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java安全会话_Java_Security_Session - Fatal编程技术网

Java安全会话

Java安全会话,java,security,session,Java,Security,Session,无论何时进行身份验证,应用程序都应更改其使用的会话标识符。这有助于防止有人设置会话、复制会话标识符,然后诱骗用户使用会话。因为攻击者已经知道会话标识符,所以他们可以在用户登录后使用该标识符访问会话,从而为用户提供完全访问权限。这种攻击被称为会话固定。用户登录到系统后,如何更改会话id 使当前会话无效并获取新会话: //invalidate the current session request.getSession().invalidate(); /* get another session a

无论何时进行身份验证,应用程序都应更改其使用的会话标识符。这有助于防止有人设置会话、复制会话标识符,然后诱骗用户使用会话。因为攻击者已经知道会话标识符,所以他们可以在用户登录后使用该标识符访问会话,从而为用户提供完全访问权限。这种攻击被称为会话固定。用户登录到系统后,如何更改会话id

使当前会话无效并获取新会话:

//invalidate the current session
request.getSession().invalidate();
/*
get another session and get the ID (getSession()) will create a session if one does not exist
*/
request.getSession().getId();

获取现有的;使其无效;创建一个新的

1使用HttpServletRequest.getSession获取当前会话; 2清除会话:HttpSession.invalidate;
3.创建一个新的:

一般来说,因为这根本不是Java问题,所以当会话ID很容易被发现或猜测时,这是一个普遍的web问题。例如,主要的攻击方法是会话ID位于页面的URL中。攻击者可以设置捕获会话,然后将链接嵌入其页面,诱使用户访问会话并成为会话的一部分。然后,当用户进行身份验证时,会话被验证。对此的缓解措施是不使用基于URL的会话ID,而是使用cookie

一些web应用程序将使用基于cookie会话的cookie,但从初始URL设置,例如,访问将在URL中看到会话id,然后从中创建会话cookie,将会话cookie中的id设置为123。缓解方法是在服务器上生成随机会话ID,而不使用任何用户输入作为生成器的种子

还有一些基于浏览器的漏洞利用,编码不好的浏览器会接受为非原始域的域创建cookie,但对此您无能为力。以及跨站点脚本攻击,您可以向受攻击的站点发送脚本命令以设置会话cookie,这可以通过将会话cookie设置为仅HTTP_来缓解,尽管Safari不遵守此标志

对于Java,一般建议是

session.invalidate();
session=request.getSession(true); 

但是,在JBoss上,有一点是不起作用的,因此您需要检查它在您选择的框架内是否按预期工作。

当您使会话无效时,您仍然在服务器上

//get stuff out of session you want before invalidating it.
currentSession = request.getSession(true);
UserProfile userProfile = (UserProfile) currentSession.getAttribute("userProfile");

//now invalidate it
currentSession.invalidate();

//get new session and stuff the data back in
HttpSession newSession = request.getSession(true);
newSession.setAttribute("userProfile", userProfile);

如果我使用这种方法,一旦用户登录,他将首先注销以重新生成idas blowdart声明:那么这恐怕是您使用的框架的一个限制。您能给出一个验证过程的代码示例吗?这可能会有所帮助。我尝试使用此方法,但用户将注销为session.invalidate被调用。这恐怕是您使用的框架的一个限制。我使用的是jsf和tomcat,所以有任何其他方法来解决此问题吗?即使OWASP页面也只有针对ASPWell和ASP.NET的反固定修复程序,这也不太令人担心,因为认证过程通常与会话分开。除非你自己滚了。我猜JSF在会话中存储身份验证信息,这就是为什么原始海报在重新生成会话时将其设置为丢失的原因,但我对该平台一无所知?是,我无法添加评论和回复邮件