1 Star 0 Fork 24

xzplink/zhongkui-waf

forked from bukale/zhongkui-waf 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
body_filter.lua 1.40 KB
一键复制 编辑 原始数据 按行查看 历史
bukale 提交于 2023-06-18 11:32 . 代码完善,增加bot识别开关判断
local sensitive = require "sensitive"
local config = require "config"
local ngxfind = ngx.re.find
local gsub = string.gsub
local CONTENT_TYPE_REGEX = "^(?:text/html|text/plain|text/xml|application/json|application/xml|application/xhtml\\+xml)"
local HTML_CONTENT_TYPE_REGEX = "^(?:text/html|application/xhtml\\+xml)"
local TRAP_URI = config.botTrapUri
local TRAP_HTML = '<a href="' .. TRAP_URI .. '" class="honeyLink">come-here</a><style>.honeyLink{display:none;}</style></body>'
local content = ngx.arg[1]
if config.isWAFOn and config.isProtectionMode then
if ngx.status ~= 403 then
local contentType = ngx.header.content_type or ''
if config.isSensitiveDataFilteringOn then
if contentType then
local from = ngxfind(contentType, CONTENT_TYPE_REGEX, "isjo")
if from then
if content then
content = sensitive.sensitive_data_filtering(content)
end
end
end
end
if config.isBotOn and config.isBotTrapOn then
if contentType then
local from = ngxfind(contentType, HTML_CONTENT_TYPE_REGEX, "isjo")
if from then
if content then
content = gsub(content, '</body>', TRAP_HTML)
end
end
end
end
end
end
ngx.arg[1] = content
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Lua
1
https://gitee.com/xzplink/zhongkui-waf.git
git@gitee.com:xzplink/zhongkui-waf.git
xzplink
zhongkui-waf
zhongkui-waf
master

搜索帮助