View | Details | Raw Unified | Return to bug 30524
Collapse All | Expand All

(-)a/C4/Auth.pm (+2 lines)
Lines 49-54 use C4::Auth_with_shibboleth qw( shib_ok get_login_shib login_shib_url logout_sh Link Here
49
use Net::CIDR;
49
use Net::CIDR;
50
use C4::Log qw( logaction );
50
use C4::Log qw( logaction );
51
use Koha::CookieManager;
51
use Koha::CookieManager;
52
use Koha::Token;
52
53
53
# use utf8;
54
# use utf8;
54
55
Lines 300-305 sub get_template_and_user { Link Here
300
        $template->param( loggedinusernumber => $borrowernumber ); # FIXME Should be replaced with logged_in_user.borrowernumber
301
        $template->param( loggedinusernumber => $borrowernumber ); # FIXME Should be replaced with logged_in_user.borrowernumber
301
        $template->param( logged_in_user     => $patron );
302
        $template->param( logged_in_user     => $patron );
302
        $template->param( sessionID          => $sessionID );
303
        $template->param( sessionID          => $sessionID );
304
        $template->param( csrf_token => Koha::Token->new->generate_csrf({ session_id => scalar $sessionID }));
303
305
304
        if ( $in->{'type'} eq 'opac' ) {
306
        if ( $in->{'type'} eq 'opac' ) {
305
            require Koha::Virtualshelves;
307
            require Koha::Virtualshelves;
(-)a/C4/Output.pm (-6 / +27 lines)
Lines 33-38 use Scalar::Util qw( looks_like_number ); Link Here
33
use C4::Auth qw( get_template_and_user );
33
use C4::Auth qw( get_template_and_user );
34
use C4::Context;
34
use C4::Context;
35
use C4::Templates;
35
use C4::Templates;
36
use Koha::Token;
36
37
37
our (@ISA, @EXPORT_OK);
38
our (@ISA, @EXPORT_OK);
38
39
Lines 311-319 sub is_ajax { Link Here
311
To executed at the beginning of scripts to stop the script at this point if
312
To executed at the beginning of scripts to stop the script at this point if
312
some errors are found.
313
some errors are found.
313
314
314
Tests for module 'members':
315
A series of tests can be run for a given module, or a specific check.
315
* patron is not defined (we are looking for a patron that does no longer exist/never existed)
316
Params "module" and "check" are mutually exclusive.
316
* The logged in user cannot see patron's infos (feature 'cannot_see_patron_infos')
317
318
Tests for modules:
319
* members:
320
    - Patron is not defined (we are looking for a patron that does no longer exist/never existed)
321
    - The logged in user cannot see patron's infos (feature 'cannot_see_patron_infos')
322
323
Tests for specific check:
324
* csrf_token
325
    will test if the csrf_token CGI param is valid
317
326
318
Others will be added here depending on the needs (for instance biblio does not exist will be useful).
327
Others will be added here depending on the needs (for instance biblio does not exist will be useful).
319
328
Lines 329-344 sub output_and_exit_if_error { Link Here
329
            if ( not $current_patron ) {
338
            if ( not $current_patron ) {
330
                $error = 'unknown_patron';
339
                $error = 'unknown_patron';
331
            }
340
            }
332
            elsif( not $logged_in_user->can_see_patron_infos( $current_patron ) ) {
341
            elsif ( not $logged_in_user->can_see_patron_infos($current_patron) )
342
            {
333
                $error = 'cannot_see_patron_infos';
343
                $error = 'cannot_see_patron_infos';
334
            }
344
            }
335
        } elsif ( $params->{module} eq 'cataloguing' ) {
345
        }
346
        elsif ( $params->{module} eq 'cataloguing' ) {
336
            # We are testing the record to avoid additem to fetch the Koha::Biblio
347
            # We are testing the record to avoid additem to fetch the Koha::Biblio
337
            # But in the long term we will want to get a biblio in parameter
348
            # But in the long term we will want to get a biblio in parameter
338
            $error = 'unknown_biblio' unless $params->{record};
349
            $error = 'unknown_biblio' unless $params->{record};
339
        }
350
        }
340
    }
351
    }
341
352
    elsif ( $params and exists $params->{check} ) {
353
        if ( $params->{check} eq 'csrf_token' ) {
354
            $error = 'wrong_csrf_token'
355
              unless Koha::Token->new->check_csrf(
356
                {
357
                    session_id => scalar $query->cookie('CGISESSID'),
358
                    token      => scalar $query->param('csrf_token'),
359
                }
360
              );
361
        }
362
    }
342
    output_and_exit( $query, $cookie, $template, $error ) if $error;
363
    output_and_exit( $query, $cookie, $template, $error ) if $error;
343
    return;
364
    return;
344
}
365
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/csrf-token.inc (-1 / +1 lines)
Line 0 Link Here
0
- 
1
<input type="hidden" name="csrf_token" value="[% csrf_token | html %]" />

Return to bug 30524