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:
Ursprung
335984ee28
Commit
d1cb726996
2 geänderte Dateien mit 20 neuen und 9 gelöschten Zeilen
26
src/auth.rs
26
src/auth.rs
|
@ -365,7 +365,7 @@ use crate::db::{
|
|||
DbConn,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct HostInfo {
|
||||
pub base_url: String,
|
||||
pub origin: String,
|
||||
|
@ -393,7 +393,8 @@ impl<'r> FromRequest<'r> for HostInfo {
|
|||
|
||||
// Get host
|
||||
// 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") {
|
||||
host.into()
|
||||
} 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())
|
||||
.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") {
|
||||
return Outcome::Success(HostInfo {
|
||||
log::debug!("Using referer host info");
|
||||
HostInfo {
|
||||
base_url: referer.to_string(),
|
||||
origin: extract_url_origin(referer),
|
||||
});
|
||||
}
|
||||
} else {
|
||||
log::debug!("Guessing host info with headers");
|
||||
// Try to guess from the headers
|
||||
use std::env;
|
||||
|
||||
|
@ -433,11 +439,15 @@ impl<'r> FromRequest<'r> for HostInfo {
|
|||
|
||||
let base_url_origin = format!("{protocol}://{host}");
|
||||
|
||||
return Outcome::Success(HostInfo {
|
||||
HostInfo {
|
||||
base_url: base_url_origin.clone(),
|
||||
origin: base_url_origin,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
log::debug!("Using host_info: {:?}", host_info);
|
||||
|
||||
Outcome::Success(host_info)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1058,6 +1058,7 @@ pub fn extract_url_host(url: &str) -> String {
|
|||
};
|
||||
|
||||
if let Some(port) = u.port().map(|p| p.to_string()) {
|
||||
host.push(':');
|
||||
host.push_str(&port);
|
||||
}
|
||||
|
||||
|
|
Laden …
In neuem Issue referenzieren