Skip to content

Commit e0cdaf2

Browse files
Bugfix: Proxy protocol doesn't mix with NAXSI
Fixes a bug in which requests blocked by NAXSI came back as a 502 rather than a 418 when running with proxy protocol enabled. This is because the /RequestDenied route proxies to localhost but doesn't know to speak proxy protocol. This has been fixed by giving NAXSI its own private port (defaults to 10418) that never expects proxy protocol. Also makes the port configurable via an environment variable. This may also be useful for SysDig.
1 parent 9b2e2c5 commit e0cdaf2

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ This is useful when testing or for development instances or when a load-balancer
7878
* `SSL_CIPHERS` - Change the SSL ciphers support default only AES256+EECDH:AES256+EDH:!aNULL
7979
* `SSL_PROTOCOLS` - Change the SSL protocols supported default only TLSv1.2
8080
* `HTTP_LISTEN_PORT` - Change the default inside the container from 80.
81-
* `HTTPS_LISTEN_PORT` - Change the default inside the container from 443.
81+
* `HTTPS_LISTEN_PORT` - Change the default inside the container from 443.
82+
* `INTERNAL_LISTEN_PORT` - Change the default inside the container from 10418. Note: This is used for internal processing and is not available externally.
8283
* `HTTPS_REDIRECT` - Toggle whether or not we force redirects to HTTPS. Defaults to true.
8384
* `ALLOW_COUNTRY_CSV` - List of [country codes](http://dev.maxmind.com/geoip/legacy/codes/iso3166/) to allow.
8485
* `STATSD_METRICS_ENABLED` - Toggle if metrics are logged to statsd (defaults to true)

go.sh

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,35 @@ if [ "${LOCATIONS_CSV}" == "" ]; then
2626
LOCATIONS_CSV=/
2727
fi
2828

29+
INTERNAL_LISTEN_PORT="${INTERNAL_LISTEN_PORT:-10418}"
30+
NGIX_LISTEN_CONF="${NGIX_CONF_DIR}/nginx_listen.conf"
31+
32+
cat > ${NGIX_LISTEN_CONF} <<-EOF-LISTEN
33+
set \$http_listen_port '${HTTP_LISTEN_PORT}';
34+
set \$https_listen_port '${HTTPS_LISTEN_PORT}';
35+
set \$internal_listen_port '${INTERNAL_LISTEN_PORT}';
36+
listen localhost:${INTERNAL_LISTEN_PORT} ssl;
37+
EOF-LISTEN
38+
2939
if [ "${LOAD_BALANCER_CIDR}" != "" ]; then
3040
msg "Using proxy_protocol from '$LOAD_BALANCER_CIDR' (real client ip is forwarded correctly by loadbalancer)..."
3141
export REMOTE_IP_VAR="proxy_protocol_addr"
32-
cat > ${NGIX_CONF_DIR}/nginx_listen.conf <<-EOF-LISTEN-PP
42+
cat >> ${NGIX_LISTEN_CONF} <<-EOF-LISTEN-PP
3343
listen ${HTTP_LISTEN_PORT} proxy_protocol;
3444
listen ${HTTPS_LISTEN_PORT} proxy_protocol ssl;
3545
real_ip_recursive on;
3646
real_ip_header proxy_protocol;
3747
set \$real_client_ip_if_set '\$proxy_protocol_addr ';
3848
set_real_ip_from ${LOAD_BALANCER_CIDR};
39-
set \$http_listen_port '${HTTP_LISTEN_PORT}';
40-
set \$https_listen_port '${HTTPS_LISTEN_PORT}';
4149
EOF-LISTEN-PP
4250
else
4351
msg "No \$LOAD_BALANCER_CIDR set, using straight SSL (client ip will be from loadbalancer if used)..."
4452
export REMOTE_IP_VAR="remote_addr"
45-
cat > ${NGIX_CONF_DIR}/nginx_listen.conf <<-EOF-LISTEN
46-
listen ${HTTP_LISTEN_PORT} ;
53+
cat >> ${NGIX_LISTEN_CONF} <<-EOF-LISTEN-NONPP
54+
listen ${HTTP_LISTEN_PORT};
4755
listen ${HTTPS_LISTEN_PORT} ssl;
4856
set \$real_client_ip_if_set '';
49-
set \$http_listen_port '${HTTP_LISTEN_PORT}';
50-
set \$https_listen_port '${HTTPS_LISTEN_PORT}';
51-
EOF-LISTEN
57+
EOF-LISTEN-NONPP
5258
fi
5359

5460
IFS=',' read -a LOCATIONS_ARRAY <<< "$LOCATIONS_CSV"

nginx.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ http {
132132

133133
location /RequestDenied {
134134
# Proxy to ourselves in order to access NAXSI debugging headers
135-
proxy_pass https://127.0.0.1:$https_listen_port/nginx-proxy/RequestDenied;
135+
proxy_pass https://127.0.0.1:$internal_listen_port/nginx-proxy/RequestDenied;
136136
internal;
137137
}
138138

0 commit comments

Comments
 (0)