mirror of
https://github.com/dani-garcia/vaultwarden.git
synced 2026-04-26 01:35:54 +03:00
[GH-ISSUE #600] Client IP address is wrong when server is behind proxy #397
Labels
No labels
SSO
Third party
better for forum
bug
bug
documentation
duplicate
enhancement
future Vault
future Vault
future Vault
good first issue
help wanted
low priority
notes
pull-request
question
troubleshooting
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/vaultwarden#397
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @sercand on GitHub (Sep 3, 2019).
Original GitHub issue: https://github.com/dani-garcia/vaultwarden/issues/600
Bitwarden uses rocket's client_id function of request which doesn't use
X-Forwarded-Forheader to determine the client IP address.Proxies like Envoy and Aws Elastic Load Balancing uses
X-Forwarded-Forheader instead ofX-Real-IPfor forwarding client IP addresses.@dani-garcia commented on GitHub (Sep 5, 2019):
Well you could always configure the proxy to set the correct header, but you are right that
X-Real-IPdoesn't seem very popular compared to other headers, I wonder why Rocket decided to use that one.We could offer an option to check extra headers, as the current situation has been confusing for some people.
@mprasil commented on GitHub (Sep 13, 2019):
I feel like this should maybe be raised upstream in the rocket repository also?
@ryanjaeb commented on GitHub (Dec 27, 2019):
This is tough to deal with when using Cloudflare and Traefik (v2). I can't find a way to rewrite the headers. Traefik adds the connecting IP as
X-Real-IPif the header is missing and Cloudflare stripsX-Real-IP. Between the two,X-Real-IPalways ends up set to a Cloudflare IP.It would be awesome if this were user settable via an environment or config variable since that would support provider specific headers like Cloudflare's CF-Connecting-IP.
@dani-garcia commented on GitHub (Dec 27, 2019):
Okay seeing as the default header choice by rocket seems to be causing issues I've made it configurable in the latest commit,
github.com/dani-garcia/bitwarden_rs@88c56de97b.Set
IP_HEADER=CF-Connecting-IPorIP_HEADER=X-Forwarded-Forto make it use those respective headers, orIP_HEADER=noneto disable the header cheking. The default is still the same as before to avoid breaking anything.@ryanjaeb commented on GitHub (Dec 28, 2019):
@dani-garcia I just tested this with the latest
bitwardenrs/server:alpineDocker image (sha256:64344a72bc0fc48df1ab421aa56154cfd18a331a066bc685a8def3f7f3adbca6). It works great withCF-Connecting-IP. Thank you!However, I also tested it with
X-Forwarded-Forand I end up seeing the IP address of my Traefik container, which would be the connecting IP as seen by my bitwarden_rs container. MyX-Forwarded-Forheader looks like this:I turned on trace logging and see:
The value shown in binary (
[ removed ]) is correct and does not include the IP address of my Traefik container. I've never written any Rust, but my best guess is the comma separated IP list doesn't parse correctly and it falls back to using the connecting IP.If that's correct, I think it's normal to treat the first IP address in the X-Forwarded-For header as the client IP, even though it can be spoofed on poorly configured proxies.
I really appreciate you adding the config option, so please let me know if I can do any testing or provide any config examples that would be useful.
@dani-garcia commented on GitHub (Dec 28, 2019):
Ah, I didn't know X-Forwarded-For had a different format!
Your explanation sounds right, if the contents of the header can't parse as an IP, then I print a warning and fall back to the remote IP.
github.com/dani-garcia/bitwarden_rs@5c6081c4e2/src/auth.rs (L433)It should work now in the latest master
github.com/dani-garcia/bitwarden_rs@cb6f392774.Yeah all these headers can be sent directly by the user, so we depend on the proxies to be configured correctly to either remove them or replace them with the correct value. Now that you mention it, we should make sure to mention it at least in the Fail2Ban and Proxy wiki pages.
@sercand commented on GitHub (Jan 26, 2020):
I think we can close this with the 1.13.1 release.
@dadatuputi commented on GitHub (Jun 7, 2020):
It would be nice to have this option documented in the env template and wiki. This was necessary to get fail2ban working properly with caddy.