Bug 1179856 - Increase length of logincookie value for greater security

r=gerv,a=sgreen
parent 19a2ebac
......@@ -1148,7 +1148,7 @@ use constant ABSTRACT_SCHEMA => {
logincookies => {
FIELDS => [
cookie => {TYPE => 'varchar(16)', NOTNULL => 1,
cookie => {TYPE => 'varchar(22)', NOTNULL => 1,
PRIMARYKEY => 1},
userid => {TYPE => 'INT3', NOTNULL => 1,
REFERENCES => {TABLE => 'profiles',
......@@ -1190,7 +1190,7 @@ use constant ABSTRACT_SCHEMA => {
COLUMN => 'userid',
DELETE => 'CASCADE'}},
issuedate => {TYPE => 'DATETIME', NOTNULL => 1} ,
token => {TYPE => 'varchar(16)', NOTNULL => 1,
token => {TYPE => 'varchar(22)', NOTNULL => 1,
PRIMARYKEY => 1},
tokentype => {TYPE => 'varchar(16)', NOTNULL => 1} ,
eventdata => {TYPE => 'TINYTEXT'},
......
......@@ -739,6 +739,12 @@ sub update_table_definitions {
$dbh->bz_add_column('keyworddefs', 'is_active',
{TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => 'TRUE'});
# 2015-07-25 dylan@mozilla.com - Bug 1179856
$dbh->bz_alter_column('tokens', 'token',
{TYPE => 'varchar(22)', NOTNULL => 1, PRIMARYKEY => 1});
$dbh->bz_alter_column('logincookies', 'cookie',
{TYPE => 'varchar(22)', NOTNULL => 1, PRIMARYKEY => 1});
################################################################
# New --TABLE-- changes should go *** A B O V E *** this point #
################################################################
......
......@@ -29,6 +29,11 @@ use parent qw(Exporter);
check_token_data delete_token
issue_hash_token check_hash_token);
# 128 bits password:
# 128 * log10(2) / log10(62) = 21.49, round up to 22.
# 62 = 0-9, a-z, A-Z.
use constant TOKEN_LENGTH => 22;
################################################################################
# Public Functions
################################################################################
......@@ -289,7 +294,7 @@ sub GenerateUniqueToken {
if ($tries > 100) {
ThrowCodeError("token_generation_error");
}
$token = generate_random_password();
$token = generate_random_password(TOKEN_LENGTH);
$sth->execute($token);
$duplicate = $sth->fetchrow_array;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment