fix once lock for domain regex
This commit is contained in:
parent
2fb79a2524
commit
c16f89d23a
2 changed files with 8 additions and 6 deletions
|
|
@ -26,7 +26,6 @@ use bytes::Bytes;
|
|||
use derive_builder::Builder;
|
||||
use dyn_clone::{clone_trait_object, DynClone};
|
||||
use moka::future::Cache;
|
||||
use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
use reqwest::{redirect::Policy, Client, Request};
|
||||
use reqwest_middleware::{ClientWithMiddleware, RequestBuilder};
|
||||
|
|
@ -38,6 +37,7 @@ use std::{
|
|||
sync::{
|
||||
atomic::{AtomicU32, Ordering},
|
||||
Arc,
|
||||
OnceLock,
|
||||
},
|
||||
time::Duration,
|
||||
};
|
||||
|
|
@ -114,8 +114,10 @@ pub struct FederationConfig<T: Clone> {
|
|||
pub(crate) queue_retry_count: usize,
|
||||
}
|
||||
|
||||
pub(crate) static DOMAIN_REGEX: Lazy<Regex> =
|
||||
Lazy::new(|| Regex::new(r"^[a-zA-Z0-9.-]*$").expect("compile regex"));
|
||||
pub(crate) fn domain_regex() -> &'static Regex {
|
||||
static DOMAIN_REGEX: OnceLock<Regex> = OnceLock::new();
|
||||
DOMAIN_REGEX.get_or_init(|| Regex::new(r"^[a-zA-Z0-9.-]*$").expect("compile regex"))
|
||||
}
|
||||
|
||||
impl<T: Clone> FederationConfig<T> {
|
||||
/// Returns a new config builder with default values.
|
||||
|
|
@ -174,7 +176,7 @@ impl<T: Clone> FederationConfig<T> {
|
|||
let Some(domain) = url.domain() else {
|
||||
return Err(Error::UrlVerificationError("Url must have a domain"));
|
||||
};
|
||||
if !DOMAIN_REGEX.is_match(domain) {
|
||||
if !domain_regex().is_match(domain) {
|
||||
return Err(Error::UrlVerificationError("Invalid characters in domain"));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::{
|
||||
config::{Data, DOMAIN_REGEX},
|
||||
config::{domain_regex, Data},
|
||||
error::Error,
|
||||
fetch::{fetch_object_http_with_accept, object_id::ObjectId},
|
||||
traits::{Actor, Object},
|
||||
|
|
@ -55,7 +55,7 @@ where
|
|||
.ok_or(WebFingerError::WrongFormat.into_crate_error())?;
|
||||
|
||||
// For production mode make sure that domain doesnt contain any port or path.
|
||||
if !data.config.debug && !DOMAIN_REGEX.is_match(domain) {
|
||||
if !data.config.debug && !domain_regex().is_match(domain) {
|
||||
return Err(Error::UrlVerificationError("Invalid characters in domain").into());
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue