2010年3月24日水曜日

jsessionidはURLリライトとCookieどっちが優先されるか

HttpServletRequest#getRequestSessionId()でURLに付加したjsessionidとCookieにセットしたjsessionidのどちらが取得されるのかという問題だが、sessionトラッキングのサーブレット仕様から考えてCookieが優先されるだろう(セキュリティ的にも)。


引用 Java Servlet 2.5 Maintenance Release 2 (抜粋)
==============================================

SRV.7.1.1 Cookies
Session tracking through HTTP cookies is the most used session tracking
mechanism and is required to be supported by all servlet containers.
The container sends a cookie to the client. The client will then return the
cookie on each subsequent request to the server, unambiguously associating the
request with a session. The name of the session tracking cookie must be
JSESSIONID.


SRV.7.1.3 URL Rewriting
URL rewriting is the lowest common denominator of session tracking. When a
client will not accept a cookie, URL rewriting may be used by the server as the basis
for session tracking. URL rewriting involves adding data, a session ID, to the URL
path that is interpreted by the container to associate the request with a session.
The session ID must be encoded as a path parameter in the URL string. The
name of the parameter must be jsessionid. Here is an example of a URL
containing encoded path information:
==============================================



でも一応試してみた。
javascriptのonloadで、actionURLにCookieに設定されているものとは異なるjsessionidを付加するコードを追加して、その画面のリクエスト時にサーバのHttpServletRequest#getRequestSessionId()でCookieとURLパラメータのどちらが取得されるか。


結果
 Tomcat6.0実装 Cookie
 Seaser2(2.4.25) 実装 Cookie
 Weblogic9.2実装 Cookie


まぁ予想通りの結果ですね。
ちなみにwebsphereは試していませんが、下記サイトにCookieが優先されると書いてあります。
http://www.cresc.co.jp/tech/java/Servlet_Tutorial/Lesson_53.htm











0 件のコメント:

コメントを投稿