Skip to content

LDEV-6447 Correct sessionInvalidate() lifecycle - #2804

Open
shane-tw wants to merge 1 commit into
lucee:7.0from
shane-tw:fix/LDEV-5942-invalidate-committed-session
Open

LDEV-6447 Correct sessionInvalidate() lifecycle#2804
shane-tw wants to merge 1 commit into
lucee:7.0from
shane-tw:fix/LDEV-5942-invalidate-committed-session

Conversation

@shane-tw

@shane-tw shane-tw commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Summary

sessionInvalidate() used create-if-missing HttpServletRequest.getSession() calls while invalidating and resetting a JEE session. Tomcat rejects session creation after the response is committed:

Cannot create a session after the response has been committed

It also eagerly created a replacement session before commit. A client could reuse that replacement JSESSIONID, even when the caller intended the session to be completely destroyed.

This change:

  • uses getSession(false) throughout invalidation so it never creates a servlet session merely to destroy it;
  • invalidates the existing JEE session after a committed response without creating a replacement;
  • stops eagerly creating replacement CFML and JEE sessions during sessionInvalidate();
  • lazily creates a clean session if CFML subsequently accesses SESSION; and
  • preserves sessionRotate() ID rotation and data migration.

The LDEV-4166 regression now verifies the actual contract: onSessionEnd runs synchronously for the invalidated session and no replacement session remains. Its previous session-count assertion accidentally encoded eager replacement behavior.

Validation

  • Added a servlet regression proving the original JEE session is invalidated, no replacement exists immediately afterward, and later SESSION access creates a clean session with a new ID.
  • Added servlet regressions for invalidation after commit with both an existing session and no existing session.
  • Confirmed the updated LDEV-4166 assertions fail on the previous implementation for both CFML and JEE sessions.
  • Focused Maven session suite passes: SessionInvalidate, LDEV-4166, and the LDEV-6046 memory case (4 tests passed; database and servlet-only cases skipped where their services were unavailable).
  • Java 11-targeted core and loader builds complete successfully.

Ticket: LDEV-6447

@shane-tw
shane-tw force-pushed the fix/LDEV-5942-invalidate-committed-session branch from 586f990 to 3364c03 Compare July 24, 2026 11:51
@shane-tw shane-tw closed this Jul 24, 2026
@shane-tw
shane-tw deleted the fix/LDEV-5942-invalidate-committed-session branch July 24, 2026 11:51
@shane-tw
shane-tw restored the fix/LDEV-5942-invalidate-committed-session branch July 24, 2026 11:53
@shane-tw shane-tw reopened this Jul 24, 2026
@shane-tw shane-tw changed the title LDEV-5942 Allow session invalidation after response commit LDEV-6447 Allow session invalidation after response commit Jul 24, 2026
@shane-tw
shane-tw force-pushed the fix/LDEV-5942-invalidate-committed-session branch from 3364c03 to da6ac61 Compare July 24, 2026 12:04
Avoid create-if-missing HttpSession calls during invalidation, including after a committed response. Do not eagerly create replacement sessions for sessionInvalidate(); subsequent SESSION access creates one lazily. Preserve sessionRotate() migration behavior.
@shane-tw
shane-tw force-pushed the fix/LDEV-5942-invalidate-committed-session branch from da6ac61 to 4c947f2 Compare August 5, 2026 10:28
@shane-tw shane-tw changed the title LDEV-6447 Allow session invalidation after response commit LDEV-6447 Correct sessionInvalidate() lifecycle Aug 5, 2026
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