Bugzilla – Attachment 154248 Details for
Bug 34478
Full CSRF protection
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 34478: Add a script to catch missing 'op' in POST forms - catch_missing_op
Bug-34478-Add-a-script-to-catch-missing-op-in-POST.patch (text/plain), 2.34 KB, created by
Jonathan Druart
on 2023-08-04 09:48:56 UTC
(
hide
)
Description:
Bug 34478: Add a script to catch missing 'op' in POST forms - catch_missing_op
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2023-08-04 09:48:56 UTC
Size:
2.34 KB
patch
obsolete
>From 7b18766a3472a63ceaa67f9283fe0cb71035a73b Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Fri, 4 Aug 2023 10:45:18 +0200 >Subject: [PATCH] Bug 34478: Add a script to catch missing 'op' in POST forms - > catch_missing_op > >--- > catch_missing_op.pl | 69 +++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 69 insertions(+) > create mode 100644 catch_missing_op.pl > >diff --git a/catch_missing_op.pl b/catch_missing_op.pl >new file mode 100644 >index 00000000000..84913354995 >--- /dev/null >+++ b/catch_missing_op.pl >@@ -0,0 +1,69 @@ >+#!/usr/bin/perl >+ >+use Modern::Perl; >+use File::Find; >+use File::Slurp; >+use Data::Dumper; >+ >+my @themes; >+ >+# OPAC themes >+my $opac_dir = 'koha-tmpl/opac-tmpl'; >+opendir ( my $dh, $opac_dir ) or die "can't opendir $opac_dir: $!"; >+for my $theme ( grep { not /^\.|lib|js|xslt/ } readdir($dh) ) { >+ push @themes, "$opac_dir/$theme/en"; >+} >+close $dh; >+ >+# STAFF themes >+my $staff_dir = 'koha-tmpl/intranet-tmpl'; >+opendir ( $dh, $staff_dir ) or die "can't opendir $staff_dir: $!"; >+for my $theme ( grep { not /^\.|lib|js/ } readdir($dh) ) { >+ push @themes, "$staff_dir/$theme/en"; >+} >+close $dh; >+ >+my @files; >+sub wanted { >+ my $name = $File::Find::name; >+ push @files, $name >+ if $name =~ m[\.(tt|inc)$] and -f $name; >+} >+ >+find({ wanted => \&wanted, no_chdir => 1 }, @themes ); >+ >+my @errors; >+for my $file ( @files ) { >+ my @e = catch_missing_op($file); >+ push @errors, { file => $file, errors => \@e } if @e; >+} >+ >+say sprintf("%s:%s", $_->{file}, join(',', @{$_->{errors}})) for @errors; >+ >+sub catch_missing_op{ >+ my ( $file ) = @_; >+ >+ my @lines = read_file($file); >+ my @errors; >+ return unless grep { $_ =~ m|<form| } @lines; >+ my ($in_form, $closed_form, $line_open_form, $has_op); >+ my $line_number = 0; >+ for my $line (@lines) { >+ $line_number++; >+ if ( $line =~ m{^(\s*)<form.*method=('|")post('|")}i ) { >+ $in_form = 1; >+ $line_open_form = $line_number; >+ } >+ if ( $in_form && $line =~ m{name="op"}) { >+ $has_op = 1; >+ } >+ if ( $in_form && $line =~ m{</form} ) { >+ $closed_form = 0; >+ unless ( $has_op ) { >+ push @errors, $line_open_form; >+ } >+ $in_form = 0; >+ } >+ } >+ return @errors; >+} >-- >2.25.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 34478
:
154241
|
154242
|
154243
|
154244
|
154245
|
154246
|
154247
|
154248
|
154249
|
154250
|
154251
|
154252
|
154253
|
154254
|
155971
|
155972
|
155973
|
155974
|
155975
|
155976
|
155977
|
155978
|
155979
|
155980
|
155981
|
155982
|
155983
|
155984
|
155985
|
155986
|
155987
|
155988
|
155989
|
155990
|
156070
|
156071
|
156072
|
156073
|
156074
|
162114
|
162165
|
162630