Skip to content

Commit 8381b8f

Browse files
committed
Fix : UserAgent filter raise exception when user agent is null
1 parent ed44a9c commit 8381b8f

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

VeryNginx/lua_script/module/filter.lua

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@ end
2626

2727
function _M.filter_ip()
2828
if VeryNginxConfig.configs["filter_ip_enable"] ~= true then
29-
return false;
29+
return true
3030
end
3131

3232
local remote_addr = ngx.var.remote_addr
3333
for i, v in ipairs( VeryNginxConfig.configs['filter_ip_rule'] ) do
3434
if v[1] == remote_addr then
35-
return true
35+
return false
3636
end
3737
end
3838

39-
return false
39+
return true
4040
end
4141

4242
function _M.filter_useragent()
@@ -47,6 +47,10 @@ function _M.filter_useragent()
4747
local find = ngx.re.find
4848
local http_user_agent = ngx.var.http_user_agent
4949

50+
if http_user_agent == nil then
51+
return true
52+
end
53+
5054
for i, v in ipairs( VeryNginxConfig.configs["filter_useragent_rule"] ) do
5155
if find( http_user_agent, v[1], "is" ) then
5256
return false
@@ -108,7 +112,7 @@ function _M.filter()
108112
return
109113
end
110114

111-
if _M.filter_ip() == true then
115+
if _M.filter_ip() ~= true then
112116
ngx.exit( ngx.HTTP_SERVICE_UNAVAILABLE )
113117
end
114118

0 commit comments

Comments
 (0)