How to set samesite cookie on WildFly 20?
Asked Answered
M

2

4

I need to set same site cookie attribute to Strict on WildFly20 server responses. I need to do it via server configuration. Any help ??

Mustang answered 26/11, 2020 at 6:45 Comment(2)
Did you got help? I would have the same issueTransfigure
Please refer wildfly.org/news/2020/05/04/WildFly-1910-ReleasedMustang
E
6

JMart's answer is correct but requires to add a file to your web-application (undertow-handlers.conf). With WildFly 19.1 (WFLY-13003) and above you can configure this feature in WildFly's standalone.xml as follows:

<subsystem xmlns="urn:jboss:domain:undertow:12.0" ...>
    <server name="default-server">
        ...
        <host name="default-host" alias="localhost">
            <location name="/" handler="welcome-content"/>
            <http-invoker http-authentication-factory="application-http-authentication"/>
            <!-- add the filter defined below -->
            <filter-ref name="samesite-cookie"/>
        </host>
    </server>
    ...
    <filters>
        <!-- configure samesite handler -->
        <expression-filter name="samesite-cookie" expression="samesite-cookie(mode=strict)"/>
    </filters>
</subsystem>

This can be achieved by executing the following commands via WildFly's CLI interface:

/subsystem=undertow/configuration=filter/expression-filter=samesite-cookie:add(expression="samesite-cookie(mode=strict)")
/subsystem=undertow/server=default-server/host=default-host/filter-ref=samesite-cookie:add
Environmentalist answered 1/6, 2022 at 8:51 Comment(2)
This is a better alternative. +1Applicatory
I believe in the above you meant standalone.xml rather than standalone.confBainite
D
3

As from WildFly19 you an add a handler to tune samesite cookie attributes.

The only thing you have to do is to add a file "undertow-handlers.conf" into your WEB-INF (or META-INF) folder.

The content of the handler could be something like this (i.e. to set mode to Lax):

samesite-cookie(mode=Lax, enable-client-checker=true, cookie-pattern=*)

The syntax is very flexible. In the above example the "enable-client-checker" and "cookie-pattern" parameters are optional.

You can take a look at Undertow feature announcement and at SameSiteCookieHandler javadoc to further understand.

You can also take a look at the Wildfly feature request, which explains the issue.

Darcie answered 18/5, 2021 at 5:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.