searchusermenu
  • 发布文章
  • 消息中心
点赞
收藏
评论
分享
原创

采用LUA屏蔽原生返回信息

2023-06-15 14:23:50
3
0

# 原生信息屏蔽

## 修改body_filter.lua

local cjson = require("cjson")
local cjson2 = cjson.new()
local resp,eof = ngx.arg[1],ngx.arg[2]
ptn="(java\\.lang\\.*)|(xception)|(error)|(Error)|(JSONObject)|(unexpected[%s]?error)|(too[%s]many[%s]values[%s]to[%s]unpack)|(NoneType)"
if resp ~= "" and not ngx.is_subrequest then
    if pcall(cjson.decode,resp) then
        ngx.log(ngx.ERR,"[resp_data_type]:", type(resp),"[resp_data]:", resp,"[eof]:", eof)
        local t = cjson.decode(resp)
        if t.code and t.code ~= 200 and t.msg then
            local m, err = ngx.re.match(t.msg, ptn, "jo")
            if m then
                t.msg = 'request failed'
            end
        end
end

## nginx配置返回信息过滤

body_filter_by_lua_file /etc/nginx/conf.d/body_filter.lua;

## nginx配置屏蔽内容长度

header_filter_by_lua 'ngx.header.content_length = nil';

0条评论
0 / 1000
x****n
2文章数
0粉丝数
x****n
2 文章 | 0 粉丝
x****n
2文章数
0粉丝数
x****n
2 文章 | 0 粉丝
原创

采用LUA屏蔽原生返回信息

2023-06-15 14:23:50
3
0

# 原生信息屏蔽

## 修改body_filter.lua

local cjson = require("cjson")
local cjson2 = cjson.new()
local resp,eof = ngx.arg[1],ngx.arg[2]
ptn="(java\\.lang\\.*)|(xception)|(error)|(Error)|(JSONObject)|(unexpected[%s]?error)|(too[%s]many[%s]values[%s]to[%s]unpack)|(NoneType)"
if resp ~= "" and not ngx.is_subrequest then
    if pcall(cjson.decode,resp) then
        ngx.log(ngx.ERR,"[resp_data_type]:", type(resp),"[resp_data]:", resp,"[eof]:", eof)
        local t = cjson.decode(resp)
        if t.code and t.code ~= 200 and t.msg then
            local m, err = ngx.re.match(t.msg, ptn, "jo")
            if m then
                t.msg = 'request failed'
            end
        end
end

## nginx配置返回信息过滤

body_filter_by_lua_file /etc/nginx/conf.d/body_filter.lua;

## nginx配置屏蔽内容长度

header_filter_by_lua 'ngx.header.content_length = nil';

文章来自个人专栏
文章 | 订阅
0条评论
0 / 1000
请输入你的评论
0
0