java - 避免会话劫持
问题描述
我正在使用下面的代码来避免会话劫持。
我能够成功登录,当我在登录后执行任何其他操作时,它会破坏我的会话并再次要求登录。
请建议,我做错了什么,我应该怎么做才能避免会话劫持。
<session-config>
<cookie-config>
<!-- <http-only>true</http-only> -->
<secure>true</secure>
</cookie-config>
<tracking-mode>COOKIE</tracking-mode>
</session-config>
解决方案
<http-only> true </http-only>
标签应该没有评论。同样的行为也可以在java端实现,比如
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// perform login checks and other validations
String sessionid = request.getSession().getId();
String contextPath = request.getContextPath();
response.setHeader("SET-COOKIE", "JSESSIONID=" + sessionid
+ "; Path=" + contextPath + "; HttpOnly; Secure");
response.sendRedirect("/some path");
}
推荐阅读
- javascript - 如何将 13 位时间转换为 10 位时间
- group-by - Oracle SQL Listagg 使用 case 语句条件删除重复项
- uml - 如何表示在序列图中调用其他对象/实体的自调用函数?
- ssl - 带有 NGINX 反向代理的上游服务器的不记名令牌。标题是否被剥离?
- javascript - 如何使用 React JsPDF 为空单元格添加边框?
- java - 在Java中,如果它们具有相同的名称,我们可以在派生类中访问父类的数据成员吗?
- r - 如何在一个 GGPlot 中绘制不同变量的两个直方图,带有图例和颜色
- powershell - Powershell 创建访问策略 Azure
- c# - 显示 400 的 ASP.NET Web 应用程序 (WebForms) 项目的 Api
- javascript - 拖放但替换为内联 svg