feat: allow HTTP operation on private LAN addresses
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
//! Zweck: Gemeinsame Token- und API-Typen für Server und Client.
|
||||
//! Wichtige Information: Geheimnisse werden nur erzeugt und gehasht, nie protokolliert.
|
||||
//! Version: 1
|
||||
//! Version: 2
|
||||
|
||||
use base64::{Engine, engine::general_purpose::URL_SAFE_NO_PAD};
|
||||
use serde::{Deserialize, Serialize};
|
||||
@ -102,6 +102,19 @@ pub struct Problem {
|
||||
pub korrelation_id: String,
|
||||
}
|
||||
|
||||
/// Erlaubt HTTP zu lokalen und privaten IP-Adressen im freigegebenen LAN-Betrieb.
|
||||
#[must_use]
|
||||
pub fn lan_host(host: &str) -> bool {
|
||||
if host == "localhost" {
|
||||
return true;
|
||||
}
|
||||
match host.trim_matches(['[', ']']).parse::<std::net::IpAddr>() {
|
||||
Ok(std::net::IpAddr::V4(ip)) => ip.is_loopback() || ip.is_private(),
|
||||
Ok(std::net::IpAddr::V6(ip)) => ip.is_loopback() || ip.is_unique_local(),
|
||||
Err(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod selbsttest {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user