Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[HttpFoundation] NativeSessionStorage regenerate method wrongly sets storage as started #15799

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

iambrosi
Copy link
Contributor

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR

This PR fixes an error when regenerating session IDs for non-active sessions.
Right now, the session is flagged as started, no matter if the session ID was successfully regenerated or not, making the storage unable to start the session later on.

This also fixes a future error with PHP 7, which throws an error if a regeneration is attempted for non-active sessions.

session_regenerate_id(): Cannot regenerate session id - session is not active

The Session Storage should not be flagged as started if
`session_regenerate_id` fails. A common use case would be to attempt
regeneration before actually starting the session.
This is to avoid flagging the storage as started(done by
`loadSession()`) if the regeneration fails. Also, PHP 7 will throw an
error if a regeneration is attempted for non-active sessions.
@iambrosi iambrosi changed the title Test regenerate wrongly sets storage as started SessionStorage regenerate wrongly sets storage as started Sep 16, 2015
@iambrosi iambrosi changed the title SessionStorage regenerate wrongly sets storage as started [HttpFoundation] NativeSessionStorage regenerate method wrongly sets storage as started Sep 17, 2015
@iambrosi
Copy link
Contributor Author

Updated title to follow contribution standards.

@fabpot
Copy link
Member

fabpot commented Sep 22, 2015

👍

@@ -195,6 +195,11 @@ public function setName($name)
*/
public function regenerate($destroy = false, $lifetime = null)
{
// Cannot regenerate the session ID for non-active sessions.
if ('' === session_id()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

PHP 5.4 and newer should use session_status(). See start() method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed!

`session_status()` should be used in PHP >= 5.4 instead of `session_id()`.
@Tobion
Copy link
Contributor

Tobion commented Sep 22, 2015

👍

@Tobion
Copy link
Contributor

Tobion commented Sep 22, 2015

Status: Reviewed

@fabpot
Copy link
Member

fabpot commented Sep 28, 2015

Thank you @iambrosi.

@fabpot fabpot closed this Sep 28, 2015
fabpot added a commit that referenced this pull request Sep 28, 2015
…wrongly sets storage as started (iambrosi)

This PR was squashed before being merged into the 2.3 branch (closes #15799).

Discussion
----------

[HttpFoundation] NativeSessionStorage `regenerate` method wrongly sets storage as started

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

This PR fixes an error when regenerating session IDs for non-active sessions.
Right now, the session is flagged as _started_, no matter if the session ID was successfully regenerated or not, making the storage [unable to _start the session_](https://github.com/symfony/symfony/blob/6393ec31690a3ecc73e5f1f7ea2185cda7aba203/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php#L130-L132) later on.

This also fixes a future error with PHP 7, which throws an error if a regeneration is attempted for non-active sessions.

```
session_regenerate_id(): Cannot regenerate session id - session is not active
```

Commits
-------

8e6ef9c [HttpFoundation] NativeSessionStorage  method wrongly sets storage as started
This was referenced Oct 27, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants