Repository navigation
clnrest: accept IPv6 in clnrest-host, with or without brackets - #9799
daywalker90 merged 1 commit into
Conversation
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
| } | ||
| }; | ||
| let address = parse_address(&plugin.option(&OPT_CLNREST_HOST)?, port)?; | ||
| let address_str = address.to_string(); |
There was a problem hiding this comment.
This would turn localhost to the resolved address (usually 127.0.0.1) so it would break with the certificate. Suggested fix: keep format!("{}:{}", host, port) when host == "localhost", and use address.to_string() for IP literals
There was a problem hiding this comment.
Thanks, fixed. localhost is kept as localhost:<port> now, and IP addresses still use address.to_string().
|
|
||
| /// The IP address in the `clnrest-host` option, if it is one. | ||
| /// An IPv6 address may be given with or without brackets. | ||
| pub fn host_ip(rest_host: &str) -> Option<IpAddr> { |
There was a problem hiding this comment.
this would accept bracketed ipv4 addresses. Suggested fix:
pub fn host_ip(rest_host: &str) -> Option<IpAddr> {
if let Some(bare) = rest_host.strip_prefix('[').and_then(|h| h.strip_suffix(']')) {
bare.parse::<Ipv6Addr>().ok().map(IpAddr::V6)
} else {
rest_host.parse::<IpAddr>().ok()
}
}There was a problem hiding this comment.
Done, I used your version. [127.0.0.1] is refused now, and I added a test for it.
|
Also please squash the commits |
clnrest-host=::1 was refused as "should be a valid IP", because the host and port were joined as "::1:3010" and parsed as one socket address. clnrest-host=[::1] started the server, but the certificate code parsed "[::1]" as an IpAddr, which fails, so the server certificate got no IP SAN for it. Parse the host as an IP once, accepting a bracketed IPv6 address, and build the socket address with SocketAddr::new. Use the same helper to add the IP SAN when generating certificates. Brackets are only accepted around IPv6, and `localhost` is still shown as `localhost:<port>`. Changelog-Fixed: clnrest: `clnrest-host` now accepts IPv6 addresses (with or without brackets), and the generated certificate includes the address.
f6bc213 to
70e28e5
Compare
|
squashed |
|
Thanks! |
clnrest-host=::1 failed with "should be a valid IP", because options.rs joined host and port as "::1:3010" and parsed that as a socket address. With clnrest-host=[::1] the server started, but certs.rs parsed "[::1]" as an IpAddr, which fails, so the certificate had no IP SAN for it.
Now the host is parsed as an IP once, brackets are stripped, and the socket address is built with SocketAddr::new. The certificate code uses the same helper. I added unit tests for both functions. Two of them fail with the old parsing code and pass with the fix.
I ran
cargo test -p clnrest,cargo clippy -p clnrest --all-targetsand rustfmt on the two changed files. I did not run the pytest clnrest tests.Fixes #9786