Skip to content

Commit 03bcdc6

Browse files
authored
OAuth: Allow non-loopback addresses (#1514)
1 parent 9456a02 commit 03bcdc6

2 files changed

Lines changed: 17 additions & 16 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2323
- [playback] Changed type alias `MixerFn` to return `Result<Arc<dyn Mixer>, Error>` instead of `Arc<dyn Mixer>` (breaking)
2424
- [playback] Optimize audio conversion to always dither at 16-bit level, and improve performance
2525
- [playback] Normalizer maintains better stereo imaging, while also being faster
26+
- [oauth] Remove loopback address requirement from `redirect_uri` when spawning callback handling server versus using stdin.
2627

2728
### Added
2829

oauth/src/lib.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -187,24 +187,17 @@ fn get_authcode_listener(
187187
code
188188
}
189189

190-
// If the specified `redirect_uri` is HTTP, loopback, and contains a port,
190+
// If the specified `redirect_uri` is HTTP and contains a port,
191191
// then the corresponding socket address is returned.
192192
fn get_socket_address(redirect_uri: &str) -> Option<SocketAddr> {
193-
#![warn(missing_docs)]
194193
let url = match Url::parse(redirect_uri) {
195194
Ok(u) if u.scheme() == "http" && u.port().is_some() => u,
196195
_ => return None,
197196
};
198-
let socket_addr = match url.socket_addrs(|| None) {
197+
match url.socket_addrs(|| None) {
199198
Ok(mut addrs) => addrs.pop(),
200199
_ => None,
201-
};
202-
if let Some(s) = socket_addr {
203-
if s.ip().is_loopback() {
204-
return socket_addr;
205-
}
206200
}
207-
None
208201
}
209202

210203
/// Struct that handle obtaining and refreshing access tokens.
@@ -509,21 +502,21 @@ mod test {
509502
assert_eq!(get_socket_address("http://127.0.0.1/foo"), None);
510503
assert_eq!(get_socket_address("http://127.0.0.1:/foo"), None);
511504
assert_eq!(get_socket_address("http://[::1]/foo"), None);
512-
// Not localhost
513-
assert_eq!(get_socket_address("http://56.0.0.1:1234/foo"), None);
514-
assert_eq!(
515-
get_socket_address("http://[3ffe:2a00:100:7031::1]:1234/foo"),
516-
None
517-
);
518505
// Not http
519506
assert_eq!(get_socket_address("https://127.0.0.1/foo"), None);
520507
}
521508

522509
#[test]
523-
fn get_socket_address_localhost() {
510+
fn get_socket_address_some() {
524511
let localhost_v4 = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 1234);
525512
let localhost_v6 = SocketAddr::new(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)), 8888);
513+
let addr_v4 = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(8, 8, 8, 8)), 1234);
514+
let addr_v6 = SocketAddr::new(
515+
IpAddr::V6(Ipv6Addr::new(0x2001, 0x4860, 0x4860, 0, 0, 0, 0, 0x8888)),
516+
8888,
517+
);
526518

519+
// Loopback addresses
527520
assert_eq!(
528521
get_socket_address("http://127.0.0.1:1234/foo"),
529522
Some(localhost_v4)
@@ -536,5 +529,12 @@ mod test {
536529
get_socket_address("http://[::1]:8888/foo"),
537530
Some(localhost_v6)
538531
);
532+
533+
// Non-loopback addresses
534+
assert_eq!(get_socket_address("http://8.8.8.8:1234/foo"), Some(addr_v4));
535+
assert_eq!(
536+
get_socket_address("http://[2001:4860:4860::8888]:8888/foo"),
537+
Some(addr_v6)
538+
);
539539
}
540540
}

0 commit comments

Comments
 (0)