Skip to content
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

No guarantee of session isolation with Symfony #163

Open
mathieudz opened this issue Jan 5, 2020 · 7 comments
Open

No guarantee of session isolation with Symfony #163

mathieudz opened this issue Jan 5, 2020 · 7 comments

Comments

@mathieudz
Copy link
Contributor

Currently PHP PM relies on Symfony to close the sessions properly. I already had two instances where that did not happen:

  • a bug where the session storage changed serializing method (PHP vs. igbinary) and thus crashed
  • a bundle (SchebTwoFactorBundle) that reads the session "on finish request", effectively reopening the session after SessionListener closed it.

Of course, these bugs need to be solved, but they should not be able to cause security issues. Luckily due to extensive use of session bound CSRF-like tokens, the website was hardly usable anymore and no harm was done. Otherwise, sessions would have leaked to other users, e.g. a regular user could have used an admin's session.

I suggest there should be some kind of session cleanup after each request. The only way to do that seems to be the save() method on the session.

@acasademont
Copy link
Contributor

@mathieudz this is one of the dangers of switching to a long running process like react-php/php-pm that manages more than one request. Developers need to be fully aware that the global state can't be trusted anymore.

Not sure php-pm can (or should) do something about it. We've had some recent discussions about how far should we (php-pm) try to go in fixing weird stuff caused by the long-running processes. How would this be best addressed?

@mathieudz
Copy link
Contributor Author

I agree this is an inherent problem, but the security consequences of this specific case are huge.
I would check the session service after each request and if it's open, close it (by saving it). In the former case it would crash (which is good), in the second case it would close the session properly.
I have an event listener now that does it in my own code, so I don't need any change in PHP PM, but I think it would be a good idea for PHP PM to do such a basic check.

@mathieudz
Copy link
Contributor Author

FYI, this is my workaround:

    public function onFinishRequest(FinishRequestEvent $event): void
    {
        $request = $event->getRequest();
        if ($request->hasSession() && $request->getSession()->isStarted()) {
            $this->logger->warning('Session not closed when processing request. Closing it now.');
            $request->getSession()->save();
        }
    }

@mathieudz
Copy link
Contributor Author

After upgrade to Symfony 5.1, sessions are again leaking despite my workaround.

@acasademont
Copy link
Contributor

@mathieudz would be great to have a repro test-case, I'm using php-pm in a stateless REST api, so no sessions on our end to see what might be happening.

@mathieudz
Copy link
Contributor Author

I'm still trying to figure out what causes the leak. The only way to reproduce it currently is to switch production to v5.1 and wait a few hours until it occurs (and all hell breaks loose).

@mathieudz
Copy link
Contributor Author

I'm back on 5.1 and the problem does not occur anymore. No way to reproduce it anymore.
Still it would be a good thing if PHP PM were able to check if a session is still open after a request and do something about it (close the session, stop the worker, ...)
These issues are really very hard to debug.

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

3 participants