Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[HttpFoundation] Subsequent calls to SessionStorageInterface::start() yield unnecessary set-cookie headers #42633

Copy link
Copy link
Closed
@bradjones1

Description

@bradjones1
Issue body actions

Symfony version(s) affected: 5.3

Description

Subsequent (n+1) calls to session_start() yield a set-cookie header, even when the session cookie is already present.

This bug is likely due to an underlying issue in PHP itself, however Symfony may wish to implement a workaround. Both of the referenced PHP issues are marked "Won't fix," but dating back to 2005-06. Perhaps it's time to reopen?

How to reproduce

As demonstrated in this proof of concept, open a session, do some business logic (including potentially reading or writing from the cookie) and then save the session. Reopen the session. Print a Response to the browser (optional.) Save the session. The last ::start() call prints a set-cookie header to the browser.

Important note: It's worth noting that this might also yield an unintended extension of the session, beyond what the site owner intended the length to be. Since the settings for the expiration time of the cookie are respected, every page subject to this condition gets refreshed. Since most session regimes intend to set the session cookie once (e.g., on login) this could result in, essentially, unlimited duration sessions if the user visits the affected page at least once before the expiration period.

Possible Solution

This comment proposes a workaround:

A workaround to this issue would be passing the session.use_cookies as false in the $options argument the 2nd time you use session_start(). This off course would only work for users of PHP7.

In Symfony, we could inspect NativeSessionStorage::$closed, and if it's TRUE, set this PHP ini option before (re-)opening.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.