Skip to content

FIX: fastly template should be teaching nginx what to trust - #1077

Merged
Supermathie merged 1 commit into
mainfrom
fix_xff
Jun 16, 2026
Merged

FIX: fastly template should be teaching nginx what to trust#1077
Supermathie merged 1 commit into
mainfrom
fix_xff

Conversation

@Supermathie

Copy link
Copy Markdown
Member

The idea of replacing proxy_add_x_forwarded_for is ghastly - we have the
ability to teach nginx how to discern the correct values for the actual end
user IP instead of telling it to pass through the header to Discourse.

This means the server-side nginx logs will be correct, plus allows for more
complex setups.

The idea of replacing proxy_add_x_forwarded_for is ghastly - we have the
ability to teach nginx how to discern the correct values for the actual end
user IP instead of telling it to pass through the header to Discourse.

This means the server-side nginx logs will be correct, plus allows for more
complex setups.
@Supermathie
Supermathie merged commit a4ca75c into main Jun 16, 2026
7 checks passed
@Supermathie
Supermathie deleted the fix_xff branch June 16, 2026 20:23
Supermathie added a commit to discourse/discourse that referenced this pull request Jun 16, 2026
…er IP

nginx's responsibility is to determine the correct end user's IP (as far as we
can trust it) and report that to Discourse.

The correct way to do that is to teach nginx how to determine this for itself -
this means that both the nginx logs and the downstream value will be correct.

(see discourse/discourse_docker#1077 which removes the
only use of `proxy_add_x_forwarded_for`)

Setting the x-f-f header to `$proxy_add_x_forwarded_for` or
`$http_x_forwarded_for` hides this learned knowledge and forces Discourse to go
through the same process and possibly arrive at a edifferent answer.

In most cases this won't make a difference, but when there is more than one
proxy in front of Discourse this exposes a failure case.

client → proxyA → proxyB → nginx → discourse

means Discourse saw:
```
x-real-ip: client_ip
x-forwarded-for: client_ip, proxyA
```

and might end using `client_ip` or `proxyA_ip` depending on codepath.

After this change, Discourse sees:
```
x-real-ip: client_ip
x-forwarded-for: client_ip
```

for the same situation.
real_ip_header fastly-client-ip;
- exec:
cmd:
- apt-get update && apt-get install -y jq && apt-get clean

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel a little bad about this, but after we move to trixie we can pull yq-go into the base image for tasks like this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants