Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: elaborate on X-Forwarded-For header #314

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

joshua-mo-143
Copy link
Member

First draft for an elaboration on how exactly to use the X-Forwarded-For header.

@joshua-mo-143 joshua-mo-143 requested a review from oddgrd January 2, 2025 16:17
#### X-Forwarded-For
`X-Forwarded-For` is a header that allows you to get the original IP of the HTTP request. Deployed Shuttle projects sit behind a proxy, meaning that when you try to get the IP address normally you may end up with the proxy IP instead of the requester IP. With the `X-Forwarded-For` header, you can now always get the requester IP by parsing the given header value.

To implement your own custom rate limiting, our [blog post on how to write API rate limiting yourself](https://www.shuttle.dev/blog/2024/02/22/api-rate-limiting-rust) may prove useful. You can also additionally implement your own middleware that utilises the `governor` crate, as seen on [`tower-governor`](https://docs.rs/tower_governor/latest/tower_governor/) and [`actix-governor`](https://docs.rs/actix-governor/latest/actix_governor/).
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if this is the right place to link to rate limiting guides, as it's not the only use-case. I feel it would be more appropriate to link to the documentation for this header in the rate limiting guides themselves.

### Request Headers

#### X-Forwarded-For
`X-Forwarded-For` is a header that allows you to get the original IP of the HTTP request. Deployed Shuttle projects sit behind a proxy, meaning that when you try to get the IP address normally you may end up with the proxy IP instead of the requester IP. With the `X-Forwarded-For` header, you can now always get the requester IP by parsing the given header value.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we make it a bit more concise, perhaps like this?

Suggested change
`X-Forwarded-For` is a header that allows you to get the original IP of the HTTP request. Deployed Shuttle projects sit behind a proxy, meaning that when you try to get the IP address normally you may end up with the proxy IP instead of the requester IP. With the `X-Forwarded-For` header, you can now always get the requester IP by parsing the given header value.
Deployed Shuttle projects sit behind a proxy, so if you extract the peer address of the incoming connection in your application, it will be the address of our proxy. To allow you to get the IP address of the original client, the Shuttle proxy will set it in the `X-Forwarded-For` (link to the mdn docs for the header here) header in all requests to your project.

We are also using the header incorrectly, it should be a comma separated list of IPs, including the IP of our proxy. If it's just the original client IP, we should have a new custom header, as I understand it. But we can address that later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants