Skip to content

WW-5848 Make the Boot session cookie attributes configurable - #2144

Open
Matefodao3636 wants to merge 1 commit into
apache:mainfrom
Matefodao3636:WW-5848-boot-session-cookie-settings
Open

Matefodao3636 wants to merge 1 commit into
apache:mainfrom
Matefodao3636:WW-5848-boot-session-cookie-settings

Conversation

@Matefodao3636

Copy link
Copy Markdown

Fixes WW-5848

Summary

Adds the two settings the ticket proposes, read by BootSettings and applied by StrutsBootServer:

Key Default Accepted values
struts.boot.session.cookie.secure false true, false
struts.boot.session.cookie.sameSite lax lax, strict, none, unset

As with the other struts.boot keys, the value comes from struts.properties, and a --key=value argument overrides it.

Why

The starter opens a plain HTTP listener, so JSESSIONID is sent without Secure, and since WW-5841 SameSite=Lax is fixed in code. An application that runs behind an HTTPS reverse proxy had no setting to get Secure on its session cookie. Now it sets struts.boot.session.cookie.secure=true, and it can pick another SameSite value if it needs one.

Behaviour

  • The current defaults are preserved. With neither key set, the header is the same as before: SameSite=Lax, HttpOnly, no forced Secure.
  • secure is applied through SessionCookieConfig#setSecure, so it only reaches the session cookie.
  • sameSite stays on Rfc6265CookieProcessor#setSameSiteCookies, where WW-5841 put it. It is therefore still the default for every cookie of the context that has no SameSite attribute of its own, and unset makes the processor add none. The README and the Javadoc say so, and tests pin it.
  • Values ignore case and surrounding spaces. Any other value, an empty one included, stops startup with a ConfigurationException that names the setting and the value.
  • sameSite=none without secure=true is accepted, because Secure may be added by the proxy. The README states what has to hold at the browser.

Set-Cookie headers observed against the embedded Tomcat (session id replaced):

(no setting)                 JSESSIONID=<id>; Path=/; HttpOnly; SameSite=Lax
secure=true                  JSESSIONID=<id>; Path=/; Secure; HttpOnly; SameSite=Lax
sameSite=strict              JSESSIONID=<id>; Path=/; HttpOnly; SameSite=Strict
sameSite=unset               JSESSIONID=<id>; Path=/; HttpOnly
secure=true, sameSite=none   JSESSIONID=<id>; Path=/; Secure; HttpOnly; SameSite=None

Startup errors for invalid values:

Invalid struts.boot.session.cookie.secure: 'yes' is not true or false
Invalid struts.boot.session.cookie.sameSite: 'bogus' is not one of lax, strict, none, unset

Tests and docs

  • BootSettingsTest: 11 new tests covering the defaults, values from the file, argument over file, case and spaces, and invalid values from both sources.
  • StrutsBootTomcatTest: 12 new tests that start the server on loopback and read the real Set-Cookie header. They include cookies added by the application (new fixture CookieProbeAction) and startup failure on invalid values. testSessionCookieHasSameSiteLax became testSessionCookieDefaultsToSameSiteLaxWithoutSecure, which also asserts HttpOnly and the absence of Secure.
  • apps/boot-hello/README.md: both keys in the settings table, plus the notes above.
  • THREAT_MODEL.md §5: the defaults stay listed as framework-owned, now with the key that overrides each.

Validation

  • Linux, whole project: the patch applied to 1fcb942, and mvn verify finished with BUILD SUCCESS on all 30 modules. Of 5,313 tests, 5,312 passed and 1 was skipped (it needs a second network interface). testBaseDirIsOwnerOnly, which is skipped on Windows, ran and passed. That run predates the rewording of one README sentence; nothing else changed after it.
  • Windows 11, boot module: 75 tests, 74 passed and 1 skipped (testBaseDirIsOwnerOnly); the module had 52 before the change. The 24 tests of this change were also run against the original code: 13 fail, 4 pass because they describe behaviour that already existed, and 7 do not compile because they call the new accessors. These Windows runs needed a local one-line workaround that is not in this PR (see the last note below).

Notes for reviewers

  • Key name. sameSite follows the ticket. The neighbouring key is context-path, so same-site would also be consistent; it is easy to rename.
  • Empty value is an error, not a fallback to the default.
  • Unknown keys (for example struts.boot.session.cookie.samesite) are ignored, as before. The README now says so.
  • Outside this PR: at 1fcb942 the starter does not start on Windows. StrutsBootServer#createBaseDir throws "Cannot restrict the Tomcat base directory to its owner", because File.setWritable(true, true) returns false for a directory there. It is unrelated to WW-5848 and probably deserves its own ticket.

AI assistance

Disclosed following the ASF generative tooling guidance:

  • Implementation and tests: written with Claude Code (Anthropic, model Claude Fable 5.2).
  • Review: two independent rounds by GPT (OpenAI) and Gemini (Google), each without seeing the other's answer. Their findings were applied before this PR: the tests select the cookie by name, there are tests for application cookies and for values read from the file, and the docs are more precise.
  • Validation: the Linux build above was run by GPT in its own environment.
  • Human role: I set the scope, approved each step and decided to submit.

The change contains no third-party material; it only extends code already in the module.

🤖 Generated with Claude Code

Adds two struts.boot settings, read by BootSettings and applied by
StrutsBootServer:

- struts.boot.session.cookie.secure: true or false (default false)
- struts.boot.session.cookie.sameSite: lax, strict, none or unset
  (default lax)

The starter opens a plain HTTP listener, so the session cookie is sent
without Secure, and SameSite=Lax was fixed in code. An application that
runs behind an HTTPS reverse proxy can now set secure=true, and pick
another SameSite value if it needs one. The defaults are unchanged:
SameSite=Lax and no forced Secure.

Values ignore case and surrounding spaces. Any other value, an empty one
included, fails startup with a ConfigurationException that names the
setting and the value.

SameSite stays on Tomcat's cookie processor, as WW-5841 introduced it,
so it remains the default for every cookie of the context that has no
SameSite attribute of its own; Secure only reaches the session cookie.
Tests cover both, and the boot-hello README and THREAT_MODEL.md describe
it.

Implemented with Claude Code, reviewed in two independent rounds by GPT
and Gemini, and validated on Linux by GPT with the full project build.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant