Adding honeypot to user and post creation. Fixes #1802 (#1803)

This commit is contained in:
Dessalines 2021-10-01 07:37:39 -04:00 committed by GitHub
parent a03727e28a
commit fe7c1b300b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 16 additions and 1 deletions

View file

@ -439,3 +439,12 @@ pub fn site_description_length_check(description: &str) -> Result<(), LemmyError
Ok(()) 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(())
}
}

View file

@ -26,6 +26,7 @@ pub struct Register {
pub email: Option<String>, pub email: Option<String>,
pub captcha_uuid: Option<String>, pub captcha_uuid: Option<String>,
pub captcha_answer: Option<String>, pub captcha_answer: Option<String>,
pub honeypot: Option<String>,
} }
#[derive(Deserialize)] #[derive(Deserialize)]

View file

@ -18,6 +18,7 @@ pub struct CreatePost {
pub community_id: CommunityId, pub community_id: CommunityId,
pub url: Option<Url>, pub url: Option<Url>,
pub body: Option<String>, pub body: Option<String>,
pub honeypot: Option<String>,
pub nsfw: Option<bool>, pub nsfw: Option<bool>,
pub auth: String, pub auth: String,
} }

View file

@ -4,6 +4,7 @@ use lemmy_api_common::{
blocking, blocking,
check_community_ban, check_community_ban,
get_local_user_view_from_jwt, get_local_user_view_from_jwt,
honeypot_check,
mark_post_as_read, mark_post_as_read,
post::*, post::*,
}; };
@ -46,6 +47,7 @@ impl PerformCrud for CreatePost {
let slur_regex = &context.settings().slur_regex(); let slur_regex = &context.settings().slur_regex();
check_slurs(&data.name, slur_regex)?; check_slurs(&data.name, slur_regex)?;
check_slurs_opt(&data.body, slur_regex)?; check_slurs_opt(&data.body, slur_regex)?;
honeypot_check(&data.honeypot)?;
if !is_valid_post_title(&data.name) { if !is_valid_post_title(&data.name) {
return Err(ApiError::err("invalid_post_title").into()); return Err(ApiError::err("invalid_post_title").into());

View file

@ -43,6 +43,7 @@ impl PerformCrud for GetSite {
show_nsfw: true, show_nsfw: true,
captcha_uuid: None, captcha_uuid: None,
captcha_answer: None, captcha_answer: None,
honeypot: None,
}; };
let login_response = register.perform(context, websocket_id).await?; let login_response = register.perform(context, websocket_id).await?;
info!("Admin {} created", setup.admin_username); info!("Admin {} created", setup.admin_username);

View file

@ -1,6 +1,6 @@
use crate::PerformCrud; use crate::PerformCrud;
use actix_web::web::Data; 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::{ use lemmy_apub::{
generate_apub_endpoint, generate_apub_endpoint,
generate_followers_url, generate_followers_url,
@ -55,6 +55,7 @@ impl PerformCrud for Register {
} }
password_length_check(&data.password)?; password_length_check(&data.password)?;
honeypot_check(&data.honeypot)?;
// Make sure passwords match // Make sure passwords match
if data.password != data.password_verify { if data.password != data.password_verify {