-
Notifications
You must be signed in to change notification settings - Fork 945
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
swarm: disallow dialing of 0.0.0.0
#4460
Comments
Thanks for the ping! The way we handle rust-libp2p/transports/tcp/src/lib.rs Lines 384 to 391 in 6f0895f
Under the hood, this uses https://github.com/mxinden/if-watch/. |
The issue is not about the listener side, it's about dialing 0.0.0.0. |
My point was towards this in that we never advertise But I guess what you are saying is that we should still deny a dial for |
Right. You shouldn't advertise it, but you need to correctly handle all kinds of nonsense that other peers might try to tell you. 0.0.0.0 is one example of such nonsense that caught us by surprise in go-libp2p. |
go-libp2p fix: libp2p/go-libp2p#2560 |
0.0.0.0
I want to address this; my initial thought goes as follows. Immediately after https://github.com/libp2p/rust-libp2p/blob/master/swarm/src/lib.rs#L438 I want to add the following filtering: let dial_address_errors = dial_opts
.get_addresses()
.iter()
.map(|address| {
// Collect errors per address.
address
.iter()
.filter_map(|protocol| match protocol {
Protocol::Ip4(ip) if ip.is_unspecified() => Some(AddressError::Ip4(ip)),
Protocol::Ip6(ip) if ip.is_unspecified() => Some(AddressError::Ip6(ip)),
_ => None,
})
.collect::<Vec<_>>()
})
.flatten()
.collect::<Vec<_>>();
if !dial_address_errors.is_empty() {
return DialError::AddressConfiguration(dial_address_errors);
} This filtering shall collect all errors in all address configurations and report them as a single error. |
Filtering the addresses sounds good to me. We need to do it as late as possible, after we gathered the addresses from the behaviours. We should also add a log statement to inform users that we are dropping one of they addresses they provided. Overall, this may result in a This will need a test too! |
I planned to introduce a new error variant in Would you prefer to
Let me know, and I will be able to make a PR. |
Adding a new variant will be a breaking change so I'd rather not do that for such a corner case. I think filtering is fine. Most users will never hit this so adding an extra variant for that is unnecessary complexity :) |
Hey @thomaseizinger let addresses = HashSet::from([
multiaddr![Ip4([0, 0, 0, 0]), Tcp(rand::random::<u16>())],
multiaddr![Ip4([0, 0, 0, 0]), Tcp(rand::random::<u16>())],
multiaddr![Ip4([0, 0, 0, 0]), Tcp(rand::random::<u16>())],
multiaddr![Udp(rand::random::<u16>())],
multiaddr![Udp(rand::random::<u16>())],
multiaddr![Udp(rand::random::<u16>())],
multiaddr![Udp(rand::random::<u16>())],
multiaddr![Udp(rand::random::<u16>())],
]); All these addresses require to produce a |
We just need to change these addresses to something else then! :) |
We just discovered a bug in go-libp2p where our existing logic that prevents self-dials doesn't work.
It turns out that on Linux, it is valid to dial 0.0.0.0: https://en.wikipedia.org/wiki/0.0.0.0#Operating_system_specific_uses. The kernel will then dial localhost.
We should detect that and disallow the dial.
The text was updated successfully, but these errors were encountered: