Repository navigation
Allow setting SameSite on the API session cookie - #612
justin-fritz wants to merge 5 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. |
- Always mark the API session cookie Secure when SameSite is None, also behind a TLS-terminating proxy in front of the HTTP connector - Log an invalid value as ERROR so it shows with the default log4j2 config - Use Locale.ROOT when parsing the value - Document the HTTPS requirement and the CSRF considerations in mirth.properties - Fix the Javadoc indentation Signed-off-by: justin-fritz <justin.fritz@amc-gmbh.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@pacmano1 Thanks for the thorough review, all four points are addressed in 039feb3:
The previous red build was a 429 (Too Many Requests) from Maven Central while resolving the dependency-check plugin, not a compile error. The build for the new commit is waiting for maintainer approval. @MichaelLeeHobbs Thanks, a TrustedProxyCustomizer sounds like the right fix for #578 and the proxy part of #600. I'd like to keep #612 small and handle that in a separate PR. Forcing Secure for SameSite=None doesn't conflict with it. |
|
I should have asked for this in the last review, sorry: please add a unit test. Nothing in CI sets Co-authored with Claude Code. |
Cover a blank or unset value, mixed case, Strict with a Turkish default locale, None forcing Secure, Lax and Strict not forcing Secure, and an invalid value leaving the attribute unset. createApiSessionHandler is now package-private and static so it can be tested without starting the web server. Signed-off-by: justin-fritz <justin.fritz@amc-gmbh.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@pacmano1 Added MirthWebServerSessionCookieTest in d9a2ffe. It covers a blank value, mixed case, Strict with a tr-TR default locale, None forcing Secure, Lax and Strict not forcing Secure, and a bad value leaving the attribute unset. To test it without starting the server, createApiSessionHandler is now package-private and static. I also checked that the Turkish locale test fails without Locale.ROOT. |
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