]> Untitled Git - lemmy.git/commitdiff
validate post URLs on the backend (#990)
authoreiknat <68170752+eiknat@users.noreply.github.com>
Fri, 17 Jul 2020 22:46:59 +0000 (18:46 -0400)
committerGitHub <noreply@github.com>
Fri, 17 Jul 2020 22:46:59 +0000 (18:46 -0400)
* added serverside url validation

* api.post: use if let instead of is_some

also add "invalid_url" to en.json

Co-authored-by: John Doe <dhas8m@protonmail.com>
server/src/api/post.rs
ui/translations/en.json

index b9518f0e956f0bad5ba345bf5cb3e0c9c31ddd4d..61f3513b68976b2428ef302f3fcb2ffc5e504e18 100644 (file)
@@ -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<CreatePost> {
       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;
index 6e111c63914ad9d98c2720d61d0159c13aac4e39..e9d768f2f5de4ca4521447fc091eaa49ea5d4b47 100644 (file)
     "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."
 }