Secure the Session Cookie
Configure the Servlet Container so XWiki's session cookie only travels over HTTPS and stays out of reach of scripts in the page.
Steps
XWiki's session cookie identifies a signed-in reader for as long as the session lasts, so whoever copies it becomes that reader, by one of the routes Attack Vectors describes.
The Servlet Container sets that cookie, not XWiki, and most containers only mark it secure when the request that created it already arrived over HTTPS. Over plain HTTP it travels in the clear. Whether a container also sets httpOnly varies from one to the next. Both flags can be pinned on instead of left to the container's judgement.
- Open XWiki's web.xml, in the WEB-INF directory of the deployed web application, and add a session configuration just before the closing </web-app> tag.
<session-config> <cookie-config> <http-only>true</http-only> <secure>true</secure> </cookie-config> </session-config>Setting the same two flags in the Servlet Container's own configuration works as well and covers every application it hosts. On Tomcat that is its conf/web.xml.
- Restart the Servlet Container so that it reads the descriptor again. In the standalone distribution:
./stop_xwiki.sh ./start_xwiki.sh - Sign in again and read the response that creates the session.
curl -sD - -o /dev/null https://wiki.example.org/xwiki/bin/view/Main/ | grep -i set-cookieThe session cookie now carries both flags:
Set-Cookie: JSESSIONID=node0ji4skdcc81gg1g7v4bhaj9u6a14.node0; Path=/xwiki; Secure; HttpOnly
FAQ
Does XWiki not set these flags itself?
No. XWiki ships no session configuration at all, which leaves the session cookie entirely to the Servlet Container. The authentication cookies are a separate matter: XWiki sets those, and always marks them httpOnly.
Is a reverse proxy terminating HTTPS enough?
Yes for the browser, which only ever speaks HTTPS. The flags are about what the browser does with the cookie, so they are worth setting whether the container itself terminates HTTPS or a proxy in front of it does.