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

X-Forwarded-For is parsed incorrectly! #28

Closed
Qqwy opened this issue Dec 21, 2021 · 3 comments
Closed

X-Forwarded-For is parsed incorrectly! #28

Qqwy opened this issue Dec 21, 2021 · 3 comments

Comments

@Qqwy
Copy link

Qqwy commented Dec 21, 2021

Given an X-Forwarded-For header like 203.0.113.195, 70.41.3.18, 150.172.238.178

remote_ip will currently replace the request's IP with 150.172.238.178.

(e.g.

iex> RemoteIp.from([{"x-forwarded-for", "203.0.113.195, 70.41.3.18, 150.172.238.178"}])
{150, 172, 238, 178}

)

However, this is incorrect. according to MDN the client IP is the first one in this list.

@ajvondrak
Copy link
Owner

Not a bug. IPs are processed last-to-first to prevent IP spoofing. If we trusted the first IP, it'd be trivial to spoof the IP of a request by setting a fake header, like curl -H "X-Forwarded-For: 1.2.3.4" http://your.site/.

Further reading:

If you know 150.172.238.178 and 70.41.3.18 are trusted proxies, configure the :proxies option accordingly (see https://hexdocs.pm/remote_ip/RemoteIp.Options.html).

@Qqwy
Copy link
Author

Qqwy commented Dec 22, 2021

Thank you for your reply and pointing to some articles with more information 😃 .

@ajvondrak
Copy link
Owner

Sure thing. Hope it makes sense. :)

@Qqwy Qqwy changed the title X-Forwarded-From is parsed incorrectly! X-Forwarded-For is parsed incorrectly! Dec 27, 2021
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

No branches or pull requests

2 participants