Skip to content

Commit 56e52eb

Browse files
committed
feat: allow access to forbidden location to specified user agents
1 parent d410259 commit 56e52eb

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ The entrypoint file contains a list of environment variables that will be replac
104104
- `NGINX_CLIENT_MAX_BODY_SIZE`: the maximum allowed size for the client request body (default: `200M`)
105105
- `NGINX_CORS_ENABLED`: enable cors for `/` path and the caller origin header represented by `$http_origin` nginx variable (<https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Origin>) (default: `0`)
106106
- `NGINX_CORS_DOMAINS`: a list of CORS enabled domains to activate cors just for the specified ones (no default provided)
107+
- `NGINX_FORBIDDEN_LOCATIONS_ALLOWED_USER_AGENTS`: a regexp (`startswith`) used to match the valid user agents that can call the forbidden locations (the response is empty, only a `return 200` is provided)
107108

108109
## Rootless feature
109110

docker-entrypoint.sh

+8
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,17 @@ if [ -n "${NGINX_BASIC_AUTH_USER}" ] && [ -n "${NGINX_BASIC_AUTH_PASS}" ]; then
7373
fi
7474

7575
# Activate the forbidden locations when the environment is not local
76+
NGINX_FORBIDDEN_LOCATIONS_ALLOWED_USER_AGENTS=${NGINX_FORBIDDEN_LOCATIONS_ALLOWED_USER_AGENTS:-}
77+
export NGINX_FORBIDDEN_LOCATIONS_ALLOWED_USER_AGENTS
7678
if [ "${ENV:-}" != "loc" ]; then
7779
print "Activating the forbidden locations"
7880
cp /templates/fragments/005-forbidden-locations.conf /etc/nginx/conf.d/fragments/005-forbidden-locations.conf
81+
82+
if [ -n "${NGINX_FORBIDDEN_LOCATIONS_ALLOWED_USER_AGENTS}" ]; then
83+
envsubst '$NGINX_FORBIDDEN_LOCATIONS_ALLOWED_USER_AGENTS' < /templates/fragments/005-forbidden-locations-user-agents-fragment.conf.tpl > /templates/fragments/005-forbidden-locations-user-agents-fragment.conf
84+
sed -e '/#forbidden-locations-allowed-user-agents/r /templates/fragments/005-forbidden-locations-user-agents-fragment.conf' -i /etc/nginx/conf.d/fragments/005-forbidden-locations.conf;
85+
fi
86+
sed -i '/#forbidden-locations-allowed-user-agents/d' /etc/nginx/conf.d/fragments/005-forbidden-locations.conf
7987
fi
8088

8189
# Activate HSTS header (default: off)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
if ($http_user_agent ~ ^${NGINX_FORBIDDEN_LOCATIONS_ALLOWED_USER_AGENTS}) {
2+
return 200;
3+
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
location = /core/install.php {
2+
#forbidden-locations-allowed-user-agents
23
return 404;
34
}
45

56
location = /update.php {
7+
#forbidden-locations-allowed-user-agents
68
return 404;
79
}

0 commit comments

Comments
 (0)