From d3a9971314953548a0fc1449cd2adbb7795e7f6d Mon Sep 17 00:00:00 2001 From: Jason Bosco Date: Sun, 24 Jan 2021 19:53:19 -0800 Subject: [PATCH] Ability to restrict multi searches to a given value --- src/core_api.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/core_api.cpp b/src/core_api.cpp index 2c9ff9a4..ab0d750e 100644 --- a/src/core_api.cpp +++ b/src/core_api.cpp @@ -297,6 +297,18 @@ bool post_multi_search(http_req& req, http_res& res) { return false; } + const char* LIMIT_MULTI_SEARCHES = "limit_multi_searches"; + size_t limit_multi_searches = 50; + + if(req.params.count(LIMIT_MULTI_SEARCHES) != 0 && StringUtils::is_uint32_t(req.params[LIMIT_MULTI_SEARCHES])) { + limit_multi_searches = std::stoi(req.params[LIMIT_MULTI_SEARCHES]); + } + + if(req_json["searches"].size() > limit_multi_searches) { + res.set_400(std::string("Number of multi searches exceeds `") + LIMIT_MULTI_SEARCHES + "` parameter."); + return false; + } + auto orig_req_params = req.params; nlohmann::json response;