Allow to add a whitelist by site on user-agent
This commit is contained in:
parent
d5d699252c
commit
8353bd9c85
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
.idea/
|
||||||
@ -1040,6 +1040,12 @@ Default value : *.googlebot.com .google.com .search.msn.com .crawl.yahoot.net .c
|
|||||||
Context : *global*
|
Context : *global*
|
||||||
The list of reverse DNS suffixes to whitelist when `USE_WHITELIST_REVERSE` is set to *yes*. The default list contains suffixes of major search engines.
|
The list of reverse DNS suffixes to whitelist when `USE_WHITELIST_REVERSE` is set to *yes*. The default list contains suffixes of major search engines.
|
||||||
|
|
||||||
|
`WHITELIST_USERAGENT_LIST`
|
||||||
|
Values : *"useragent1", "^[user]agent2"*
|
||||||
|
Default value : **
|
||||||
|
Context : *global*, *multisite*
|
||||||
|
Whitelist user agent from be blocked by `BLOCK_USER_AGENT`
|
||||||
|
|
||||||
### Custom blacklisting
|
### Custom blacklisting
|
||||||
|
|
||||||
`USE_BLACKLIST_IP`
|
`USE_BLACKLIST_IP`
|
||||||
|
|||||||
@ -6,6 +6,7 @@ access_by_lua_block {
|
|||||||
local use_whitelist_ip = %USE_WHITELIST_IP%
|
local use_whitelist_ip = %USE_WHITELIST_IP%
|
||||||
local use_whitelist_reverse = %USE_WHITELIST_REVERSE%
|
local use_whitelist_reverse = %USE_WHITELIST_REVERSE%
|
||||||
local use_user_agent = %USE_USER_AGENT%
|
local use_user_agent = %USE_USER_AGENT%
|
||||||
|
local whitelist_useragent_list = { %WHITELIST_USERAGENT_LIST% }
|
||||||
local use_referrer = %USE_REFERRER%
|
local use_referrer = %USE_REFERRER%
|
||||||
local use_country = %USE_COUNTRY%
|
local use_country = %USE_COUNTRY%
|
||||||
local use_blacklist_ip = %USE_BLACKLIST_IP%
|
local use_blacklist_ip = %USE_BLACKLIST_IP%
|
||||||
@ -80,6 +81,19 @@ end
|
|||||||
|
|
||||||
-- check if user-agent is allowed
|
-- check if user-agent is allowed
|
||||||
if use_user_agent and ngx.var.bad_user_agent == "yes" then
|
if use_user_agent and ngx.var.bad_user_agent == "yes" then
|
||||||
|
local headers = ngx.req.get_headers()
|
||||||
|
local ua = headers["User-Agent"]
|
||||||
|
if not whitelist_useragent_list ~= "" then
|
||||||
|
local k_ua_white, v_ua_white = next(whitelist_useragent_list, nil)
|
||||||
|
while v_ua_white do
|
||||||
|
local rst_whitelist = string.match(ua, v_ua_white)
|
||||||
|
if rst_whitelist ~= nil and rst_whitelist ~= "" then
|
||||||
|
ngx.log(ngx.WARN, "[ALLOW] User-Agent " .. ngx.var.http_user_agent .. " is whitelisted")
|
||||||
|
ngx.exit(ngx.OK)
|
||||||
|
end
|
||||||
|
k_ua_white, v_ua_white = next(whitelist_useragent_list, k_ua_white)
|
||||||
|
end
|
||||||
|
end
|
||||||
ngx.log(ngx.WARN, "[BLOCK] User-Agent " .. ngx.var.http_user_agent .. " is blacklisted")
|
ngx.log(ngx.WARN, "[BLOCK] User-Agent " .. ngx.var.http_user_agent .. " is blacklisted")
|
||||||
ngx.exit(ngx.HTTP_FORBIDDEN)
|
ngx.exit(ngx.HTTP_FORBIDDEN)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -45,6 +45,7 @@ DISABLE_DEFAULT_SERVER="${DISABLE_DEFAULT_SERVER-no}"
|
|||||||
SERVER_NAME="${SERVER_NAME-www.bunkerity.com}"
|
SERVER_NAME="${SERVER_NAME-www.bunkerity.com}"
|
||||||
ALLOWED_METHODS="${ALLOWED_METHODS-GET|POST|HEAD}"
|
ALLOWED_METHODS="${ALLOWED_METHODS-GET|POST|HEAD}"
|
||||||
BLOCK_USER_AGENT="${BLOCK_USER_AGENT-yes}"
|
BLOCK_USER_AGENT="${BLOCK_USER_AGENT-yes}"
|
||||||
|
WHITELIST_USERAGENT_LIST="${WHITELIST_USERAGENT_LIST-}"
|
||||||
BLOCK_REFERRER="${BLOCK_REFERRER-yes}"
|
BLOCK_REFERRER="${BLOCK_REFERRER-yes}"
|
||||||
BLOCK_TOR_EXIT_NODE="${BLOCK_TOR_EXIT_NODE-yes}"
|
BLOCK_TOR_EXIT_NODE="${BLOCK_TOR_EXIT_NODE-yes}"
|
||||||
BLOCK_PROXIES="${BLOCK_PROXIES-yes}"
|
BLOCK_PROXIES="${BLOCK_PROXIES-yes}"
|
||||||
|
|||||||
@ -276,6 +276,11 @@ fi
|
|||||||
# block bad UA
|
# block bad UA
|
||||||
if [ "$BLOCK_USER_AGENT" = "yes" ] ; then
|
if [ "$BLOCK_USER_AGENT" = "yes" ] ; then
|
||||||
replace_in_file "${NGINX_PREFIX}main-lua.conf" "%USE_USER_AGENT%" "true"
|
replace_in_file "${NGINX_PREFIX}main-lua.conf" "%USE_USER_AGENT%" "true"
|
||||||
|
if [ "$WHITELIST_USERAGENT_LIST" != "" ] ; then
|
||||||
|
replace_in_file "${NGINX_PREFIX}main-lua.conf" "%WHITELIST_USERAGENT_LIST%" "$WHITELIST_USERAGENT_LIST"
|
||||||
|
else
|
||||||
|
replace_in_file "${NGINX_PREFIX}main-lua.conf" "%WHITELIST_USERAGENT_LIST%" ""
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
replace_in_file "${NGINX_PREFIX}main-lua.conf" "%USE_USER_AGENT%" "false"
|
replace_in_file "${NGINX_PREFIX}main-lua.conf" "%USE_USER_AGENT%" "false"
|
||||||
fi
|
fi
|
||||||
|
|||||||
@ -684,6 +684,14 @@
|
|||||||
"regex":"^([A-Z]{2} ?)*$",
|
"regex":"^([A-Z]{2} ?)*$",
|
||||||
"id":"whitelist-country",
|
"id":"whitelist-country",
|
||||||
"default":""
|
"default":""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type":"text",
|
||||||
|
"label":"Whitelist user agent list",
|
||||||
|
"env":"WHITELIST_USERAGENT_LIST",
|
||||||
|
"regex":".*",
|
||||||
|
"id":"whitelist-user-agent-list",
|
||||||
|
"default":""
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user