]> Untitled Git - lemmy.git/commitdiff
Adding honeypot to user and post creation. Fixes #1802 (#1803)
authorDessalines <dessalines@users.noreply.github.com>
Fri, 1 Oct 2021 11:37:39 +0000 (07:37 -0400)
committerGitHub <noreply@github.com>
Fri, 1 Oct 2021 11:37:39 +0000 (11:37 +0000)
crates/api_common/src/lib.rs
crates/api_common/src/person.rs
crates/api_common/src/post.rs
crates/api_crud/src/post/create.rs
crates/api_crud/src/site/read.rs
crates/api_crud/src/user/create.rs

index 19715c3a5162680e0692ec9275138de56036b1d6..068de48a173705352d260892bb3a37011b648a43 100644 (file)
@@ -439,3 +439,12 @@ pub fn site_description_length_check(description: &str) -> Result<(), LemmyError
     Ok(())
   }
 }
+
+/// Checks for a honeypot. If this field is filled, fail the rest of the function
+pub fn honeypot_check(honeypot: &Option<String>) -> Result<(), LemmyError> {
+  if honeypot.is_some() {
+    Err(ApiError::err("honeypot_fail").into())
+  } else {
+    Ok(())
+  }
+}
index c71cf540ba4698ecc4e68f96ad205a8c152bbf52..2dd9953b778b56cf0a41eeb143377646de9d7c53 100644 (file)
@@ -26,6 +26,7 @@ pub struct Register {
   pub email: Option<String>,
   pub captcha_uuid: Option<String>,
   pub captcha_answer: Option<String>,
+  pub honeypot: Option<String>,
 }
 
 #[derive(Deserialize)]
index 3926ed8c7adf9e5ff56172893aab677140534206..a4e823bd8f9b3cad233daecc308427037f86e164 100644 (file)
@@ -18,6 +18,7 @@ pub struct CreatePost {
   pub community_id: CommunityId,
   pub url: Option<Url>,
   pub body: Option<String>,
+  pub honeypot: Option<String>,
   pub nsfw: Option<bool>,
   pub auth: String,
 }
index 3a5883ff37ce4fed15610edc071e75c7dac6cb23..2b6b4b572aa4e5889e8ff32ca0a5c2f4106f6071 100644 (file)
@@ -4,6 +4,7 @@ use lemmy_api_common::{
   blocking,
   check_community_ban,
   get_local_user_view_from_jwt,
+  honeypot_check,
   mark_post_as_read,
   post::*,
 };
@@ -46,6 +47,7 @@ impl PerformCrud for CreatePost {
     let slur_regex = &context.settings().slur_regex();
     check_slurs(&data.name, slur_regex)?;
     check_slurs_opt(&data.body, slur_regex)?;
+    honeypot_check(&data.honeypot)?;
 
     if !is_valid_post_title(&data.name) {
       return Err(ApiError::err("invalid_post_title").into());
index 1bed1e3bca5bdc9bad9a0530b7fbe573c6cac34c..2668939ef7f0ad2a83f526835e207266210e1801 100644 (file)
@@ -43,6 +43,7 @@ impl PerformCrud for GetSite {
             show_nsfw: true,
             captcha_uuid: None,
             captcha_answer: None,
+            honeypot: None,
           };
           let login_response = register.perform(context, websocket_id).await?;
           info!("Admin {} created", setup.admin_username);
index 2b093e013f596bfb7b1d579abbb76d0d872b48d3..2e855fff63e99aabc1e71b319fa97922e3c4320c 100644 (file)
@@ -1,6 +1,6 @@
 use crate::PerformCrud;
 use actix_web::web::Data;
-use lemmy_api_common::{blocking, password_length_check, person::*};
+use lemmy_api_common::{blocking, honeypot_check, password_length_check, person::*};
 use lemmy_apub::{
   generate_apub_endpoint,
   generate_followers_url,
@@ -55,6 +55,7 @@ impl PerformCrud for Register {
     }
 
     password_length_check(&data.password)?;
+    honeypot_check(&data.honeypot)?;
 
     // Make sure passwords match
     if data.password != data.password_verify {