From fb083c95a2582904d633b84e4eddabce08baf99c Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 3 May 2018 09:09:19 -0300 Subject: [PATCH] Bug 20701: Add csrf protection to mancredit.pl Works OK. Signed-off-by: Amit Gupta Signed-off-by: Marcel de Rooy Signed-off-by: Nick Clemens --- .../prog/en/modules/members/mancredit.tt | 1 + members/mancredit.pl | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/mancredit.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/mancredit.tt index 65a61a59ea..0f7ffc78ba 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/mancredit.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/mancredit.tt @@ -36,6 +36,7 @@ $(document).ready(function(){
+
Manual credit
    diff --git a/members/mancredit.pl b/members/mancredit.pl index fcfa1bf96d..3617f2af90 100755 --- a/members/mancredit.pl +++ b/members/mancredit.pl @@ -36,6 +36,7 @@ use C4::Members::Attributes qw(GetBorrowerAttributes); use Koha::Patrons; use Koha::Patron::Categories; +use Koha::Token; my $input=new CGI; my $flagsrequired = { borrowers => 1, updatecharges => 1 }; @@ -51,6 +52,15 @@ my $add=$input->param('add'); if ($add){ if ( checkauth( $input, 0, $flagsrequired, 'intranet' ) ) { + + die "Wrong CSRF token" + unless Koha::Token->new->check_csrf( { + session_id => $input->cookie('CGISESSID'), + token => scalar $input->param('csrf_token'), + }); + + # Note: If the logged in user is not allowed to see this patron an invoice can be forced + # Here we are trusting librarians not to hack the system my $barcode = $input->param('barcode'); my $itemnum; if ($barcode) { @@ -101,6 +111,9 @@ if ($add){ borrowernumber => $borrowernumber, categoryname => $patron->category->description, is_child => ($patron->category->category_type eq 'C'), # FIXME is_child should be a Koha::Patron method + csrf_token => Koha::Token->new->generate_csrf( + { session_id => scalar $input->cookie('CGISESSID') } + ), ); output_html_with_http_headers $input, $cookie, $template->output; } -- 2.39.5