Skip to content

Commit

Permalink
Fix setting X-Forwarded-For inside of ALB setup
Browse files Browse the repository at this point in the history
If somebody is setting X-Forwarded-For it will lead to X-Real-Ip
containing a list instead of a fixed IP.

We can instead trust the last item in the X-Forwarded-For list since
this comes from ALB as we are running it in append mode (see:
https://docs.aws.amazon.com/elasticloadbalancing/latest/application/application-load-balancers.html)
  • Loading branch information
hellais committed Dec 11, 2024
1 parent 3922e84 commit 93b1db1
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ gzip_proxied any;
gzip_types text/plain application/json;
gzip_min_length 1000;


server {
listen 8080;
location /stub_status {
Expand All @@ -11,6 +12,8 @@ server {
}

server {
real_ip_header X-Forwarded-For;

listen 80;

server_name _;
Expand All @@ -26,7 +29,7 @@ server {
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $http_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_cache_bypass $http_upgrade;
}
}
Expand Down

0 comments on commit 93b1db1

Please sign in to comment.