This is an automated email from the ASF dual-hosted git repository. spacewander pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/apisix.git
The following commit(s) were added to refs/heads/master by this push: new 4423509 fix(ua-restriction): refine plugin configuration check logic (#5728) 4423509 is described below commit 4423509680a0c2103ce23b30a0da71735ef73e8f Author: jackfu <jackfu1...@gmail.com> AuthorDate: Sun Dec 19 19:51:32 2021 +0800 fix(ua-restriction): refine plugin configuration check logic (#5728) Co-authored-by: jack.fu <jack...@yijinin.com> --- apisix/plugins/ua-restriction.lua | 31 ++++++++++++++++++++-- t/plugin/ua-restriction.t | 54 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 2 deletions(-) diff --git a/apisix/plugins/ua-restriction.lua b/apisix/plugins/ua-restriction.lua index 3683a15..ec74e75 100644 --- a/apisix/plugins/ua-restriction.lua +++ b/apisix/plugins/ua-restriction.lua @@ -16,6 +16,7 @@ -- local ipairs = ipairs local core = require("apisix.core") +local re_compile = require("resty.core.regex").re_match_compile local stringx = require('pl.stringx') local type = type local str_strip = stringx.strip @@ -36,11 +37,19 @@ local schema = { }, allowlist = { type = "array", - minItems = 1 + minItems = 1, + items = { + type = "string", + minLength = 1, + } }, denylist = { type = "array", - minItems = 1 + minItems = 1, + items = { + type = "string", + minLength = 1, + } }, message = { type = "string", @@ -88,6 +97,24 @@ function _M.check_schema(conf) return false, err end + if conf.allowlist then + for _, re_rule in ipairs(conf.allowlist) do + ok, err = re_compile(re_rule, "j") + if not ok then + return false, err + end + end + end + + if conf.denylist then + for _, re_rule in ipairs(conf.denylist) do + ok, err = re_compile(re_rule, "j") + if not ok then + return false, err + end + end + end + return true end diff --git a/t/plugin/ua-restriction.t b/t/plugin/ua-restriction.t index 77c6874..82e6658 100644 --- a/t/plugin/ua-restriction.t +++ b/t/plugin/ua-restriction.t @@ -739,3 +739,57 @@ hello world } --- response_body passed + + + +=== TEST 33: the element in allowlist is null +--- config + location /t { + content_by_lua_block { + local plugin = require("apisix.plugins.ua-restriction") + local conf = { + allowlist = { + "userdata: NULL", + null, + nil, + "" + }, + } + local ok, err = plugin.check_schema(conf) + if not ok then + ngx.say(err) + end + + ngx.say("done") + } + } +--- response_body +property "allowlist" validation failed: wrong type: expected array, got table +done + + + +=== TEST 34: the element in denylist is null +--- config + location /t { + content_by_lua_block { + local plugin = require("apisix.plugins.ua-restriction") + local conf = { + denylist = { + "userdata: NULL", + null, + nil, + "" + }, + } + local ok, err = plugin.check_schema(conf) + if not ok then + ngx.say(err) + end + + ngx.say("done") + } + } +--- response_body +property "denylist" validation failed: wrong type: expected array, got table +done