since php5 there are two new settings:
session.hash_function integer
session.hash_function allows you to specify the hash algorithm used to generate the session IDs. '0' means MD5 (128 bits) and '1' means SHA-1 (160 bits).Note: This was introduced in PHP 5.
session.hash_bits_per_character integer
session.hash_bits_per_character allows you to define how many bits are stored in each character when converting the binary hash data to something readable. The possible values are '4' (0-9, a-f), '5' (0-9, a-v), and '6' (0-9, a-z, A-Z, "-", ",").Note: This was introduced in PHP 5.
however, if one sets the hash functions to SHA-1 the session id is 40 characters long. the database field for the sid is only 32 characters long, so the sid is choped and users get duplicate session id errors every page hit and aren't able to login. So drupal becomes completely unusable!
session.hash_bits_per_character can't be set lower than 4. In combination with SHA-1 hashing the sid is as long as possible: 40 characters.
so I propose to change the database field to VARCHAR(40)
I'm not attaching a patch, because I'm not so familiar with postgreSQL, however for mysql this statement worked for me:
ALTER TABLE `sessions` CHANGE `sid` `sid` VARCHAR( 40 )
note: this issue affects all drupal versions!
| Comment | File | Size | Author |
|---|---|---|---|
| #27 | wider-sid-column_0.patch | 2.87 KB | webchick |
| #26 | wider-sid-column.patch | 2.65 KB | webchick |
| #13 | 78732.patch.txt | 1.49 KB | dopry |
| #10 | htaccess_1.76_p01 | 581 bytes | AjK |
| #5 | system.install_1.21_p0.txt | 1.04 KB | AjK |
Comments
Comment #1
beginner commentedComment #2
fagoimho that's a bug report!
Comment #3
AjK commentedThe other solution to this is to set :-
ini_set('session.hash_bits_per_character', 5);in the settings.php file. If SHA-1 is used the 160bits are then fitted into 32characters. I tested this and it works fine on PHP5.1.4 and doesn't require a database change.
regards,
--AjK
Comment #4
killes@www.drop.org commentedMaybe we should add a comment?
Comment #5
AjK commentedWe could add a comment to make it more clear. The main problem is that PHP's default bits per char is 4. Might have made more sense to make it 5 but hey, what more can you say.
I've attached a system.install patch here also which changes the VARCHAR from 32 to 40 (as noted above) if this is the prefered method/solution.
I wasn't sure if this alteration required an update_ as it seems to me that if the problem exists then an old site just won't be working anyway! So, only possible future versions really need 40 chars.
But a retrospective change by a site admin would render the login system dead so adding a note is a good idea.
regards,
--AjK
Comment #6
webchickThere should still be an update for this. I might have a 4.7 site and not use this functionality yet, but I may in the future when I upgrade to 5.0, for example.
Comment #7
AjK commentedhaving spoke with killes on IRC it seems (so far) the prefered fix is to set the hash_bits_per_character correctly as per my first patch (and with some added comments in there regarding this issue?)
I guuess this one is "for the powers that be" to decide on the proper end solution.
regards,
--AjK
Comment #8
webchickOk, in that case, patch still needs comments saying why you're setting the bits to 5. :)
Comment #9
chx commentedHow reasonable would be to document session.hash_bits_per_character 5 necessity if sha1 is used and not bother with code? What happens if you set an ini setting which does not exist in the relevant php version?
Comment #10
AjK commentedSorry, yet another patch to apply the "fix" in a more suitable way.
This patch adds the two PHP INI settings to the .htaccess file as there exists in there a way to set these depending upon the PHP version (the PHP version test already exists in .htaccess).
There's little in the way of comments in .htaccess so if this needs documenting then I'd be happy to add a doc page in the handbook that explains what these two settings do and implications of altering them (and how to alter them safely).
regards,
--AjK
Comment #11
fagoI don't like using mod-php to set php-values. What is with users using php-cgi, php-fcgi or su-php?
In my opinion everything that could be done with ini_set() should be done with ini_set().
@chx: I think it will return FALSE. So there should be no problem.
Comment #12
dries commentedThe best solution is to grow the size of the database field. .htaccess solutions are limited to Apache and not portable to other web servers. We should have a good index/key on the field so it shouldn't really matter for performance (I think).
Comment #13
dopry commentedHere is a patch which updates system_install and adds system_update_1013. I tested the query for the mysql update manually. I tested a clean install of HEAD on mysql 4.1. The pgsql should be examined by someone who can vouch for it. I can still login and my sessions seems to work fine.
Comment #14
Kjartan commentedWhy not just set the field to VARCHAR(255) so we don't need to update again should an even longer session id pop up. Storage wise it really doesn't matter in the MySQL world at least.
http://dev.mysql.com/doc/refman/5.0/en/char.html#char
Also since the sid key is the primary key I think it defaults to using the first 96 chars for the index. My bet is that the index file will be just as large, if not bigger, as the data file with the current indexes.
Comment #15
beginner commentedThe patch above is exactly was was originally asked for.
I tested on mysql 4 and it works as expected.
postgresql untested.
If it is felt that the field should be increased to 255 chars, the patch can easily be updated (even manually) to reflect this.
Comment #16
dries commentedCommitted to CVS HEAD. Thanks.
Comment #17
beginner commentedFYI: patch committed has varchar(64)
http://drupal.org/cvs?commit=41667
Comment #18
fagogreat. It would be nice to have this fixed for 4.7 too.
Comment #19
killes@www.drop.org commentedTo add this to 4.7 I'd need a patch that adds the correct db update number. However, I am not really in favour of adding db updates to maintenance releases and I dont consider this to be really critical.
Comment #20
chx commentedif you are savvy enough to set sha1 then you are savvy enoguh to raise session.hash_bits_per_character integer too. While it's OK in HEAD because no pain (and imo no gain but no lose either) it's not important to disturb the peace of 4.7.
Comment #21
fagoyeah, I am. But what if some hosters decide to set sha1 session ids as default setting? then all drupal 4.7 installations are going to die...
Comment #22
chx commentedNo, not all. Only at that host. You are free to complain at the host and if there is no act, vote with your feet.
Comment #23
fagoyeah, of course I meant "only" the installations on these hosts..
Comment #24
Zen commentedThe HEAD patch misses the sid field in the access_log table [statistics module].
IMO, omitting this patch for 4.7 is very negligent. I will try to submit a patch for it soon.
Cheers,
-K
Comment #25
Zen commentedCorrection, the committed patch:
I will submit a backport for 4.7 once this has been sorted. Changing version to CVS.
Thanks,
-K
Comment #26
webchickTry this...
Note: I did not add another update to correct the mistake in the previous update because we do not support HEAD -> HEAD updates.
Comment #27
webchickThat capitalized VARCHAR was annoying me. ;)
Comment #28
dries commentedCommitted to CVS HEAD. Thanks.
Comment #29
Zen commentedWhat update number should I use for a backport?
Thanks
-K
Comment #30
webchickLooks like 183.
Comment #31
webchickActually, for 4.7.x there is http://drupal.org/node/64049 which was posted before this one. So that's a better place for discussion. Marking this bug as 5.x-dev and fixed.
Comment #32
(not verified) commented