Bug 20701: Add csrf protection to mancredit.pl
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 3 May 2018 12:09:19 +0000 (09:09 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 23 May 2018 16:01:59 +0000 (13:01 -0300)
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

koha-tmpl/intranet-tmpl/prog/en/modules/members/mancredit.tt
members/mancredit.pl

index 857eeb8..305910f 100644 (file)
@@ -32,6 +32,7 @@
 
 <form action="/cgi-bin/koha/members/mancredit.pl" method="post" id="mancredit">
 <input type="hidden" name="borrowernumber" id="borrowernumber" value="[% patron.borrowernumber %]" />
+    <input type="hidden" name="csrf_token" value="[% csrf_token %]" />
 
 <fieldset class="rows">
 <legend>Manual credit</legend><ol>
index 557f517..0e8ac3e 100755 (executable)
@@ -35,6 +35,7 @@ use C4::Members::Attributes qw(GetBorrowerAttributes);
 use Koha::Patrons;
 
 use Koha::Patron::Categories;
+use Koha::Token;
 
 my $input=new CGI;
 my $flagsrequired = { borrowers => 'edit_borrowers', updatecharges => 1 };
@@ -50,6 +51,13 @@ 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 => scalar $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');
@@ -93,10 +101,12 @@ if ($add){
         );
     }
 
-    $template->param( patron => $patron );
-
     $template->param(
-        finesview      => 1,
-        );
+        patron     => $patron,
+        finesview  => 1,
+        csrf_token => Koha::Token->new->generate_csrf(
+            { session_id => scalar $input->cookie('CGISESSID') }
+        ),
+    );
     output_html_with_http_headers $input, $cookie, $template->output;
 }