Skip to content

[#2962] Jakarta EE: secure-session-cookie.disabled is ignored in Faces Production mode - #2963

Open
AndrewG10i wants to merge 4 commits into
apache:mainfrom
AndrewG10i:fix/2962-secure-session-cookie
Open

AndrewG10i wants to merge 4 commits into
apache:mainfrom
AndrewG10i:fix/2962-secure-session-cookie

Conversation

@AndrewG10i

@AndrewG10i AndrewG10i commented Nov 20, 2026 •

Copy link
Copy Markdown

Summary

Fixes #2962: [Bug] Jakarta EE: secure-session-cookie.disabled is ignored in Faces Production mode

This PR fixes an issue in EnvironmentLoaderListener where the org.apache.shiro.ee.secure-session-cookie.disabled=true configuration parameter was not respected when Jakarta Faces was running in Production mode (jakarta.faces.PROJECT_STAGE=Production).

Due to incorrect operator precedence in the existing condition, the Production check could bypass the explicit opt-out, causing Shiro to force the Secure attribute on the servlet container's session cookie.

Changes

  • Corrected the conditional expression in EnvironmentLoaderListener so the explicit opt-out applies regardless of the Jakarta Faces project stage.
  • Added ShiroSessionCookieIT to verify the behavior using two Production deployments with container-managed sessions.
  • Added a CreateSessionServlet test fixture that creates an HTTP session using request.getSession(true).
  • The integration tests inspect the raw Set-Cookie headers and verify that:
    • By default, the JSESSIONID cookie includes the Secure attribute.
    • With org.apache.shiro.ee.secure-session-cookie.disabled=true, Shiro does not force the Secure attribute.

Testing

Verified the regression before and after the fix:

  • Before the fix: The opt-out integration test failed, confirming the reported issue.
  • After the fix: Both integration test cases passed.

Executed from the repository root:

mvnw -B -ntp -pl :shiro-its-jakarta-ee -am verify `
  '-Dit.test=ShiroSessionCookieIT' `
  '-Dfailsafe.failIfNoSpecifiedTests=false' `
  '-Dtest=NoUnitTestsSelected' `
  '-Dsurefire.failIfNoSpecifiedTests=false' `
  '-DskipITs=false' `
  '-Dintegration.modes.skip=true' `
  '-Djapicmp-skip=true'

Contribution checklist

Licensing

AI Assistance

This contribution was prepared with the assistance of OpenAI Codex (GPT-6.2 Sol) for code analysis, implementation, and regression testing. The changes and test results were reviewed and validated by the contributor.

AndrewG10i and others added 3 commits November 20, 2026 20:26
- Group the Faces stage checks in EnvironmentLoaderListener so the explicit opt-out applies in Production. Previously, operator precedence let the Production check bypass the opt-out.
- Add ShiroSessionCookieIT to verify that the container-managed JSESSIONID cookie carries Secure by default and omits it when the opt-out is enabled.
@lprimak lprimak added this to the 3.1.0 milestone Nov 20, 2026
@lprimak

lprimak commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Thank you for your contribution, Andrew,

I removed the slow IT tests, as they added 2 deployments (x3 integration mode tests) which added much time to integration testing.
I also replaced the IT tests with fast unit tests.

@github-actions github-actions Bot added java Pull requests that update Java code tests labels Nov 20, 2026
@lprimak lprimak changed the title [#2962] - Fix for [Bug] Jakarta EE: secure-session-cookie.disabled is ignored in Faces Production mode [#2962] - Jakarta EE: secure-session-cookie.disabled is ignored in Faces Production mode Nov 20, 2026
@lprimak lprimak changed the title [#2962] - Jakarta EE: secure-session-cookie.disabled is ignored in Faces Production mode [#2962] Jakarta EE: secure-session-cookie.disabled is ignored in Faces Production mode Nov 20, 2026
@AndrewG10i

Copy link
Copy Markdown
Author

I removed the slow IT tests, as they added 2 deployments (x3 integration mode tests) which added much time to integration testing. I also replaced the IT tests with fast unit tests.

Ah, yes, makes total sense! I just went with the first testing option GPT suggested to confirm the regression and verify the fix.

@ToniAdreal ToniAdreal left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I independently verified this fix against current main (0b3f11f).

The diagnosis in #2962 is correct. On main, EnvironmentLoaderListener.java:178-182 reads (!disabled && !hasFacesContext()) || !Faces.isDevelopment(), so with disabled=true in Faces Production mode the trailing !Faces.isDevelopment() is true and setSecure(true) still runs. The regrouped condition !disabled && (!hasFacesContext() || !Faces.isDevelopment()) fixes exactly that case. I checked the other three quadrants as well. Disabled=false with no Faces context still enforces secure, disabled=false in Production still enforces secure, and disabled=false in Development still skips it. Default Production behavior is preserved.

The new unit test covers all four quadrants, and productionHonorsOptOut is a real regression test. Under the old condition it would call setSecure(true) and fail the never() verification, under the new one it passes. The verifyNoInteractions() assertion also pins down that the opt-out short-circuits before any Faces call. I also checked the only other isDevelopment() use in the module, SslFilter.computeEnabled(), and it uses a plain if/else, so this precedence shape does not recur there.

One non-blocking note: the PR description still describes the removed ShiroSessionCookieIT integration tests and the mvn verify command. Since those were replaced by the unit tests, updating the description would keep the record accurate.

Caveat: I have no JDK on this machine, so I did not execute the tests locally. I am relying on the Jenkins PR-merge check, which is green at this head.

@lprimak lprimak added the CLA label Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA java Pull requests that update Java code tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Jakarta EE: secure-session-cookie.disabled is ignored in Faces Production mode

4 participants