mirror of
https://github.com/kanidm/kanidm.git
synced 2025-02-23 12:37:00 +01:00
Fix ip addr parse (#1729)
This commit is contained in:
parent
18fe86db26
commit
38f8ab2f99
|
@ -186,12 +186,12 @@ impl RequestExtensions for tide::Request<AppState> {
|
|||
/// Returns the remote address of the client, based on if you've got trust_x_forward_for set in config.
|
||||
fn get_remote_addr(&self) -> Option<IpAddr> {
|
||||
if self.state().trust_x_forward_for {
|
||||
// split the socket address off if we've got one, then parse it as an `IpAddr`
|
||||
// xff headers don't have a port, but if we're going direct you might get one
|
||||
let res = self
|
||||
.remote()
|
||||
.map(|addr| addr.split(':').next().unwrap_or(addr))
|
||||
.and_then(|ip| ip.parse::<IpAddr>().ok());
|
||||
let res = self.remote().and_then(|ip| {
|
||||
ip.parse::<IpAddr>()
|
||||
.ok()
|
||||
.or_else(|| ip.parse::<SocketAddr>().map(|s_ad| s_ad.ip()).ok())
|
||||
});
|
||||
debug!("Trusting XFF, using remote src_ip={:?}", res);
|
||||
res
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue