博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Tomcat - Disable JSESSIONID in URL
阅读量:6932 次
发布时间:2019-06-27

本文共 2995 字,大约阅读时间需要 9 分钟。

I had a problem with a Java webapp that works within a Tomcat 6 container.

In fact when you block sites from setting any data inside your browser, Tomcat 6 rewrites the URL and add a JSESSIONID parameter in it. URL session IDs are sensible informations that shouldn't be transmitted via GET method for security concerns. It may also have a bad impact on SEO. Because sessionid is unique, multiple visits by the same search bot will return identical content with different URLs.

https://webapp.com/index.jsp;jsessionid=557206C363F1267A24AB769CA0DE4529.node01

Security is a major concern for our customers, and JSESSIONIDs appearing in the URLs freak them out (especially when they demonstrate that you can get a URL from the app, email it to someone else, and have that person magically bypass authentication and assume the role of the other user - of course as long as the session is still valid).

The thing is that URL-based session tracking is intended for web clients that do not support session cookies. Every browser worth mentioning supports these cookies, and almost nobody surfs with them disabled. Moreover we are comfortable saying that in order to use our application you need to have cookies enabled, so I'm making the assumption that if we disable the feature of putting JSESSIONID into the URLs cookie-based session setting/tracking will still function just as we expect it.

You have multiple solutions to disable URL rewriting :

1. 'disableURLRewriting' attribute

In Tomcat 6, you can disable URL rewriting by setting 'disableURLRewriting' attribute to true in your context.xml.

For this you have to make sure that attribute "cookies" in not set to false. This is the default.

  • Attribute cookies

  • Set to true if you want cookies to be used for session identifier communication if supported by the client (this is the default). Set to false if you want to disable the use of cookies for session identifier communication, and rely only on URL rewriting by the application.

  • Attribute disableURLRewriting

  • Set to true to disable support for using URL rewriting to track session IDs for clients of this Context. URL rewriting is an optional component of the servlet 2.5 specification but disabling URL rewriting will result in non-compliant behaviour since the specification requires that there must be a way to retain sessions if the client doesn't allow session cookies. If not specified, the specification compliant default value of false will be used.

2. "Servlet Filter"

You can use a servlet filter such as which allow you to rewrite URLs before they get to your code.

3. Switch to Tomcat 7 !

The Servlet 3.0 standard gives you two ways to disable URL session rewriting. This works in Tomcat 7, Glassfish v3, and any other Servlet 3.0-compliant servlet container. First, you can add this to your web.xml webapp config:

     
COOKIE

Or programmatically, you can use:

servletContext.setSessionTrackingModes(EnumSet.of(SessionTrackingMode.COOKIE));

转载地址:http://qcljl.baihongyu.com/

你可能感兴趣的文章
一道题来对mysql的连接查询复习
查看>>
架构之美阅读笔记之三
查看>>
Ferris教程学习笔记:js示例2.3 用循环将三个DIV变成红色
查看>>
supersr--class_copyIvarList和class_copyPropertyList的区别
查看>>
[转] js实现对图片的二进制流md5计算
查看>>
通联支付相关注意事项
查看>>
Postdoctoral Position
查看>>
JavaScript定义类的几种方式
查看>>
JavaScript 中 for in 循环和数组的问题
查看>>
[CQOI2013]新Nim游戏
查看>>
结队-五子棋游戏-项目进度
查看>>
WebSocket前后端实现
查看>>
JavaScript设计模式
查看>>
hasLayout原理【转】
查看>>
sql server 2008学习9 视图
查看>>
单身职场人士怎么利用晚上时间提高自己?
查看>>
零碎的java知识点记录(一)
查看>>
探路者团队-贪吃蛇(测评人:刘耀泽)
查看>>
用户组和用户的实际应用模拟板
查看>>
无参方法声明实现及调用
查看>>