From 436088e29ef4afa4b56961718ae8c9a88346c54d Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Mon, 18 Mar 2024 12:49:20 -0300 Subject: [PATCH] Bug 35129: Return 400 if _per_page=0 passed This patch adds a safe guard for when consumers pass _per_page=0 to endpoints. This condition is checked for on a centralized place and avoid reaching the controller in such scenarios that would provoke a division by zero exception. To test: 1. Apply the regression tests patch 2. Run: $ ktd --shell k$ prove t/db_dependent/api/v1/pagination.t => FAIL: We expect a 400, but get a 500 instead 3. Apply this patch 4. Repeat 2 => SUCCESS: Tests pass! No more explosions for this! 5. Sign off :-D Signed-off-by: Tomas Cohen Arazi Signed-off-by: Laura Escamilla Signed-off-by: Nick Clemens --- Koha/REST/V1/Auth.pm | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Koha/REST/V1/Auth.pm b/Koha/REST/V1/Auth.pm index 948bed689bd..b8d793b0f68 100644 --- a/Koha/REST/V1/Auth.pm +++ b/Koha/REST/V1/Auth.pm @@ -358,6 +358,9 @@ sub validate_query_parameters { push @errors, { path => "/query/" . $param, message => 'Malformed query string' } unless exists $valid_parameters{$param}; } + push @errors, { path => "/query/_per_page", message => 'Invalid value: 0' } + if exists $existing_params->{_per_page} && $existing_params->{_per_page} == 0; + Koha::Exceptions::BadParameter->throw( error => \@errors ) if @errors; -- 2.30.2