Content-Length: 373845 | pFad | https://github.com/sebadob/rauthy/commit/824b109e081f608a9b950483b3da90cde288f6eb

4B Merge pull request #488 from sebadob/user-reg-domain-blacklisting · sebadob/rauthy@824b109 · GitHub
Skip to content

Commit

Permalink
Merge pull request #488 from sebadob/user-reg-domain-blacklisting
Browse files Browse the repository at this point in the history
featu: open user registration domain blacklisting
  • Loading branch information
sebadob authored Jun 20, 2024
2 parents 8320891 + 77494a9 commit 824b109
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 2 deletions.
17 changes: 17 additions & 0 deletions book/src/config/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ extract these values, create Kubernetes Secrets and provide them as environment
# registrations with 'user@gmail.com' (default: '')
#USER_REG_DOMAIN_RESTRICTION=some-domain.com
# If `OPEN_USER_REG=true`, you can blacklist certain domains
# on the open registration endpoint.
# Provide the domains as a `\n` separated list.
#USER_REG_DOMAIN_BLACKLIST="
#example.com
#evil.net
#"
# If set to true, a violation inside the CSRF protection middleware based
# on Sec-* headers will block invalid requests. Usually you always want this
# enabled. You may only set it to false during the first testing phase if you
Expand Down Expand Up @@ -951,6 +959,15 @@ PUB_URL=localhost:8080
# default: false
PROXY_MODE=false
# A `\n` separated list of trusted proxy CIDRs.
# When `PROXY_MODE=true` or `PEER_IP_HEADER_NAME` is set,
# these are mandatory to be able to extract the real client
# IP properly and safely to prevent IP header spoofing.
# All requests with a different source will be blocked.
#TRUSTED_PROXIES="
#192.168.14.0/24
#"
# To enable or disable the additional HTTP server to expose the /metrics endpoint
# default: true
#METRICS_ENABLE=true
Expand Down
8 changes: 8 additions & 0 deletions rauthy.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ USERINFO_STRICT=true
# default: ''
#USER_REG_DOMAIN_RESTRICTION=@some-mail-domain.com

# If `OPEN_USER_REG=true`, you can blacklist certain domains
# on the open registration endpoint.
# Provide the domains as a `\n` separated list.
USER_REG_DOMAIN_BLACKLIST="
example.com
evil.net
"

# If set to true, a violation inside the CSRF protection middleware based
# on Sec-* headers will block invalid requests. Usually you always want this
# enabled. You may only set it to false during the first testing phase if you
Expand Down
12 changes: 11 additions & 1 deletion src/api/src/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ use rauthy_api_types::users::{
};
use rauthy_common::constants::{
COOKIE_MFA, ENABLE_WEB_ID, HEADER_ALLOW_ALL_ORIGINS, HEADER_HTML, HEADER_JSON, OPEN_USER_REG,
PWD_RESET_COOKIE, SSP_THRESHOLD, TEXT_TURTLE, USER_REG_DOMAIN_RESTRICTION,
PWD_RESET_COOKIE, SSP_THRESHOLD, TEXT_TURTLE, USER_REG_DOMAIN_BLACKLIST,
USER_REG_DOMAIN_RESTRICTION,
};
use rauthy_common::utils::real_ip_from_req;
use rauthy_error::{ErrorResponse, ErrorResponseType};
Expand Down Expand Up @@ -327,6 +328,15 @@ pub async fn post_users_register(
),
));
}
} else if let Some(blacklist) = &*USER_REG_DOMAIN_BLACKLIST {
for blacklisted in blacklist {
if req_data.email.ends_with(blacklisted) {
return Err(ErrorResponse::new(
ErrorResponseType::BadRequest,
"Domain is blacklisted",
));
}
}
}

// validate the PoW
Expand Down
10 changes: 10 additions & 0 deletions src/common/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use actix_web::http::Uri;
use lazy_static::lazy_static;
use regex::Regex;
use std::env;
use std::ops::Not;
use std::str::FromStr;
use std::string::ToString;

Expand Down Expand Up @@ -348,6 +349,15 @@ lazy_static! {
Ok(domain) => Some(domain)
}
};
pub static ref USER_REG_DOMAIN_BLACKLIST: Option<Vec<String>> = env::var("USER_REG_DOMAIN_BLACKLIST")
.ok()
.map(|blacklist| blacklist.lines()
.filter_map(|line| {
let trimmed = line.trim();
trimmed.is_empty().not().then_some(trimmed.to_string())
})
.collect()
);

pub static ref PEER_IP_HEADER_NAME: Option<String> = env::var("PEER_IP_HEADER_NAME").ok();

Expand Down
2 changes: 1 addition & 1 deletion src/middlewares/src/logging.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use actix_web::http::header::HeaderValue;
use actix_web::http::{Method, Uri};
use actix_web::http::Method;
use actix_web::{
dev::{forward_ready, Service, ServiceRequest, ServiceResponse, Transform},
Error,
Expand Down

0 comments on commit 824b109

Please sign in to comment.








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/sebadob/rauthy/commit/824b109e081f608a9b950483b3da90cde288f6eb

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy