Tomcat - Disable JSESSIONID in URL

   Tomcat - Disable JSESSIONID in URL    

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.

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>好的,我现在需要处理用户关于--disable-gpu和--disable-chromium-sandbox这两个命令行参数的询问。首先,我得回忆这两个参数的作用,并确保信息准确。 用户可能是在运行基于Chromium的应用程序时遇到了问题,比如Electron应用或Chrome浏览器本身。我需要先分别解释每个参数的意义和用途。 对于--disable-gpu,我记得这是用来禁用GPU硬加速的。可能在某些情况下,用户的显卡驱动不兼容,导致应用崩溃或图形渲染问题。这时候禁用GPU可以作为一种排查手段。需要说明它适用于解决图形相关的问题,但长期使用可能会影响性能。 然后是--disable-chromium-sandbox,这个参数涉及沙箱安全机制。沙箱的作用是限制进程权限,防止恶意代码对系统造成破坏。禁用沙箱可能会带来安全风险,所以通常只在特定情况下使用,比如在Linux上权限不足时,或者调试需要。需要强调用户应谨慎使用,并仅在必要时临时启用。 接下来,我需要考虑用户可能的场景。比如,用户可能在开发Electron应用时遇到崩溃,或者在使用Puppeteer进行自动化测试时出现问题。这时候他们可能需要这些参数来绕过问题。但需要提醒他们这些只是临时解决方案,长期应修复根本原因。 另外,要确保回答结构清晰,分点说明每个参数的作用、适用场景和注意事项。同时,语言要口语化,避免技术术语过多,让用户容易理解。 最后,需要检查是否有遗漏的信息或可能的误解。比如,是否混淆了Chromium沙箱和其他类型的沙箱?是否需要提到具体的使用方法,比如在命令行中如何添加这些参数?可能需要补充示例,比如在启动Chrome时加上这些参数,或者如何在Electron应用中配置。 总之,回答要准确、实用,并强调安全性和正确使用场景,帮助用户解决问题同时避免潜在风险。</think>以下是对`--disable-gpu`和`--disable-chromium-sandbox`命令行参数的详细说明: --- ### 1. `--disable-gpu` **作用** 禁用应用程序的GPU硬件加速功能,强制使用软件渲染。 **适用场景** - 当应用程序(如基于Chromium的浏览器、Electron应用)因显卡驱动不兼容导致崩溃或显示异常时 - 在虚拟化环境或旧硬件中运行出现图形渲染问题 - 调试图形相关的崩溃问题时 **注意事项** $$性能影响 = \text{可能显著降低渲染速度}$$ 长期使用可能导致页面卡顿,建议仅作为临时解决方案。 --- ### 2. `--disable-chromium-sandbox` **作用** 关闭Chromium的沙箱安全机制,允许进程以更高权限运行。 **适用场景** - 在Linux系统上因权限配置问题导致应用无法启动时 - 调试需要绕过沙箱限制的特殊场景 - 某些Docker/容器环境中运行Chromium时 **注意事项** $$安全风险 \propto \frac{1}{\text{沙箱防护强度}}$$ 禁用后会显著降低安全性,可能被恶意代码利用,**生产环境绝对禁止使用**。 --- ### 典型使用案例 ```bash # Electron应用启动示例 electron --disable-gpu --disable-chromium-sandbox # Headless Chrome测试示例 chrome --headless --disable-gpu --no-sandbox ``` --- ### 关联知识补充 - **沙箱机制**:通过隔离进程权限实现纵深防御,Chromium每个标签页默认运行在独立沙箱中 - **GPU加速**:利用显卡处理CSS动画、WebGL等任务,可提升性能约$3\times$ - **替代方案**:更新显卡驱动、配置正确沙箱权限(推荐)比直接禁用更安全有效 建议优先通过`chrome://gpu`诊断GPU问题,或使用`--use-angle`选择渲染后端。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值