webarc/src/blacklist.rs
JMARyA 654d4b9cba
Some checks failed
ci/woodpecker/push/build Pipeline failed
refactor
2024-12-30 09:57:42 +01:00

22 lines
745 B
Rust

/// Checks if a domain is present in the blacklist of unwanted domains.
///
/// This function checks the `$BLACKLIST_DOMAINS` environment variable for a comma-separated list of regular expressions to match against.
/// If a match is found, it immediately returns `true`. Otherwise, it returns `false`.
pub fn check_blacklist(domain: &str) -> bool {
let blacklist_raw = std::env::var("BLACKLIST_DOMAINS").unwrap_or_default();
if blacklist_raw.is_empty() {
return false;
}
let blacklist: Vec<&str> = blacklist_raw.split(',').collect();
for domain_regex in blacklist {
let rgx = regex::Regex::new(domain_regex).unwrap();
if rgx.is_match(domain) {
return true;
}
}
false
}