Bugzilla – Attachment 168698 Details for
Bug 37018
SQL injection using q under api/
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 37018: Add validation method to Koha::REST::Plugin::Query.pm
Bug-37018-Add-validation-method-to-KohaRESTPluginQ.patch (text/plain), 2.88 KB, created by
Martin Renvoize (ashimema)
on 2024-07-10 08:40:58 UTC
(
hide
)
Description:
Bug 37018: Add validation method to Koha::REST::Plugin::Query.pm
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2024-07-10 08:40:58 UTC
Size:
2.88 KB
patch
obsolete
>From fd621c3f67c88d76fa7e463dba40b49381a2d641 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@ptfs-europe.com> >Date: Wed, 5 Jun 2024 14:19:54 +0100 >Subject: [PATCH] Bug 37018: Add validation method to > Koha::REST::Plugin::Query.pm > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > Koha/REST/Plugin/Query.pm | 67 +++++++++++++++++++++++++++++++++++++++ > 1 file changed, 67 insertions(+) > >diff --git a/Koha/REST/Plugin/Query.pm b/Koha/REST/Plugin/Query.pm >index 53decc94bcf..a4c27c1c1b7 100644 >--- a/Koha/REST/Plugin/Query.pm >+++ b/Koha/REST/Plugin/Query.pm >@@ -23,6 +23,7 @@ use Scalar::Util qw( reftype ); > use JSON qw( decode_json ); > > use Koha::Exceptions; >+use Koha::Exceptions::REST; > > =head1 NAME > >@@ -187,6 +188,21 @@ Generates the DBIC join attribute based on extended_attributes query entries, an > } > ); > >+=head3 dbic_validate_operators >+ >+ $attributes = $c->dbic_validate_operators( { filtered_params => $filtered_params } ); >+ >+Validate operators in the passed query. >+ >+=cut >+ >+ $app->helper( >+ 'dbic_validate_operators' => sub { >+ my ( $c, $args ) = @_; >+ _validate_query( $args->{filtered_params} ); >+ } >+ ); >+ > =head3 _build_query_params_from_api > > my $params = _build_query_params_from_api( $filtered_params, $reserved_params ); >@@ -641,4 +657,55 @@ sub _rewrite_related_metadata_query { > return $extended_attributes_entries; > } > >+=head3 _validate_operator >+ >+=cut >+ >+sub _validate_operator { >+ my ($operator) = @_; >+ my %allowed_operators = map { $_ => 1 } qw(= != < > <= >= like -not_like -in -ident -bool -not_bool -or); >+ Koha::Exceptions::REST::Query::InvalidOperator->throw( operator => $operator ) >+ unless exists $allowed_operators{$operator}; >+ return; >+} >+ >+=head3 _validate_query >+ >+=cut >+ >+sub _validate_query { >+ my ($query) = @_; >+ >+ if ( ref $query eq 'HASH' ) { >+ for my $field ( keys %$query ) { >+ my $value = $query->{$field}; >+ >+ if ( ref $value eq 'HASH' ) { >+ >+ # Hash reference with operators >+ for my $operator ( keys %$value ) { >+ _validate_operator($operator); >+ } >+ } elsif ( ref $value eq 'ARRAY' ) { >+ >+ # Array reference with operator as the first element >+ _validate_query($value); >+ } else { >+ >+ # Simple key-value pairs (no operator to validate) >+ } >+ } >+ } elsif ( ref $query eq 'ARRAY' ) { >+ >+ # Top-level OR combination or nested AND combination >+ for my $element (@$query) { >+ if ( ref $element eq 'ARRAY' && $element->[0] eq '-and' ) { >+ _validate_query( $element->[1] ); >+ } else { >+ _validate_query($element); >+ } >+ } >+ } >+} >+ > 1; >-- >2.45.2
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 37018
:
167440
|
167441
|
167442
|
167446
|
167447
|
167448
|
167449
|
167603
|
167672
|
167691
|
167772
|
168458
|
168582
|
168583
|
168584
|
168585
|
168586
|
168587
|
168616
|
168617
|
168618
|
168619
|
168620
|
168621
|
168622
|
168624
|
168626
|
168627
|
168628
|
168629
|
168630
|
168631
|
168632
|
168633
|
168634
|
168635
|
168654
|
168655
|
168656
|
168657
|
168658
|
168659
|
168660
|
168661
|
168662
|
168695
|
168696
|
168697
|
168698
|
168699
|
168700
|
168701
|
168702
|
168703
|
168704
|
168786
|
168787
|
168788
|
168789
|
168790
|
168791
|
168792
|
168793
|
168794
|
168795
|
169309
|
169337
|
169338
|
169339
|
169340
|
169341
|
169342
|
169343
|
169344
|
169345
|
169346
|
169368
|
169369
|
169370
|
169371
|
169372
|
169373
|
169374
|
169375
|
169376
|
169377
|
169378
|
169414
|
169832
|
169833
|
169834
|
169835
|
169836
|
169837
|
169838
|
169839
|
169840
|
169841