From dde8692a5dad4f31d8fb84ad8eb6027c72290b35 Mon Sep 17 00:00:00 2001 From: aprilthepink Date: Sat, 3 Aug 2024 08:15:54 +0200 Subject: [PATCH] fix: accept any domain cuz bridge --- Cargo.lock | 2 ++ Cargo.toml | 2 ++ src/http.rs | 12 ++++++++++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 236b8c8..0720bbf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1949,7 +1949,9 @@ dependencies = [ "env_logger", "lazy_static", "num_cpus", + "once_cell", "rand", + "regex", "reqwest 0.12.5", "sea-orm", "serde", diff --git a/Cargo.toml b/Cargo.toml index b77f1a2..e8c24b4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,6 +35,8 @@ dotenv = "0.15.0" async-recursion = "1.1.1" base64-url = "3.0.0" webfinger = "0.5.1" +regex = "1.10.6" +once_cell = "1.19.0" [dependencies.sea-orm] version = "0.12.0" diff --git a/src/http.rs b/src/http.rs index e4715fc..c398315 100644 --- a/src/http.rs +++ b/src/http.rs @@ -13,13 +13,15 @@ use crate::{ use activitypub_federation::{ actix_web::{inbox::receive_activity, signing_actor}, config::{Data, FederationConfig, FederationMiddleware}, - fetch::webfinger::{build_webfinger_response, extract_webfinger_name}, + fetch::webfinger::{build_webfinger_response, extract_webfinger_name, WebFingerError}, protocol::context::WithContext, traits::{Actor, Object}, FEDERATION_CONTENT_TYPE, }; use actix_web::{web, web::Bytes, App, HttpRequest, HttpResponse, HttpServer}; use anyhow::anyhow; +use once_cell::sync::Lazy; +use regex::Regex; use serde::Deserialize; use tracing::info; use url::Url; @@ -106,7 +108,13 @@ pub async fn webfinger( query: web::Query, data: Data, ) -> Result { - let name = extract_webfinger_name(&query.resource, &data)?; + static WEBFINGER_REGEX: Lazy = + Lazy::new(|| Regex::new(r"^acct:([\p{L}0-9_\.\-]+)@(.*)$").expect("compile regex")); + let captures = WEBFINGER_REGEX + .captures(&query.resource) + .ok_or(WebFingerError::WrongFormat)?; + let account_name = captures.get(1).ok_or(WebFingerError::WrongFormat)?; + let name = account_name.as_str(); let user = local_db_user_from_name(name.to_string()).await?; Ok(HttpResponse::Ok().json(build_webfinger_response( query.resource.clone(),