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

Skip to content

[Session] SessionInterface should have a destroy() method. Currently there is no way to simply destroy a session #12375

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
drscre opened this issue Nov 1, 2014 · 13 comments

Comments

@drscre
Copy link

drscre commented Nov 1, 2014

SessionInterface::invalidate() method starts a new session after invalidating the current one.

When PdoSessionHandler is used, this creates unnecessary db entries.

In my case sessions have long gc_maxlifetime (because they are used by mobile clients), so there is no way to close a session without generating implicit redundant db rows which stays there for a long time.

@Tobion
Copy link
Contributor

Tobion commented Nov 1, 2014

Yes I agree.

@parnas
Copy link
Contributor

parnas commented Nov 29, 2014

Working on this

@parnas
Copy link
Contributor

parnas commented Nov 29, 2014

488bc8b is the functionality for this. There are few issues though:

  • "destroy" method would need to be added to the interface (so BC break)
  • While docs for the "clear" method in interface defines itself as "Clear all session data in memory." NativeSessionStorage (and not only it) also calls loadSession() which reconnects bags back to the session), probably because right now handlers operate with the presumption that session always exists. I got around it by moving some of the functionality of it (that "destroy" reuses) to the new protected "clean" function, but I don't think that, logically, "loadSession" should be called in "clear" at all (which would be a BC break), or we can leave "clear" as it is now, and add "clean" to the interface, and update docblock comments.

@parnas
Copy link
Contributor

parnas commented Nov 29, 2014

Also, right now both "set" and "get" methods of session object will start up session. That seems to be logical for the "set", but probably behaviour should be changed for the "get" method.

@dbu
Copy link
Contributor

dbu commented Mar 10, 2015

+1, session needs a bunch of improvements. lets do the necessary BC breaks in symfony 3.0! (add to #11742?)

note that session_destroy does not remove the session cookie, only remove all data. but for caching, what we really need is to get rid even of the session cookie. maybe we could call the method remove() instead of destroy to avoid confusion.

and lets not mix this issue with the topic of fixing session behaviour to avoid accidental sessions. that is the topic of #6036 and there is #6388 which has been waiting for feedback for a long time.

i hope that #12325 can be pushed forward to clean up session handling in symfony in general.

@dbu
Copy link
Contributor

dbu commented Mar 10, 2015

btw, the workaround i currently use is $response->headers->clearCookie($request->getSession()->getName());

@geoffrey-brier
Copy link
Contributor

@dbu says it all, it's a real problem for caching.
If anyone is willing to write an RFC, I'd gladly write a PR :)
/cc @Tobion

@andypost
Copy link

andypost commented Sep 5, 2017

What it means "write rfc"?

@geoffrey-brier
Copy link
Contributor

@andypost something like that : #12325

@geoffrey-brier
Copy link
Contributor

Oh, juste stumbled upon http://symfony.com/doc/current/reference/configuration/security.html#logout-configuration and the delete_cookies node which fits my use case.

@alterphp
Copy link

@geoffrey-brier Do you finally use delete_cookies security logout option ? I can not make it work, or I need to inject if in a logout success handler...

@geoffrey-brier
Copy link
Contributor

@alterphp TBH I didn't implement something as only admin can log in, the impact was not that important.

But from what I remember, the delete_cookies would be too complicated to implement as I had a bunch of cookies and I figured that the easiest to do would be to manually clear ALL cookies in a logout success handler.

@alterphp
Copy link

@geoffrey-brier Thanks. I use a logout success handler too, as I can't make delete_cookies options do the job.

fabpot added a commit that referenced this issue Oct 16, 2017
…s-grekas)

This PR was merged into the 3.4 branch.

Discussion
----------

[HttpFoundation] Make sessions secure and lazy

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | yes
| Tests pass?   | not yet
| Fixed tickets | #6388, #6036, #12375, #12325
| License       | MIT
| Doc PR        | -

The `SessionUpdateTimestampHandlerInterface` (new to PHP 7.0) is mostly undocumented, and just not implemented anywhere. Yet, it's required to implement session fixation preventions and lazy write in userland session handlers (there is https://wiki.php.net/rfc/session-read_only-lazy_write which describes the behavior.)

By implementing it, we would make Symfony session handling much better and stronger. Meanwhile, doing some cookie headers management, this also gives the opportunity to fix the "don't start if session is only read issue".

So, here we are for the general idea. Now needs more (and green) tests, and review of course.

Commits
-------

347939c [HttpFoundation] Make sessions secure and lazy
@fabpot fabpot closed this as completed Oct 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants