This is an automated email from the ASF dual-hosted git repository.

rnewson pushed a commit to branch changes-validation
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 6548076fdc38af726a5cc1b3ff6a3d6ff87660fb
Author: Robert Newson <[email protected]>
AuthorDate: Tue Aug 4 18:32:59 2026 +0100

    validate limit and timeout parameters to _changes
    
    closes #6087
---
 src/chttpd/src/chttpd_db.erl | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)

diff --git a/src/chttpd/src/chttpd_db.erl b/src/chttpd/src/chttpd_db.erl
index 200e705d2..20f41e04a 100644
--- a/src/chttpd/src/chttpd_db.erl
+++ b/src/chttpd/src/chttpd_db.erl
@@ -2153,7 +2153,21 @@ parse_changes_query(Req) ->
                 {"last-event-id", _} ->
                     Args#changes_args{since = Value};
                 {"limit", _} ->
-                    Args#changes_args{limit = list_to_integer(Value)};
+                    try list_to_integer(Value) of
+                        LimitInteger when LimitInteger >= 0 ->
+                            Args#changes_args{limit = list_to_integer(Value)};
+                        _ ->
+                            throw(
+                                {bad_request,
+                                    <<"The limit value should be a 
non-negative integer">>}
+                            )
+                    catch
+                        error:badarg ->
+                            throw(
+                                {bad_request,
+                                    <<"The limit parameter should be a 
non-negative integer">>}
+                            )
+                    end;
                 {"style", _} ->
                     Args#changes_args{style = list_to_existing_atom(Value)};
                 {"heartbeat", "true"} ->
@@ -2175,7 +2189,21 @@ parse_changes_query(Req) ->
                             )
                     end;
                 {"timeout", _} ->
-                    Args#changes_args{timeout = list_to_integer(Value)};
+                    try list_to_integer(Value) of
+                        TimeoutInteger when TimeoutInteger >= 0 ->
+                            Args#changes_args{timeout = 
list_to_integer(Value)};
+                        _ ->
+                            throw(
+                                {bad_request,
+                                    <<"The timeout value should be a 
non-negative integer">>}
+                            )
+                    catch
+                        error:badarg ->
+                            throw(
+                                {bad_request,
+                                    <<"The timeout parameter should be a 
non-negative integer">>}
+                            )
+                    end;
                 {"include_docs", "true"} ->
                     Args#changes_args{include_docs = true};
                 {"conflicts", "true"} ->

Reply via email to