feat: allow multiple IP patterns in JWT

This commit is contained in:
Conrad Ludgate
2025-01-14 16:53:36 +00:00
parent f64a240888
commit eab0be6fa8
+5 -4
View File
@@ -312,13 +312,14 @@ async fn auth_quirks(
// the token has a required IP claim.
if let Some(expected_ip) = token.get("ip") {
// todo: don't panic here, obviously.
let expected_ip: IpAddr = expected_ip
let allowed_ips: Vec<IpPattern> = expected_ip
.as_str()
.expect("jwt should not have an invalid IP claim")
.parse()
.expect("jwt should not have an invalid IP claim");
.split(',')
.map(|s| s.parse().expect("jwt should not have an invalid IP claim"))
.collect();
if ctx.peer_addr() != expected_ip {
if !check_peer_addr_is_in_list(&ctx.peer_addr(), &allowed_ips) {
return Err(auth::AuthError::ip_address_not_allowed(ctx.peer_addr()));
}
}