Throw error when attempting to http fetch local object

This commit is contained in:
Felix Ableitner 2024-11-12 12:06:18 +01:00
parent 6dfd30a8ab
commit 3a5c621e17
2 changed files with 12 additions and 1 deletions

View file

@ -78,6 +78,9 @@ pub enum Error {
/// Attempted to fetch object but the response's id field doesn't match /// Attempted to fetch object but the response's id field doesn't match
#[error("Attempted to fetch object from {0} but the response's id field doesn't match")] #[error("Attempted to fetch object from {0} but the response's id field doesn't match")]
FetchWrongId(Url), FetchWrongId(Url),
/// Object which has local domain cannot be fetched over HTTP
#[error("Object which has local domain cannot be fetched over HTTP")]
CannotDereferenceLocalObject,
/// Other generic errors /// Other generic errors
#[error("{0}")] #[error("{0}")]
Other(String), Other(String),

View file

@ -92,7 +92,7 @@ where
// object found in database // object found in database
if let Some(object) = db_object { if let Some(object) = db_object {
if let Some(last_refreshed_at) = object.last_refreshed_at() { if let Some(last_refreshed_at) = object.last_refreshed_at() {
let is_local = data.config.is_local_url(&self.0); let is_local = self.is_local(data);
if !is_local && should_refetch_object(last_refreshed_at) { if !is_local && should_refetch_object(last_refreshed_at) {
// object is outdated and should be refetched // object is outdated and should be refetched
return self.dereference_from_http(data, Some(object)).await; return self.dereference_from_http(data, Some(object)).await;
@ -158,6 +158,10 @@ where
where where
<Kind as Object>::Error: From<Error>, <Kind as Object>::Error: From<Error>,
{ {
if self.is_local(data) {
return Err(Error::CannotDereferenceLocalObject.into());
}
let res = Box::pin(fetch_object_http(&self.0, data)).await; let res = Box::pin(fetch_object_http(&self.0, data)).await;
if let Err(Error::ObjectDeleted(url)) = res { if let Err(Error::ObjectDeleted(url)) = res {
@ -170,6 +174,10 @@ where
let res = res?; let res = res?;
let redirect_url = &res.url; let redirect_url = &res.url;
if data.config.is_local_url(&redirect_url) {
return Err(Error::CannotDereferenceLocalObject.into());
}
Box::pin(Kind::verify(&res.object, redirect_url, data)).await?; Box::pin(Kind::verify(&res.object, redirect_url, data)).await?;
Box::pin(Kind::from_json(res.object, data)).await Box::pin(Kind::from_json(res.object, data)).await
} }