[
https://issues.apache.org/jira/browse/WW-5848?focusedWorklogId=1055096&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-1055096
]
ASF GitHub Bot logged work on WW-5848:
--------------------------------------
Author: ASF GitHub Bot
Created on: 16/Nov/26 19:04
Start Date: 16/Nov/26 19:04
Worklog Time Spent: 10m
Work Description: Matefodao3636 opened a new pull request, #2144:
URL: https://github.com/apache/struts/pull/2144
Fixes [WW-5848](https://issues.apache.org/jira/browse/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](https://www.apache.org/legal/generative-tooling.html):
- **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](https://claude.com/claude-code)
Issue Time Tracking
-------------------
Worklog Id: (was: 1055096)
Remaining Estimate: 0h
Time Spent: 10m
> Struts Boot: make the session cookie attributes configurable (Secure,
> SameSite)
> -------------------------------------------------------------------------------
>
> Key: WW-5848
> URL: https://issues.apache.org/jira/browse/WW-5848
> Project: Struts 2
> Issue Type: Improvement
> Components: Core
> Reporter: Lukasz Lenart
> Priority: Minor
> Fix For: 7.6.0
>
> Time Spent: 10m
> Remaining Estimate: 0h
>
> Follow-up to [WW-5841|https://issues.apache.org/jira/browse/WW-5841] (review
> of PR [#2117|https://github.com/apache/struts/pull/2117]).
> After WW-5841 the embedded Tomcat context in {{StrutsBootServer}} tracks
> sessions by cookie only and sets {{SameSite=Lax}} on the session cookie
> through a hard-coded {{Rfc6265CookieProcessor}}. The {{Secure}} attribute is
> never set.
> A Boot application has no way to change either value: there is no
> {{web.xml}}, {{StrutsBootApplication}} exposes only
> {{actions(ActionRegistry)}}, and {{BootSettings}} carries only
> {{struts.boot.port}}, {{struts.boot.address}} and
> {{struts.boot.contextPath}}. An operator who terminates TLS in front of Boot
> cannot mark the session cookie {{Secure}}, and an application that is
> embedded cross-site cannot switch {{SameSite}} to {{None}}.
> Proposal: two new {{struts.boot.*}} settings, read by {{BootSettings}} and
> applied in {{StrutsBootServer}} next to the existing session defaults:
> * {{struts.boot.session.cookie.secure}} — {{true}} or {{false}}, default
> {{false}} (Boot opens a plain HTTP listener by default; a browser drops a
> {{Secure}} cookie on {{http://}}). Applied via the servlet context's
> {{SessionCookieConfig#setSecure}}.
> * {{struts.boot.session.cookie.sameSite}} — {{lax}} (default), {{strict}},
> {{none}} or {{unset}}, the values Tomcat's {{SameSiteCookies}} accepts.
> Applied via {{Rfc6265CookieProcessor#setSameSiteCookies}}.
> Invalid values throw a {{ConfigurationException}} naming the setting and the
> value, as the other {{struts.boot.*}} settings do.
> Tests owed in {{StrutsBootTomcatTest}}: the defaults stay {{SameSite=Lax}}
> without {{Secure}}; {{secure=true}} adds {{Secure}}; {{sameSite=none}} and
> {{sameSite=strict}} are reflected in {{Set-Cookie}}; an invalid value fails
> startup. The Boot documentation page lists both settings, and
> {{THREAT_MODEL.md}} §5 keeps the defaults as the framework-owned values.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)