diff --git a/server/src/api/post.rs b/server/src/api/post.rs index b9518f0e9..61f3513b6 100644 --- a/server/src/api/post.rs +++ b/server/src/api/post.rs @@ -37,6 +37,7 @@ use lemmy_utils::{ }; use serde::{Deserialize, Serialize}; use std::str::FromStr; +use url::Url; #[derive(Serialize, Deserialize, Debug)] pub struct CreatePost { @@ -162,6 +163,13 @@ impl Perform for Oper { return Err(APIError::err("site_ban").into()); } + if let Some(url) = data.url.as_ref() { + match Url::parse(url) { + Ok(_t) => (), + Err(_e) => return Err(APIError::err("invalid_url").into()), + } + } + // Fetch Iframely and pictrs cached image let (iframely_title, iframely_description, iframely_html, pictrs_thumbnail) = fetch_iframely_and_pictrs_data(&self.client, data.url.to_owned()).await; diff --git a/ui/translations/en.json b/ui/translations/en.json index 6e111c639..e9d768f2f 100644 --- a/ui/translations/en.json +++ b/ui/translations/en.json @@ -277,5 +277,6 @@ "what_is": "What is", "cake_day_title": "Cake day:", "cake_day_info": "It's {{ creator_name }}'s cake day today!", - "invalid_post_title": "Invalid post title" + "invalid_post_title": "Invalid post title", + "invalid_url": "Invalid URL." }