playframework / playframework/play1

Setting the httpOnly flag does not work when deployed in a servlet container

Open
#1,289 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
1.6k
Forks
671
Avg merge
12d 15h
Merged PRs (30d)
1

Description

Hello,

Play 1.5.x allows you to set the cookies as HttpOnly using this configuration:
application.session.httpOnly=true
It works well when starting Play framework, but not when packaging the application as WAR in a servlet container (we use Jetty for instance).

It seems that Play uses a dependency on servlet-api-2.5.jar, and in this version, the javax.servlet.http.Cookie class does not contain yet the httpOnly flag. It is only available in servlet API > 3.0:
https://docs.oracle.com/javaee/6/api/javax/servlet/http/Cookie.html

There are some "tricks" to append ";HTTPOnly;" to the path, but it also seems to have some side effects in some browser

To reproduce the issue, you need to simply create a Cookie in a Controller:

cookie.path = "/";
cookie.name = "TEST-NAME";
cookie.value = "TEST-VALUE";
cookie.domain = Http.Cookie.defaultDomain;
cookie.secure = false;
cookie.httpOnly = true;
Http.Response.current().cookies.put(cookie.name, cookie);

Then package as WAR and deploy it on a servlet container.

Once deployed, navigate to the Controller's page and using the browser dev tools, you will see that the httpOnly flag is not set on the cookie.
I don't know if upgrading to servlet 3.0 would have a lot of side effects though.

Fabien

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Controller reproduction described in the issue, the application.session.httpOnly setting, and the servlet-api-2.5 dependency while comparing standalone and WAR deployments on Jetty. Verify the deployed response with browser developer tools; done means cookies created with httpOnly=true retain the HttpOnly flag in a servlet container without breaking the existing deployment path.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.