Bug 34478: Check CSRF in get_template_and_user

Not sure this is the right place in get_template_and_user
Will have to test login and 2FA

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
This commit is contained in:
Jonathan Druart 2023-08-04 11:32:27 +02:00
parent 4ed5bf19a7
commit a0dcce9ce1
No known key found for this signature in database
GPG Key ID: A085E712BEF0E0F0
1 changed files with 25 additions and 1 deletions

View File

@ -947,6 +947,8 @@ sub checkauth {
}
}
my $request_method = $query->request_method // q{};
if ( $auth_state eq 'failed' || $logout ) {
$sessionID = undef;
$userid = undef;
@ -1090,7 +1092,6 @@ sub checkauth {
}
else {
my $retuserid;
my $request_method = $query->request_method // q{};
if (
$request_method eq 'POST'
@ -1480,6 +1481,29 @@ sub checkauth {
}
}
if ( $auth_state eq 'completed' && defined $query->param('op') ) {
die "Cannot use GET for this request"
if $request_method ne 'POST';
print $query->header(
{
type => 'text/html',
charset => 'utf-8',
cookie => $cookie,
'X-Frame-Options' => 'SAMEORIGIN',
-sameSite => 'Lax'
}
);
output_and_exit( $query, $cookie, $template, 'wrong_csrf_token' )
unless Koha::Token->new->check_csrf(
{
session_id => scalar $query->cookie('CGISESSID'),
token => scalar $query->param('csrf_token'),
}
);
}
$template->param(
LibraryName => C4::Context->preference("LibraryName"),
%info,