Skip to content

Commit

Permalink
make CSRF tokens much harder to guess
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Oct 12, 2015
1 parent b2088ea commit 0cc79c4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 3 additions & 3 deletions Changes
@@ -1,7 +1,7 @@

6.24 2015-10-10
- Improved session security by not storing secrets in the stash and not using
secrets to generate the CSRF token.
6.24 2015-10-12
- Improved session security by not storing secrets in the stash and making
CSRF tokens much harder to guess.
- Improved commands to show all options that can affect their behavior.

6.23 2015-10-06
Expand Down
6 changes: 4 additions & 2 deletions lib/Mojolicious/Plugin/DefaultHelpers.pm
Expand Up @@ -5,7 +5,7 @@ use Mojo::ByteStream;
use Mojo::Collection;
use Mojo::Exception;
use Mojo::IOLoop;
use Mojo::Util qw(dumper sha1_sum steady_time);
use Mojo::Util qw(dumper hmac_sha1_sum steady_time);

sub register {
my ($self, $app) = @_;
Expand Down Expand Up @@ -66,7 +66,9 @@ sub _content {
}

sub _csrf_token {
shift->session->{csrf_token} ||= sha1_sum $$ . steady_time . rand 999;
my $c = shift;
return $c->session->{csrf_token}
||= hmac_sha1_sum $$ . steady_time . rand 999, $c->app->secrets->[0];
}

sub _current_route {
Expand Down

0 comments on commit 0cc79c4

Please sign in to comment.