Tomcat - Disable JSESSIONID in URL

本文介绍如何在Tomcat中禁用URL重写,避免敏感的JSESSIONID出现在URL中。提供了三种方法:修改context.xml文件中的'disableURLRewriting'属性;使用过滤器如Tuckey进行URL重写;升级到Tomcat7并利用Servlet3.0标准特性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://fralef.me/tomcat-disable-jsessionid-in-url.html

http://stackoverflow.com/questions/5276634/remove-jsessionid-in-url-rewrite-in-spring-mvc/5276689#5276689

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.

<?xml version='1.0' encoding='utf-8'?>
<Context docBase="PATH_TO_WEBAPP" path="/CONTEXT" disableURLRewriting="true">
</Context>

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 Tuckey which allow you to rewrite URLs before they get to your code.

Hide jsessionid for requests from googlebot.


<outbound-rule>
     <name>Strip URL Session ID's</name>
     <note>
         Strip ;jsession=XXX from urls passed through response.encodeURL().
         The characters ? and # are the only things we can use to find out where the jsessionid ends.
         The expression in 'from' below contains three capture groups, the last two being optional.
             1, everything before ;jesessionid
             2, everything after ;jesessionid=XXX starting with a ? (to get the query string) up to #
             3, everything ;jesessionid=XXX and optionally ?XXX starting with a # (to get the target)
         eg,
         from index.jsp;jsessionid=sss?qqq to index.jsp?qqq
         from index.jsp;jsessionid=sss?qqq#ttt to index.jsp?qqq#ttt
         from index.jsp;jsessionid=asdasdasdsadsadasd#dfds - index.jsp#dfds
         from u.jsp;jsessionid=wert.hg - u.jsp
         from /;jsessionid=tyu - /
     </note>
     <condition name="user-agent">googlebot</condition>
     <from>^(.*?)(?:\;jsessionid=[^\?#]*)?(\?[^#]*)?(#.*)?$</from>
     <to>$1$2$3</to>
 </outbound-rule>

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:

<session-config>
     <tracking-mode>COOKIE</tracking-mode>
</session-config>

Or programmatically, you can use:

servletContext.setSessionTrackingModes(EnumSet.of(SessionTrackingMode.COOKIE));
<think>好的,我需要解释用户提供的这个复杂的./configure命令。首先,我要分步骤解析每个参数的作用,确保理解正确。用户可能是在交叉编译FFmpeg,针对ARM架构的Linux系统,所以重点参数如--arch=arm和--cross-prefix需要注意。 接下来,检查每个禁用和启用的选项。例如,--disable-ffmpeg等是关闭不必要的程序,而--enable-swresample是启用必要的库。需要确认这些模块的作用,避免误解。比如,avcodec和avformat是核心库,必须启用。 然后,处理许可证相关的选项,如--disable-gpl和--enable-nonfree,这可能涉及法律问题,需要正确说明。另外,路径设置如--prefix=host和--shlibdir会影响安装位置,要解释清楚。 还要注意编译选项,如extra-cflags中的调试符号,说明这是为了调试目的。同时,交叉编译的相关参数需要明确解释其作用,比如交叉工具链的前缀。 需要确保回答结构清晰,分点说明每个部分的用途,帮助用户理解整个配置的目的。可能用户是想优化FFmpeg的编译,去除不必要的组件,专注于特定功能。因此,要强调各个禁用选项如何减少体积和依赖,以及启用的功能如何支持他们的目标平台。 最后,总结整个命令的目标,确保用户明白这是为ARM Linux生成一个精简且调试友好的FFmpeg库,适用于嵌入式环境。检查是否有可能的错误,比如重复的禁用选项或拼写错误,确保解释准确。</think>这是一个典型的FFmpeg库交叉编译配置命令,主要用于为ARM架构的Linux系统生成精简的媒体处理库。参数解析如下: --- ### **基础配置** 1. `--prefix=host` 指定安装目录为当前路径下的`host`文件夹 2. `--enable-cross-compile` 启用交叉编译(为目标平台生成代码) 3. `--arch=arm --target-os=linux` 目标平台为ARM架构的Linux系统 4. `--cross-prefix=arm-linux-gnueabihf-` 指定交叉编译工具链前缀(如使用`arm-linux-gnueabihf-gcc`) --- ### **功能裁剪** 1. **禁用工具集** ``` --disable-ffmpeg \ --disable-ffprobe \ --disable-ffplay \ --disable-programs ``` 关闭所有可执行程序的编译 2. **文档与符号** ``` --disable-symver \ --disable-doc \ --disable-htmlpages \ --disable-manpages \ --disable-podpages \ --disable-txtpages ``` 移除版本符号、所有文档 3. **模块精简** ``` --disable-avresample \ --disable-avfilter \ --disable-avdevice \ --disable-postproc \ --disable-hwaccels \ --disable-muxers \ --disable-indevs \ --disable-outdevs \ --disable-devices \ --disable-filters ``` 仅保留核心编解码、封装格式处理功能 --- ### **核心功能启用** 1. **关键组件** ``` --enable-swscale \ --enable-swresample \ --enable-avcodec \ --enable-avformat ``` 保留视频缩放、音频重采样、编解码器、媒体格式处理 2. **调试支持** ``` --enable-debug \ --extra-cflags="... -g -rdynamic -funwind-tables -ffunction-sections" ``` 添加调试符号和回溯支持 --- ### **编译优化** 1. `--enable-small` 启用空间优化(减少代码体积) 2. `--enable-shared` 生成动态链接库(.so文件) 3. `--libdir=host/static --shlibdir=host/dynamic` 静态库和动态库分别存放路径 --- ### **安全与许可** 1. `--disable-gpl --enable-nonfree` 禁用GPL协议代码,允许闭源组件 2. `--enable-openssl` 启用HTTPS协议支持 3. `--enable-pthreads` 启用多线程支持 --- ### **特殊处理** 1. `--disable-decoder=ssh264_ss268` 显式禁用特定解码器(可能涉及专利问题) 2. `--pkg-config=pkg-config` 指定使用系统的pkg-config工具 --- ### **总结** 该配置目标是: ✅ 为ARM-Linux生成精简的FFmpeg核心库 ✅ 支持动态/静态库分离存放 ✅ 包含调试信息便于问题追踪 ✅ 规避GPL协议限制 ❌ 移除了所有非必要组件(工具/硬件加速/输入输出设备等) 适用于嵌入式场景下的基础媒体处理需求。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值