9

This issue is driving me insane, so maybe someone could help me understand what the issue is. I have a tomcat web application being fronted by HAProxy. HAProxy is also doing SSL offloading, and is configured to use sticky sessions. I am using Tomcat's session replication feature which seems to be working just fine. The sessions appear on both appservers.

For some reason, Tomcat is generating a new JSESSIONID for every single web request, and then copying the contents of the old session into the new session. That is to say, my session contents are still there within the new session, but a new ID is generated and sent back to the client. But it only does this for my web application. It does not do this for the /manager application.

I have tried every trick in the book, such as setting this in my context.xml:

<Valve className="org.apache.catalina.authenticator.BasicAuthenticator" changeSessionIdOnAuthentication="false" />

And setting these attributes on my Context element:

<Context path="/myapp" reloadable="false" override="true" useNaming="false" allowLinking="true" useHttpOnly="false" sessionCookiePath="/" sessionCookiePathUsesTrailingSlash="false">

And still, the result is the same. Tomcat generates a new session id with every request and copies the contents of the old session into the new id.

I would suspect it had something to do with HAProxy, except that the /manager application is also behind HAProxy and it does not exhibit this behavior.

Why is Tomcat doing this, and what can I do to prevent it?

4

3 に答える 3

9

Spring Security が原因であることが判明しました。Spring Security 3.1x を使用しています。デフォルトでは、認証された資格情報がユーザーのセッションに保存されます。また、セッション固定攻撃に対抗するために、ユーザーのセッションの内容を新しいセッション ID に自動的にコピーし、古いセッションを無効にします。

アプリケーションでセッションを使用する必要がないため、修正はセキュリティ構成の http 要素に次を追加することでした。

create-session="stateless"

うまくいけば、これは他の誰かの助けになります。

于 2013-01-24T01:36:27.380 に答える
4

ページを更新すると、新しいIDセッションで同じ問題が発生しました tomcat7サーバーでは、context.xmlに次のコードを追加するだけです:

<Valve className="org.apache.catalina.authenticator.BasicAuthenticator" changeSessionIdOnAuthentication="false" />

<Context path="/myapp" reloadable="false" override="true" useNaming="false" allowLinking="true" useHttpOnly="false" sessionCookiePath="/" sessionCookiePathUsesTrailingSlash="false">

これは私にとってはうまくいきます。

于 2015-01-28T21:04:19.420 に答える
1

あなたの問題が何であるか正確にはわかりませんが、確認することが2つあります。まず、Tomcat で jvmRoute を指定しましたか?

トムキャット server.xml

<Engine name="Catalina" defaultHost="localhost" jvmRoute="machine1">

Haproxy.cfg (jvmRoute を参照)

server machine1 SERVER_IP cookie machine1 check 

Tomcat はサーバーの名前を Cookie に追加するため、設定しないと問題が発生する可能性があります。

他に確認することは、この行をセクションweb.xmlに追加したことを確認することですweb-app

<distributable />
于 2013-01-22T19:48:16.617 に答える