Skip to content

Commit 0cb410f

Browse files
tgxworldjancernik
authored andcommitted
FIX: Scrub Client-Ip request header in nginx (discourse#30971)
We are scrubbing the `Client-Ip` request header at the nginx proxy because it is not a request header which we have decided to trust. Our application should only use the `X-Fowarded-For` request header instead. This change helps to resolve `ActionDispatch::RemoteIp::IpSpoofAttackError` errors from being raised by the `ActionDispatch::RemoteIp` when the request headers contains both `Client-Ip` and `X-Forwarded-For`. At the time of writing, https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For also states that "The HTTP X-Forwarded-For (XFF) request header is a de-facto standard header for identifying the originating IP address of a client connecting to a web server through a proxy server."
1 parent f58b244 commit 0cb410f

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

config/nginx.sample.conf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ server {
109109
proxy_set_header X-Forwarded-Proto $thescheme;
110110
proxy_set_header X-Sendfile-Type "";
111111
proxy_set_header X-Accel-Mapping "";
112+
proxy_set_header Client-Ip "";
112113
proxy_pass http://discourse;
113114
break;
114115
}
@@ -121,6 +122,7 @@ server {
121122
proxy_set_header X-Forwarded-Proto $thescheme;
122123
proxy_set_header X-Sendfile-Type "";
123124
proxy_set_header X-Accel-Mapping "";
125+
proxy_set_header Client-Ip "";
124126
proxy_pass http://discourse;
125127
break;
126128
}
@@ -141,6 +143,7 @@ server {
141143
proxy_set_header X-Forwarded-Proto $thescheme;
142144
proxy_set_header X-Sendfile-Type "";
143145
proxy_set_header X-Accel-Mapping "";
146+
proxy_set_header Client-Ip "";
144147
proxy_pass http://discourse;
145148
break;
146149
}
@@ -244,6 +247,7 @@ server {
244247
proxy_set_header X-Forwarded-Proto $thescheme;
245248
proxy_set_header X-Sendfile-Type "";
246249
proxy_set_header X-Accel-Mapping "";
250+
proxy_set_header Client-Ip "";
247251

248252
# if Set-Cookie is in the response nothing gets cached
249253
# this is double bad cause we are not passing last modified in
@@ -270,6 +274,7 @@ server {
270274
proxy_set_header X-Forwarded-Proto $thescheme;
271275
proxy_set_header X-Sendfile-Type "";
272276
proxy_set_header X-Accel-Mapping "";
277+
proxy_set_header Client-Ip "";
273278
proxy_http_version 1.1;
274279
proxy_buffering off;
275280
proxy_pass http://discourse;
@@ -293,6 +298,7 @@ server {
293298
proxy_set_header X-Forwarded-Proto $thescheme;
294299
proxy_set_header X-Sendfile-Type "";
295300
proxy_set_header X-Accel-Mapping "";
301+
proxy_set_header Client-Ip "";
296302
proxy_pass http://discourse;
297303
}
298304

0 commit comments

Comments
 (0)