From fe7c1b300b114bff5fca3b8b52d364ed926b9b77 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Fri, 1 Oct 2021 07:37:39 -0400 Subject: [PATCH] Adding honeypot to user and post creation. Fixes #1802 (#1803) --- crates/api_common/src/lib.rs | 9 +++++++++ crates/api_common/src/person.rs | 1 + crates/api_common/src/post.rs | 1 + crates/api_crud/src/post/create.rs | 2 ++ crates/api_crud/src/site/read.rs | 1 + crates/api_crud/src/user/create.rs | 3 ++- 6 files changed, 16 insertions(+), 1 deletion(-) diff --git a/crates/api_common/src/lib.rs b/crates/api_common/src/lib.rs index 19715c3a..068de48a 100644 --- a/crates/api_common/src/lib.rs +++ b/crates/api_common/src/lib.rs @@ -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) -> Result<(), LemmyError> { + if honeypot.is_some() { + Err(ApiError::err("honeypot_fail").into()) + } else { + Ok(()) + } +} diff --git a/crates/api_common/src/person.rs b/crates/api_common/src/person.rs index c71cf540..2dd9953b 100644 --- a/crates/api_common/src/person.rs +++ b/crates/api_common/src/person.rs @@ -26,6 +26,7 @@ pub struct Register { pub email: Option, pub captcha_uuid: Option, pub captcha_answer: Option, + pub honeypot: Option, } #[derive(Deserialize)] diff --git a/crates/api_common/src/post.rs b/crates/api_common/src/post.rs index 3926ed8c..a4e823bd 100644 --- a/crates/api_common/src/post.rs +++ b/crates/api_common/src/post.rs @@ -18,6 +18,7 @@ pub struct CreatePost { pub community_id: CommunityId, pub url: Option, pub body: Option, + pub honeypot: Option, pub nsfw: Option, pub auth: String, } diff --git a/crates/api_crud/src/post/create.rs b/crates/api_crud/src/post/create.rs index 3a5883ff..2b6b4b57 100644 --- a/crates/api_crud/src/post/create.rs +++ b/crates/api_crud/src/post/create.rs @@ -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()); diff --git a/crates/api_crud/src/site/read.rs b/crates/api_crud/src/site/read.rs index 1bed1e3b..2668939e 100644 --- a/crates/api_crud/src/site/read.rs +++ b/crates/api_crud/src/site/read.rs @@ -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); diff --git a/crates/api_crud/src/user/create.rs b/crates/api_crud/src/user/create.rs index 2b093e01..2e855fff 100644 --- a/crates/api_crud/src/user/create.rs +++ b/crates/api_crud/src/user/create.rs @@ -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 { -- 2.44.1