You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
uuWAF/rules/data-mask.lua

41 lines
1.2 KiB

3 months ago
--[[
:
:
:
: *
--]]
if waf.respContentLength == 0 or waf.respContentLength >= 2097152 then
return
end
-- 只保留身份证号前2位和后2位
1 month ago
local newstr, n, err = waf.rgxGsub(waf.respBody, [[\b((1[1-5]|2[1-3]|3[1-7]|4[1-6]|5[0-4]|6[1-5]|[7-9]1)\d{4}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx])\b]], function(m)
3 months ago
return m[0]:sub(1, 2) .. "**************" .. m[0]:sub(-2)
end, "jos")
if not newstr then
waf.errLog("error: ", err)
return
end
1 month ago
if n > 0 then
waf.respBody = newstr
-- 通知南墙进行数据替换
waf.replaceFilter = true
end
3 months ago
-- 只保留手机号前3位和后4位
1 month ago
newstr, n, err = waf.rgxGsub(waf.respBody, [[\b1(?:(((3[0-9])|(4[5-9])|(5[0-35-9])|(6[2,5-7])|(7[0135-8])|(8[0-9])|(9[0-35-9]))[ -]?\d{4}[ -]?\d{4})|((74)[ -]?[0-5]\d{3}[ -]?\d{4}))\b]], function(m)
3 months ago
return m[0]:sub(1, 3) .. "****" .. m[0]:sub(-4)
end, "jos")
if not newstr then
waf.errLog("error: ", err)
return
end
1 month ago
if n > 0 then
waf.respBody = newstr
-- 通知南墙进行数据替换
waf.replaceFilter = true
end