diff --git a/lib/Dancer/Session/Abstract.pm b/lib/Dancer/Session/Abstract.pm index 43a34121..7a1a7dbf 100644 --- a/lib/Dancer/Session/Abstract.pm +++ b/lib/Dancer/Session/Abstract.pm @@ -4,6 +4,7 @@ package Dancer::Session::Abstract; use strict; use warnings; use Carp; +use Crypt::SysRandom; use base 'Dancer::Engine'; @@ -81,23 +82,8 @@ sub set_value { # Methods below this line should not be overloaded. -# we try to make the best random number -# with native Perl 5 code. -# to rebuild a session id, an attacker should know: -# - the running PID of the server -# - the current timestamp of the time it was built -# - the path of the installation directory -# - guess the correct number between 0 and 1000000000 -# - should be able to reproduce that 3 times sub build_id { - my $session_id = ""; - foreach my $seed (rand(1000), rand(1000), rand(1000)) { - my $c = 0; - $c += ord($_) for (split //, File::Spec->rel2abs(File::Spec->curdir)); - my $current = int($seed * 1000000000) + time + $$ + $c; - $session_id .= $current; - } - return $session_id; + return unpack("N*", Crypt::SysRandom::random_bytes(16)); } sub read_session_id {