Files
nginx_lua_waf/waf.lua
2026-05-06 20:25:22 +08:00

34 lines
784 B
Lua
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- WAF统一入口模块
-- 功能集中管理所有安全检查IP限流、UA限制等
local _M = {}
-- 尝试加载resty.core如果失败则忽略兼容旧版本OpenResty
pcall(function()
require "resty.core"
end)
local rate_limiter = require "modules.rate_limiter"
local ua_limiter = require "modules.ua_limiter"
-- 执行所有安全检查
-- 返回值:
-- - true: 所有检查通过,允许访问
-- - false: 某个检查失败,已返回错误响应
function _M.check()
-- IP频率限制检查
if not rate_limiter.check_rate_limit() then
return false
end
-- User-Agent限制检查
if not ua_limiter.check_ua_limit() then
return false
end
-- 所有检查通过
return true
end
return _M