-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Add a session wrapper to encrypt sessiondata #17866
Conversation
Example how a session is stored now:
vs.
I do operate on the whole session blob here instead of the single elements. |
So and now let's |
182395a
to
a462681
Compare
@LukasReschke I take it this will be very useful for enhancing SMB with OC login, making it more secure? |
This is correct. An admin can still intercept the encryption key obviously but on storage the whole session is stored encrypted. The key is the actual session ID which is not stored on the application server in plain-text, with this change it is only stored as a hashed form. Still allowing some form of memory-time-tradeoff attacks but if an admin wants to bruteforce a 192bit strong key he can also just intercept the key 🙊 |
I think this is a good approach. I think it is possible that this might break some custom 3rdparty libraries or apps but let's try this for now. Maybe we need to add a switch later if we discover incompatibilities. |
@DeepDiver1975 I'm confused. I declared
I don't really have any clue about our DB layer. What is the most pragmatic way to handle this cross-platform? 🙊 |
Especially this leads on MySQL to:
|
@LukasReschke Use the |
What a simple solution that I didn't even think of 🙊 |
3146ca7
to
34c298c
Compare
You forgot to update the unit test after your last commit:
|
Stores the used sessions to reduce the risks of session collisions | ||
--> | ||
<name>*dbprefix*sessions</name> | ||
<declaration> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@LukasReschke should we add a user column to allow session enum on user basis?
I'm thinking about the scenario of password-change where we want to invalidate all user sessions ....
(there was an issue once by @danimo ....)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call. We can indeed implement this with this approach. – I will think about an actual implementation and merge it into this PR.
Todo:
- Add user id to database
- Read action needs to check if session is terminated, if yes: invalidate the session
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. This is rather hard to do since we have a circular dependency, in order to read the user we need to read the session which is not going to work here. There are ways to work around this by moving this code to another place but this requires quite some more changes than the integration we have right now.
I'll think about it…
Class CryptoSessionHandler provides some rough basic level of additional security by storing the session data in an encrypted form. The content of the session is encrypted using it's session ID and the actual session ID is not stored on the application server. One should note that an adversary with access to the source code or the system memory is still able to read the original session ID from the users' request. This thus can not be considered a strong security measure one should consider it as an additional small security obfuscation layer to comply with compliance guidelines. This class also provides a custom `create_sid` function to provide a generic protection against potential session collisions which may be experienced on huge instances where the PHP settings have been configured wrongly. Due to PHP limitations this is however only applied on instances running at least PHP 5.5.1
9efb8b8
to
7480cf6
Compare
A new inspection was created. |
@butonic Had time to test this on a memcache setup? |
@rperezb qa help is appreciated - THX |
It seems that php 5.5.9 doesn't like it...
If you want to check: http://docker.oc.solidgear.es:51680/ the ssh port is 51682. Feel free to use it. |
70 TB? |
I've also tried with a local VM with ubuntu 14.04 and php 5.5.9 with the same result and figures
Checked with mysql and postgresql DBs with the same result. Except for the VM (which I'd need to have a look to check what it contains), the other systems are fresh installed. |
Gotta love distributions which only backport security patches… 🙊 I will work around this… later… |
Ok. We need then a completely custom session handler. This is a little bit "more difficult" but not impossible. Basically this allows us to completely handle the session stuff on our own but also makes us incompatible with the default adapters. (such as the memcached one) @butonic Do you know what session storages are used at the moment at customers? Memcache and local ones? If so I will also write a memcached backend… |
hmm ... kind of critical with respect to existing installations out there. |
Sessions are ephemeral data, so there is no permanent data stored in there. What happens when an instance that previously used Memcache as session storage via the native PHP instance updates is that it will now use the local storage unless configured otherwise within ownCloud. This can lead to problems when the load-balancer is not based on some sticky component. In this case we would "just" need to advise the administrator that the storage handler they defined needs manual migration. We can for example block the instance when we detect that memcache has been configured. (using http://php.net/manual/en/function.session-module-name.php) The actual migration would then be to edit With regard to the implementation others such as Symfony have already done it and we would "only" need to adjust it: http://symfony.com/doc/current/components/http_foundation/session_configuration.html#custom-save-handlers
|
What we have now: This is a wrapper executing encryption stuff. It then tries to invoke the parent session handler to store the data. This does not seem to work reliably with all PHP versions. What it would be: Wrapper executing encryption stuff, it handles storage of the data on it's own. For that we need a list of what we want to support. Suggestion: Memcache and Local. |
… or we go back to #17744, which requires however two cookies and cannot provide other advantages such as a nearly perfect detection against collisions, misconfigured and misbehaving servers etc. It's all a trade-off ;-) |
as a result: wrapping is not the way to go ... we should discuss this in a bigger round @karlitschek @MTRichards @cmonteroluque Lets set this on hold for the time being - THX |
Perhaps at the conference? Can't wait too long, we need to get something in for 8.2, but of course the right something. |
well - after the conf we have only one week left for development - kind of critical to change a core component that late in the game. |
It is possible to use wrapping but we can't call the parent session handler (inheriting) in all versions which means we need to handle session storage on our own. |
in case we go with our own implementation of the php session storage we will rely on symfony for sure |
If we want something "not as secure" but also working thing: #17744 We should however really remove the conditional switch and also be aware of the other implications. It's not going to be worse than now, but also not much better :-) |
conference is too late and should be reserved for community topics anyways. |
So 8.3 for this and I will reanimate Joas' PR for 8.2? - Thoughts? While it does not offer the same level of protections we do not need to play around with PHP internals for now... |
@LukasReschke sonds like the best option. @DeepDiver1975 what do yo think? |
(closed because too buggy) |
This PR extends the default PHP
\SessionHandler
and adds the following changes to it:create_sid
function is offering some protection against a potential session collision on systems which are likely misconfigured or misrunning. This is achieved by writing each used session to the database.I decided to extend the default
\SessionHandler
instead of writing a custom one since there are instances already using stuff such as the memcached extension and dealing with session locking on our own can be pretty risky.This fixes https://github.com/owncloud/enterprise/issues/518 and also is related to https://github.com/owncloud/enterprise/issues/445. Replaces #17744.
Impact
sessions
table. This needs considerations how this behaves in huge environments. One should note that this is the same approach as in https://github.com/LukasReschke/session_login_tracker which was used at https://github.com/owncloud/enterprise/issues/445 and does not seem to have had a huge performance impact. @butonic may know more about DB stuff than me 🙊This requires real proper testing on all supported systems and PHP versions and can in no case be backported. Since it is pretty independent from core with only one small change in base.php I'd say we should merge this within master as soon as possible to get early feedback on this. In case of a problem we can anyways remove this again.
Test plan
Local storage
Memcache
PHP versions tested
Distributions tested
@butonic Please review and test. Especially the memcache part requires your expertise.
@DeepDiver1975 @MorrisJobke Please review.