Repository navigation
Allow setting SameSite on the API session cookie - #612
justin-fritz wants to merge 3 commits into
Conversation
Added a method to create a session handler for the REST API with SameSite cookie attribute support. Signed-off-by: justin-fritz <justin.fritz@amc-gmbh.com>
Added comments for session cookie SameSite attribute. Signed-off-by: justin-fritz <justin.fritz@amc-gmbh.com>
Added documentation for session cookie SameSite attribute configuration. Signed-off-by: justin-fritz <justin.fritz@amc-gmbh.com>
pacmano1
left a comment
There was a problem hiding this comment.
None needs Secure even when the engine sees HTTP. Behind a proxy that terminates TLS and forwards to the HTTP port (server.api.allowhttp), the cookie comes back SameSite=None without Secure. Chromium, Firefox and WebKit all drop it, so login returns 200 and the next call 401. Marking the session cookie Secure whenever None is configured fixes it in all three (tried it). Plain HTTP between the browser and the engine can't work with None either way. The OIE web client's Node server (1.3.0) on plain HTTP also still breaks, because it strips Secure. That one is on its side, and I'll raise it there.
Log bad values at ERROR. With the shipped log4j2.properties (root at ERROR) the "Invalid value" warning shows in neither mirth.log nor the console. Logged at ERROR it shows in both.
Uppercase with Locale.ROOT. On a JVM with -Duser.language=tr -Duser.country=TR, Strict comes back without the attribute. With Locale.ROOT it's set.
The mirth.properties comment should say that None needs HTTPS to the engine or its TLS proxy, and that with None the cookie goes along on other sites' form posts. So server.api.require-requested-with should stay on, and frame-ancestors should list only the sites that embed it.
Tested with the web admin WAR framed by another site: None fixes it in Chromium, Firefox already works with blank, and WebKit still fails with None.
Co-authored with Claude Code.
|
Great testing on this, especially running it in all three browser engines. One thought from someone who runs web servers behind TLS proxies every day: Forcing It's the same root cause as #578. #600 stops trusting a client-supplied Jetty 9.4's class TrustedProxyCustomizer implements HttpConfiguration.Customizer {
private final InetAddressSet trusted = new InetAddressSet();
private final ForwardedRequestCustomizer forwarded = new ForwardedRequestCustomizer();
TrustedProxyCustomizer(String[] proxies) {
for (String proxy : proxies) {
trusted.add(proxy.trim());
}
}
@Override
public void customize(Connector connector, HttpConfiguration config, Request request) {
InetSocketAddress peer = request.getHttpChannel().getEndPoint().getRemoteAddress();
if (peer != null && trusted.test(peer.getAddress())) {
forwarded.customize(connector, config, request);
}
}
}String[] proxies = mirthProperties.getStringArray("server.api.trustedproxies");
if (proxies.length > 0) {
httpConfig.addCustomizer(new TrustedProxyCustomizer(proxies));
}
With a proxy listed:
One thing for the docs: the proxy should overwrite One property closes #578, fixes the proxy case for #600, and fixes this cookie without a workaround. Happy to help test it behind nginx. |
Adds server.api.sessioncookie.samesite to configure the SameSite attribute of the REST API session cookie. Blank (default) keeps the current behavior. With None, the Web Admin works inside an iframe of a different site allowed by server.api.contentsecuritypolicy. Invalid values are logged and ignored.
Verified with Jetty 9.4.57: Set-Cookie: JSESSIONID=…; Path=/api; Secure; SameSite=None.
Closes #611