Skip to content

Commit

Permalink
Add blacklist of domains used by scammers
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmerlin committed Apr 1, 2024
1 parent 14a98a8 commit df32d82
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions urllb/src/blacklist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
free.nf
cl.gy
webwave.dev
urlz.fr
yww.uy
prurl.co
17 changes: 17 additions & 0 deletions urllb/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use axum::{
use axum_client_ip::{SecureClientIp, SecureClientIpSource};
use diesel_async::pooled_connection::AsyncDieselConnectionManager;
use include_dir::{include_dir, Dir};
use lazy_static::lazy_static;
use rand::seq::SliceRandom;
use serde::{Deserialize, Serialize};
use tokio::io;
Expand Down Expand Up @@ -146,13 +147,29 @@ struct Params {
link: String,
}

lazy_static! {
static ref BLACKLIST: Vec<String> = include_str!("blacklist.txt")
.lines()
.map(|s| s.to_string())
.collect();
}

async fn post_link(
State(pool): State<Pool>,
SecureClientIp(ip): SecureClientIp,
Json(body): Json<CreateLinkDto>,
) -> Result<impl IntoResponse, StatusCode> {
body.validate().map_err(|_| StatusCode::BAD_REQUEST)?;

if BLACKLIST.iter().any(|b| {
body.targets
.iter()
.map(|t| &t.target_url)
.any(|t| t.contains(b))
}) {
return Err(StatusCode::FORBIDDEN);
}

let mut connection = pool
.get()
.await
Expand Down

0 comments on commit df32d82

Please sign in to comment.