JSESSIONID †
JSESSIONID の secure 属性 †
- Cookie に格納されている JSESSIONID が外部に漏洩すると、第三者がセッションの横取りをすることができる
- それを防ぐために JSESSIONID に secure 属性をつける必要がある
HttpOnly? | Javascript による Ajax アクセスには JSESSIONID を付加しない |
secure | https ではない通信には JSESSIONID を付加しない |
- secure属性をつけないと、せっかくサイトを https にしても JSESSIONID を盗まれる可能性がある
- あるユーザが https://secureshop.example.com/ で買い物をしているとする。仮にクラッカーさんがブラウザとサーバ間のパケットを盗聴できても暗号化されていて JSESSIONID は盗めない
- そこで、クラッカーさんは、ユーザを別サイトに誘導して <img src="
"> を実行させる。すると、ブラウザは http で画像のリクエストを平文で送るので、これを盗聴できればリクエストに付加されている JSESSIONID を横取りして、ユーザの権限であんなことやこんなことができる。
Glassfish 4.1 のデフォルト設定 †
| HttpOnly? | secure |
http | ✓ | |
https | ✓ | ✓ |
デフォルト設定の設定場所 †
- HttpOnly?属性 は 実行インスタンスの設定で切り替えられる ([Server-Config]-[Virtual Server]-[server])
- Secure属性 は http-listener で "Security" (HTTPS) を選択すると付与される
明示的に secure 属性を設定する †
- cf. Oracle GlassFish Server 3.1 Application Deployment Guide Cookie Properties
- WEB-INF/glassfish-web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app error-url="">
<class-loader delegate="true"/>
<jsp-config>
<property name="keepgenerated" value="true">
<description>Keep a copy of the generated servlet class' java code.</description>
</property>
</jsp-config>
<session-config>
<cookie-properties>
<property name="cookieSecure" value="true"/>
<property name="cookieHttpOnly" value="true"/>
</cookie-properties>
</session-config>
</glassfish-web-app>
Apache を Reverse Proxy に使う場合 †
| Apache |
Browser ---(HTTPS)---> |mod_ssl mod_proxy_http| ---(HTTP)---> Glassfish
- みたいな感じのときには、Apache で JSESSIONID Cookie に secure 属性を付けて欲しい。
- もしも Glassfish 側で JSESSIONID Cookie に secure 属性をつけると、デバック用に Glassfish に直接繋いだときに、一切 Session が使えなくなる
- あるいは開発中でも
- こういうときには、Apache の mod_headers モジュールを使って HTTP RESPONSE HEADER を書き換えてあげればいい
Java#Glassfish