Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Oct 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions crates/api_common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
}
1 change: 1 addition & 0 deletions crates/api_common/src/person.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
1 change: 1 addition & 0 deletions crates/api_common/src/post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
2 changes: 2 additions & 0 deletions crates/api_crud/src/post/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*,
};
Expand Down Expand Up @@ -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());
Expand Down
1 change: 1 addition & 0 deletions crates/api_crud/src/site/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion crates/api_crud/src/user/create.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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 {
Expand Down