Secure and HttpOnly flags for session cookie Websphere 7
Asked Answered
G

3

10

In Servlet 3.0 complaint application servers I can set the HttpOnly and secure flags for the session cookie (JSESSIONID) by adding the following to the web.xml:

<session-config>
  <cookie-config>
    <secure>true</secure>
    <http-only>true</http-only>
  </cookie-config>
</session-config>

However, the application I'm working on is to be deployed in Websphere 7, which is Servlet 2.5 complaint and it fails to start if I add the above to the web.xml

Is there any other declarative way or setting in Websphere 7 configuration to turn on the HttpOnly and secure flags for the session cookie?

If not, what would be the best approach to accomplish that programmatically?

Gaal answered 8/2, 2012 at 12:14 Comment(0)
P
8

I think in WebSphere 7 you may have to delve into the administrative console. As ever the WebSphere documentation seems poor but seems to suggest setting the com.ibm.ws.security.addHttpOnlyAttributeToCookies property:

Both the Secure flag and the HTTPOnly flag are enabled by setting the WebSphere Application Server property: com.ibm.ws.security.addHttpOnlyAttributeToCookies.

I found this, which I hope is applicable to WAS7. Can you try please (I only have WAS 8 at the moment on my system):

JSESSIONID cookie:

Secure Flag:

The Secure flag can be set within the WebSphere Application Server administrative interface by selecting AppServer->[Server Name]->Web Container Settings->Session Management. Check the checkbox for “Restrict cookies to HTTPS Sessions”.

HTTPOnly Flag:

The HTTPOnly attribute cannot currently be set on this cookie. This is registered on the IBM site as APAR PK98436. The fix for this APAR is currently targeted for inclusion in Fix Packs 6.1.0.31 and 7.0.0.9, which are not yet available. With this APAR in place, the HTTPOnly flag can be set on the JSESSIONID cookie by way of the property name: com.ibm.ws.webcontainer.httpOnlyCookies. Refer to the following technote for instructions on enabling WebContainer custom properties.

The com.ibm.ws.webcontainer.httpOnlyCookies property is documented on the WAS 7 help site.

Polysepalous answered 8/2, 2012 at 12:28 Comment(3)
Thanks for the link. However, my uderstanding from it is that the JSESSIONID (among others) won't be affected by that property. Right?Gaal
Thanks. The second link I think is specific to Tivoli, isn't it? Where did you get the "Both Secure flag and HTTPOnly flag are enabled by ... " quote from ?Gaal
www-01.ibm.com/support/docview.wss?uid=swg21422185 - Have you tried these solutions?Polysepalous
W
3

To set Secure flag to JSESSIONID cookie (same for WebSphere 7.x and 8.x):

  • log in log in WebSphere admin console
  • Navigate to Server > Server types > WebSphere application servers
  • Click on server name (default is server1)
  • Click on link Web Container settings > Web Container
  • Click on link Session Management
  • Click on link Enable Cookies. This bit a litle bit confusing, you have to click on text not on the check box
  • select option (check box) Restrict cookies to HTTPS sessions
  • Save changes

To set HttpOnly flag in WebSphere 8.x to JSESSIONID cookie

  • log in log in WebSphere admin console
  • Navigate to Server > Server types > WebSphere application servers
  • Click on server name (default is server1)
  • Click on link Web Container settings > Web Container
  • Click on link Session Management
  • Click on link Enable Cookies. This bit a litle bit confusing, you have to click on text not on the check box
  • select option (check box) Set session cookies to HTTPOnly to help prevent cross-site scripting attacks
  • Save changes

To set HttpOnly flag in WebSphere 7.x to JSESSIONID cookie

  • log in log in WebSphere admin console
  • Navigate to Server > Server types > WebSphere application servers
  • Click on server name (default is server1)
  • Click on link Web Container settings > Web Container
  • Click on link Custom Proprties
  • Click on button New
  • Enter name: com.ibm.ws.webcontainer.httpOnlyCookies value:* (HttpOnly will be set on all cookies not only JSESSIONID)
  • Click on OK button
  • Save changes
Winne answered 27/1, 2016 at 10:57 Comment(0)
H
0

In WebSphere 7, you can find this in the administration console under Servers > WebSphere application servers > [Server Name] > Session management (under "Container Settings") > Enable cookies > Restrict cookies to HTTPS sessions.

Howell answered 22/4, 2014 at 16:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.