November 20, 2018

Set HttpOnly and secure for Cookies in JBoss EAP 6 and 7

What is Cookie HttpOnly and secure?

Example

Set-Cookie: a=b; HttpOnly; SameSite=strict; secure

HttpOnly = No JavaScript

SameSite = no cross-origin cookie sharing

secure = SSL only

SameSite is not yet supported in all browser, see https://caniuse.com/#feat=same-site-cookie-attribute

JBoss EAP 6.x

Not supported to set globally. Best effort is deploy Servlet 3.0 web-fragment.xml and deploy overlay which is messy.

Next best in local application WEB-INF/web.xml.


<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">
...
    <session-config>
        <!-- Session timeout after X MINUTES after no user interaction. -->
        <session-timeout>15</session-timeout>
        <cookie-config>
            <http-only>true</http-only>
            <secure>true</secure>
        </cookie-config>
        <tracking-mode>COOKIE</tracking-mode>
    </session-config>
</web-app>

JBoss EAP 7.x

Edit standalone.xml


<subsystem xmlns="urn:jboss:domain:undertow:4.0">
...
    <servlet-container name="default">
...
        <session-cookie http-only="true" secure="true" />
    </servlet-container>
...
</subsystem>

No comments: