|
Lines 1-5
Link Here
|
| 1 |
#!/usr/bin/perl |
1 |
#!/usr/bin/perl |
| 2 |
|
2 |
|
|
|
3 |
# Copyright 2021 Koha development team |
| 4 |
# |
| 3 |
# This file is part of Koha. |
5 |
# This file is part of Koha. |
| 4 |
# |
6 |
# |
| 5 |
# Koha is free software; you can redistribute it and/or modify it |
7 |
# Koha is free software; you can redistribute it and/or modify it |
|
Lines 63-81
sub check_csrf_in_forms {
Link Here
|
| 63 |
my @lines = read_file($file); |
65 |
my @lines = read_file($file); |
| 64 |
my @errors; |
66 |
my @errors; |
| 65 |
return @errors unless grep { $_ =~ m|<form| } @lines; |
67 |
return @errors unless grep { $_ =~ m|<form| } @lines; |
| 66 |
my ( $open, $found, $closed ) = ( 0, 0, 0 ); |
68 |
my ( $open, $found ) = ( 0, 0 ); |
| 67 |
my $line = 0 ; |
69 |
my $line = 0 ; |
| 68 |
for my $l (@lines) { |
70 |
for my $l (@lines) { |
| 69 |
$line++; |
71 |
$line++; |
| 70 |
$open = $line if ( $l =~ m{<form} && !($l =~ m{method=('|")get('|")})); |
72 |
$open = $line if ( $l =~ m{<form} && !( $l =~ m{method=('|")get('|")} ) ); |
| 71 |
$found++ if ($l =~ m|csrf\-token\.inc| && $open); |
73 |
$found++ if ( $l =~ m|csrf\-token\.inc| && $open ); |
| 72 |
$closed++ if ($l =~ m|</form| && $open); |
74 |
if ( $open && $l =~ m|</form| ) { |
| 73 |
if ( $open && $closed ) { |
75 |
push @errors, |
| 74 |
push @errors, "The <form> starting on line $open is missing it's corresponding csrf_token include (see bug 22990)" |
76 |
"The <form> starting on line $open is missing it's corresponding csrf_token include (see bug 22990)" |
| 75 |
if !$found; |
77 |
if !$found; |
| 76 |
|
78 |
$found = 0; |
| 77 |
# reset |
|
|
| 78 |
( $open, $found, $closed ) = ( 0, 0, 0 ); |
| 79 |
} |
79 |
} |
| 80 |
} |
80 |
} |
| 81 |
return @errors; |
81 |
return @errors; |
| 82 |
- |
|
|