diff --git a/crates/buzz-relay/src/invite_preview.rs b/crates/buzz-relay/src/invite_preview.rs index e7c804051f..bcd29f3f15 100644 --- a/crates/buzz-relay/src/invite_preview.rs +++ b/crates/buzz-relay/src/invite_preview.rs @@ -4,9 +4,12 @@ use axum::{ http::StatusCode, response::{Html, IntoResponse, Response}, }; -use std::path::Path; +use std::{path::Path, time::Duration}; use url::Url; +/// The lookup only serves link-preview metadata; never hold the page for it. +const HOST_LOOKUP_DEADLINE: Duration = Duration::from_millis(250); + pub(crate) async fn response( index: &Path, relay_url: &str, @@ -15,7 +18,13 @@ pub(crate) async fn response( ) -> Response { match tokio::fs::read_to_string(index).await { Ok(html) => { - let tenant = crate::tenant::bind_community(resolver, raw_host).await.ok(); + let tenant = tokio::time::timeout( + HOST_LOOKUP_DEADLINE, + crate::tenant::bind_community(resolver, raw_host), + ) + .await + .ok() + .and_then(Result::ok); Html(with_metadata(html, relay_url, tenant.as_ref())).into_response() } Err(_) => StatusCode::INTERNAL_SERVER_ERROR.into_response(), @@ -90,6 +99,7 @@ mod tests { ))) } "error.example" => Err(()), + "slow.example" => std::future::pending().await, _ => Ok(None), } } @@ -111,6 +121,7 @@ mod tests { "beta.example:8443", "unknown.example", "error.example", + "slow.example", "", ] { let response = response(&index, relay, &Resolver, host).await; diff --git a/previews/invite-video/README.md b/previews/invite-video/README.md index 41a30ede07..01b6fbd7ea 100644 --- a/previews/invite-video/README.md +++ b/previews/invite-video/README.md @@ -43,7 +43,7 @@ do not validate or redeem the invite. Deploy both the updated relay and its web bundle (the relay Docker image includes both). The media host comes from the request's resolved community, matching the invite link's host. `RELAY_URL` supplies only the `wss`/`ws` TLS posture, mapped to -`https`/`http`. Unmapped hosts or lookup failures receive no preview metadata. +`https`/`http`. Unmapped hosts, lookup failures and slow lookups receive no preview metadata. Each community host must serve the web bundle without authentication. Use HTTPS in production.