Skip to content

Commit

Permalink
[UPC#180] Session hash timed out at login
Browse files Browse the repository at this point in the history
  • Loading branch information
frankiejol committed Apr 12, 2017
1 parent 1ab9cdb commit e88613b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions etc/rvd_front.conf.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
}
,user => 'ravada'
,group => 'ravada'
,secrets = ['changeme1','changeme2']
};
24 changes: 22 additions & 2 deletions rvd_front.pl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use locale ':not_characters';
#####
use Carp qw(confess);
use Digest::SHA qw(sha256_hex);
use Data::Dumper;
use Getopt::Long;
use Hash::Util qw(lock_hash);
Expand Down Expand Up @@ -35,8 +36,10 @@
,login_bg_file => '../img/intro-bg.jpg'
,login_header => 'Login'
,login_message => ''
,secrets => ['changeme0']
}
,file => '/etc/rvd_front.conf' };
,file => '/etc/rvd_front.conf'
};
#####
#####
#####
Expand Down Expand Up @@ -552,16 +555,29 @@ sub login {

my $login = $c->param('login');
my $password = $c->param('password');
my $form_hash = $c->param('login_hash');
my $url = ($c->param('url') or $c->req->url->to_abs->path);
$url = '/' if $url =~ m{^/login};

my @error =();

# TODO: improve this hash
my ($time) = time =~ m{(.*)...$};
my $login_hash1 = $time.$CONFIG_FRONT->{secrets}->[0];

# let login varm be valid for 60 seconds
($time) = (time-60) =~ m{(.*)...$};
my $login_hash2 = $time.$CONFIG_FRONT->{secrets}->[0];

if (defined $login || defined $password || $c->param('submit')) {
push @error,("Empty login name") if !length $login;
push @error,("Empty password") if !length $password;
push @error,("Session timeout")
if $form_hash ne sha256_hex($login_hash1)
&& $form_hash ne sha256_hex($login_hash2);
}

if (defined $login && defined $password && length $login && length $password ) {
if ( !@error ) {
my $auth_ok;
eval { $auth_ok = Ravada::Auth::login($login, $password)};
if ( $auth_ok && !$@) {
Expand All @@ -577,13 +593,15 @@ sub login {
." url($CONFIG_FRONT->{login_bg_file})"
." no-repeat bottom center scroll;\n\t}"];

sleep 5 if scalar(@error);
$c->render(
template => 'main/start'
,css => ['/css/main.css']
,csssnippets => @css_snippets
,js => ['/js/main.js']
,navbar_custom => 1
,login => $login
,login_hash => sha256_hex($login_hash1)
,error => \@error
,login_header => $CONFIG_FRONT->{login_header}
,login_message => $CONFIG_FRONT->{login_message}
Expand Down Expand Up @@ -1435,6 +1453,8 @@ sub _new_anonymous_user {
return $name;
}

warn Dumper($CONFIG_FRONT->{secrets});
app->secrets($CONFIG_FRONT->{secrets}) if $CONFIG_FRONT->{secrets};
app->start;
__DATA__
Expand Down
2 changes: 2 additions & 0 deletions templates/main/start.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<input class="form-control" id="pssw" type="password" name="password" value="" placeholder="Password">

<input type="hidden" name="url" value="<%= $url %>">
<input type="hidden" name="login_hash"
value="<%= $login_hash %>">
<!-- <input type="submit" name="submit" value="launch"> -->
<button id="submit" class="btn btn-lg btn-success btn-block" href="/" type="submit" name="submit" value="launch">Launch</button>
% if (scalar @$error) {
Expand Down

0 comments on commit e88613b

Please sign in to comment.