Skip to content

Fix default session cookie name for non-alphanumeric APP_NAME#59588

Draft
vashukarn wants to merge 1 commit intolaravel:13.xfrom
vashukarn:fix/session-cookie-name-non-alphanumeric
Draft

Fix default session cookie name for non-alphanumeric APP_NAME#59588
vashukarn wants to merge 1 commit intolaravel:13.xfrom
vashukarn:fix/session-cookie-name-non-alphanumeric

Conversation

@vashukarn
Copy link
Copy Markdown

Summary

Fixes #59344. Since #56172 switched the default session cookie name from Str::slug(APP_NAME, '_') to Str::snake(APP_NAME), applications whose APP_NAME contains characters like [, ], ., or whitespace produce cookie names browsers refuse to round-trip. The result: every request creates a new session and authenticated users are silently logged out.

Examples from the issue:

  • APP_NAME="[LOCAL] My Awesome App"[_l_o_c_a_l]_my_awesome_app_session
  • APP_NAME="admin.domain"admin.domain_session

This wraps the snake-cased result in Str::slug(..., '_') so the resolved name is always restricted to RFC 6265–safe characters ([A-Za-z0-9_]) while preserving the snake_case style for normal APP_NAME values introduced in #56172.

  • My Appmy_app_session (unchanged)
  • [LOCAL] My Awesome Appl_o_c_a_l_my_awesome_app_session
  • admin.domainadmindomain_session

Test plan

  • New test file tests/Integration/Session/SessionCookieNameTest.php covering simple names, bracketed names, dotted names, and a regex check that the resolved name is always RFC 6265 safe across a variety of unsafe inputs.
  • All 4 new tests pass.

Since the switch to Str::snake() for the default session cookie name,
APP_NAME values containing characters like brackets or dots produced
cookie names with characters that browsers refuse to round-trip,
breaking session persistence and silently logging users out.

Wrap the result in Str::slug(..., '_') so the resolved cookie name is
always RFC 6265 safe while preserving the snake_case style for normal
APP_NAME values.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 8, 2026

Thanks for submitting a PR!

Note that draft PRs are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

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.

Default session naming using 'snake' breaks session with non-alphanumeric APP_NAME value

1 participant