mirror of
https://github.com/potats0/lua-resty-coraza.git
synced 2025-06-28 17:41:00 +03:00
feat: 添加错误消息
This commit is contained in:
parent
09a8d0834f
commit
57f31a904a
@ -19,28 +19,21 @@ local core_log = core.log
|
|||||||
local coraza = require "resty.coraza"
|
local coraza = require "resty.coraza"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
local schema = {
|
local schema = {
|
||||||
type = "object",
|
type = "object",
|
||||||
properties = {
|
properties = {
|
||||||
Mode = {
|
mode = {
|
||||||
description = "waf running at block mode or monitor mode",
|
description = "waf running at block mode or monitor mode.",
|
||||||
type = "string"
|
type = "string"
|
||||||
},
|
},
|
||||||
Rules = {
|
rules = {
|
||||||
type = "array",
|
description = "self waf rules.",
|
||||||
items = {
|
type = "array"
|
||||||
type = "string",
|
|
||||||
minLength = 1,
|
|
||||||
maxLength = 4096,
|
|
||||||
},
|
|
||||||
uniqueItems = true
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
required = {"Mode"},
|
required = {"mode"},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
local plugin_name = "apisix-coraza"
|
local plugin_name = "apisix-coraza"
|
||||||
|
|
||||||
local _M = {
|
local _M = {
|
||||||
@ -52,12 +45,20 @@ local _M = {
|
|||||||
|
|
||||||
function _M.check_schema(conf)
|
function _M.check_schema(conf)
|
||||||
core.log.info("check coraza schema")
|
core.log.info("check coraza schema")
|
||||||
if conf.Rules ~= nil then
|
local ok, err = core.schema.check(schema, conf)
|
||||||
for i, rule in ipairs(conf.Rules) do
|
if not ok then
|
||||||
coraza.rules_add(rule)
|
return false, err
|
||||||
|
end
|
||||||
|
if conf.rules ~= nil then
|
||||||
|
for i, rule in ipairs(conf.rules) do
|
||||||
|
local ok, msg = coraza.rules_add(rule)
|
||||||
|
ngx.log(ngx.ERR, ok)
|
||||||
|
if not ok then
|
||||||
|
return false, rule..msg
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return core.schema.check(schema, conf)
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
function _M.init()
|
function _M.init()
|
||||||
@ -75,7 +76,6 @@ end
|
|||||||
|
|
||||||
function _M.header_filter(conf, ctx)
|
function _M.header_filter(conf, ctx)
|
||||||
core.log.info("plugin access phase, conf: ", core.json.delay_encode(conf))
|
core.log.info("plugin access phase, conf: ", core.json.delay_encode(conf))
|
||||||
-- each connection will be created a transaction
|
|
||||||
coraza.do_header_filter()
|
coraza.do_header_filter()
|
||||||
ngx.status, _ = coraza.do_handle()
|
ngx.status, _ = coraza.do_handle()
|
||||||
core.response.clear_header_as_body_modified()
|
core.response.clear_header_as_body_modified()
|
||||||
@ -91,4 +91,4 @@ function _M.log(conf, ctx)
|
|||||||
coraza.do_free()
|
coraza.do_free()
|
||||||
end
|
end
|
||||||
|
|
||||||
return _M
|
return _M
|
||||||
|
Loading…
x
Reference in New Issue
Block a user