1
0
Fork 1
Spiegel von https://github.com/dani-garcia/vaultwarden.git synchronisiert 2024-11-16 04:12:53 +01:00

fix bug when extracing host from domain

Dieser Commit ist enthalten in:
BlockListed 2023-09-09 19:21:32 +02:00
Ursprung 335984ee28
Commit d1cb726996
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 2D204777C477B588
2 geänderte Dateien mit 20 neuen und 9 gelöschten Zeilen

Datei anzeigen

@ -365,7 +365,7 @@ use crate::db::{
DbConn, DbConn,
}; };
#[derive(Clone)] #[derive(Clone, Debug)]
pub struct HostInfo { pub struct HostInfo {
pub base_url: String, pub base_url: String,
pub origin: String, pub origin: String,
@ -393,7 +393,8 @@ impl<'r> FromRequest<'r> for HostInfo {
// Get host // Get host
// TODO: UPDATE THIS SECTION // TODO: UPDATE THIS SECTION
if CONFIG.domain_set() { let host_info = if CONFIG.domain_set() {
log::debug!("Using configured host info");
let host: Cow<'_, str> = if let Some(host) = headers.get_one("X-Forwarded-Host") { let host: Cow<'_, str> = if let Some(host) = headers.get_one("X-Forwarded-Host") {
host.into() host.into()
} else if let Some(host) = headers.get_one("Host") { } else if let Some(host) = headers.get_one("Host") {
@ -403,15 +404,20 @@ impl<'r> FromRequest<'r> for HostInfo {
}; };
let host_info = get_host_info(host.as_ref()) let host_info = get_host_info(host.as_ref())
.unwrap_or_else(|| get_host_info(&get_main_host()).expect("Main domain doesn't have entry!")); .unwrap_or_else(|| {
log::debug!("Falling back to default domain, because {host} was not in domains.");
get_host_info(&get_main_host()).expect("Main domain doesn't have entry!")
});
return Outcome::Success(host_info); host_info
} else if let Some(referer) = headers.get_one("Referer") { } else if let Some(referer) = headers.get_one("Referer") {
return Outcome::Success(HostInfo { log::debug!("Using referer host info");
HostInfo {
base_url: referer.to_string(), base_url: referer.to_string(),
origin: extract_url_origin(referer), origin: extract_url_origin(referer),
}); }
} else { } else {
log::debug!("Guessing host info with headers");
// Try to guess from the headers // Try to guess from the headers
use std::env; use std::env;
@ -433,11 +439,15 @@ impl<'r> FromRequest<'r> for HostInfo {
let base_url_origin = format!("{protocol}://{host}"); let base_url_origin = format!("{protocol}://{host}");
return Outcome::Success(HostInfo { HostInfo {
base_url: base_url_origin.clone(), base_url: base_url_origin.clone(),
origin: base_url_origin, origin: base_url_origin,
});
} }
};
log::debug!("Using host_info: {:?}", host_info);
Outcome::Success(host_info)
} }
} }

Datei anzeigen

@ -1058,6 +1058,7 @@ pub fn extract_url_host(url: &str) -> String {
}; };
if let Some(port) = u.port().map(|p| p.to_string()) { if let Some(port) = u.port().map(|p| p.to_string()) {
host.push(':');
host.push_str(&port); host.push_str(&port);
} }