如何在 WildFly 20 上设置 Samesite cookie?

Ami*_*t P 3 cookies jboss wildfly undertow samesite

我需要在 WildFly20 服务器响应上将相同的站点 cookie 属性设置为“严格”。我需要通过服务器配置来完成此操作。有什么帮助吗?

Mar*_*ler 5

JMart 的答案是正确的,但需要将文件添加到您的 Web 应用程序 ( undertow-handlers.conf)。使用 WildFly 19.1 ( WFLY-13003 ) 及更高版本,您可以在 WildFly 中配置此功能,standalone.xml如下所示:

<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>
Run Code Online (Sandbox Code Playgroud)

这可以通过 WildFly 的 CLI 界面执行以下命令来实现:

/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
Run Code Online (Sandbox Code Playgroud)

  • 我相信上面你指的是standalone.xml而不是standalone.conf (2认同)