nic-6443 commented on code in PR #13886:
URL: https://github.com/apache/apisix/pull/13886#discussion_r3877515797


##########
apisix/admin/config_validate.lua:
##########
@@ -125,10 +125,31 @@ function _M.validate_configuration(req_body, 
collect_all_errors)
     local is_valid = true
     local validation_results = {}
 
+    if type(req_body) ~= "table" then
+        local err_msg = "invalid request body: it should be an object"
+        if not collect_all_errors then
+            return false, err_msg
+        end
+        return false, {{resource_type = "", error = err_msg}}
+    end
+
     for key, conf_version_key in pairs(ALL_RESOURCE_KEYS) do
         local items = req_body[key]
         local resource = resources[key] or {}
 
+        -- a client can send any JSON/YAML value here; `#items` and `ipairs`
+        -- raise a Lua error on a scalar, and admin/standalone.lua calls this
+        -- without a pcall
+        if items ~= nil and type(items) ~= "table" then
+            local err_msg = key .. " must be an array, got " .. type(items)
+            if not collect_all_errors then
+                return false, err_msg
+            end
+            is_valid = false
+            table_insert(validation_results, {resource_type = key, error = 
err_msg})
+            items = nil
+        end

Review Comment:
   I think a JSON schema should be provided for input validation to be 
consistent with the existing admin API.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to