Skip to content

Fix session cookie writes for string responses#3763

Open
Sanjay44NS wants to merge 2 commits into
spring-projects:mainfrom
Sanjay44NS:fix-3755
Open

Fix session cookie writes for string responses#3763
Sanjay44NS wants to merge 2 commits into
spring-projects:mainfrom
Sanjay44NS:fix-3755

Conversation

@Sanjay44NS
Copy link
Copy Markdown

@Sanjay44NS Sanjay44NS commented May 21, 2026

Summary

  • fix OnCommittedResponseWrapper so Spring Session commits once an explicitly zero content-length response performs a body write
  • add core regressions for string and empty-body cases that previously missed the early session commit path
  • include JDBC and Redis sample checks as proof-of-concept verification that a plain String response writes the SESSION cookie

Fixes #3755

Notes

  • the main fix is isolated to spring-session-core
  • the sample changes are included only as additional verification of the reported behavior
  • if you would prefer to keep the PR scoped to the core fix and regressions, I can drop the sample changes

Testing

  • .\gradlew.bat :spring-session-core:test --tests "org.springframework.session.web.http.OnCommittedResponseWrapperTests" --tests "org.springframework.session.web.http.SessionRepositoryFilterTests"
  • .\gradlew.bat :spring-session-core:build
  • .\gradlew.bat :spring-session-sample-boot-jdbc:integrationTest --tests "sample.BootTests.stringResponseSetsSessionCookie"
  • .\gradlew.bat :spring-session-sample-boot-redis:integrationTest --tests "sample.BootTests.stringResponseSetsSessionCookie"

Commit the session once an explicit Content-Length of 0 is followed by a body write so String responses still write the session cookie, including empty-body cases. Add regressions for the wrapper and filter paths that previously missed the early commit.

Signed-off-by: sanjay44ns <nunagondasanjay44@gmail.com>
Add plain String endpoints to the JDBC and Redis Boot samples and verify with MockMvc that the response sets the Spring Session cookie without falling back to JSESSIONID.

Signed-off-by: sanjay44ns <nunagondasanjay44@gmail.com>
@Sanjay44NS Sanjay44NS changed the title Add sample checks for string response session cookies Fix session cookie writes for string responses May 21, 2026
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Spring 7: Session cookie no longer set for Controller returning Strings

2 participants