From 9eddab11af7a3e663d0e1c6e47992e86019f67b8 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 --- 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 948bed689b..b8d793b0f6 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