This commit is contained in:
Felix Ableitner 2023-07-10 16:24:39 +02:00 committed by Nutomic
parent ee97430b2b
commit aa9aed2621
2 changed files with 13 additions and 11 deletions

View file

@ -114,9 +114,9 @@ impl<T: Clone> FederationConfig<T> {
verify_domains_match(activity.id(), activity.actor())?; verify_domains_match(activity.id(), activity.actor())?;
self.verify_url_valid(activity.id()).await?; self.verify_url_valid(activity.id()).await?;
if self.is_local_url(activity.id()) { if self.is_local_url(activity.id()) {
return Err(Error::UrlVerificationError( return Err(Error::UrlVerificationError(anyhow!(
anyhow!("Activity was sent from local instance"), "Activity was sent from local instance"
)); )));
} }
Ok(()) Ok(())
@ -139,9 +139,9 @@ impl<T: Clone> FederationConfig<T> {
"https" => {} "https" => {}
"http" => { "http" => {
if !self.allow_http_urls { if !self.allow_http_urls {
return Err(Error::UrlVerificationError( return Err(Error::UrlVerificationError(anyhow!(
anyhow!("Http urls are only allowed in debug mode"), "Http urls are only allowed in debug mode"
)); )));
} }
} }
_ => return Err(Error::UrlVerificationError(anyhow!("Invalid url scheme"))), _ => return Err(Error::UrlVerificationError(anyhow!("Invalid url scheme"))),
@ -153,13 +153,15 @@ impl<T: Clone> FederationConfig<T> {
} }
if url.domain().is_none() { if url.domain().is_none() {
return Err(Error::UrlVerificationError(anyhow!("Url must have a domain"))); return Err(Error::UrlVerificationError(anyhow!(
"Url must have a domain"
)));
} }
if url.domain() == Some("localhost") && !self.debug { if url.domain() == Some("localhost") && !self.debug {
return Err(Error::UrlVerificationError( return Err(Error::UrlVerificationError(anyhow!(
anyhow!("Localhost is only allowed in debug mode"), "Localhost is only allowed in debug mode"
)); )));
} }
self.url_verifier self.url_verifier

View file

@ -1,7 +1,7 @@
//! Verify that received data is valid //! Verify that received data is valid
use crate::error::Error;
use anyhow::anyhow; use anyhow::anyhow;
use crate::error::{Error};
use url::Url; use url::Url;
/// Check that both urls have the same domain. If not, return UrlVerificationError. /// Check that both urls have the same domain. If not, return UrlVerificationError.