diff options
author | Matthias Benkard <matthias.benkard@egym.de> | 2015-04-14 08:39:27 +0000 |
---|---|---|
committer | Matthias Andreas Benkard <code@mail.matthias.benkard.de> | 2015-04-23 21:55:02 +0200 |
commit | ba65cc50b7b468f0738398312a468ea413727bdc (patch) | |
tree | 19749bd8803a2f718013cf8901c04ea658f98731 /www/login.pl | |
parent | faea34e5c94922645b337bdeb5db32871eb1fde9 (diff) |
QT-1900 Add a CSRF token to the OIDC login flow.
This improves security by generating a CSRF token, passing it to the
OIDC IdP, and validating it afterwards. The token is stored in
a cookie reverse-encrypted with MulkyID's private key.
Diffstat (limited to 'www/login.pl')
-rwxr-xr-x | www/login.pl | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/www/login.pl b/www/login.pl index fe1729d..5d27cbe 100755 --- a/www/login.pl +++ b/www/login.pl @@ -79,6 +79,14 @@ while (my $cgi = new CGI::Fast) { } when ('google') { my $code = $cgi->param('code') or die "Authorization code is missing."; + + # Validate CSRF token. + my $oauth_state = $cgi->param('state'); + my $csrf_token = read_cookie($cgi, 'mulkyid_csrf_token'); + unless ($csrf_token && $oauth_state && $csrf_token eq $oauth_state) { + die "CSRF token was forged!"; + } + my $oidc_client = OIDC::Lite::Client::WebServer->new( id => $::MULKONF->{'google_oauth2_client_id'}, secret => $::MULKONF->{'google_oauth2_client_secret'}, |