add per domain config
Some checks failed
ci/woodpecker/push/build Pipeline failed

This commit is contained in:
JMARyA 2025-01-03 13:34:59 +01:00
parent dc10052c16
commit 536f42a4e8
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
4 changed files with 164 additions and 18 deletions

View file

@ -7,13 +7,37 @@ pub fn check_blacklist(domain: &str) -> bool {
let conf = get_config();
let conf = conf.websites.as_ref();
// TODO : Block IPs
// Test SSRF
let blacklisted_domains = conf
.map(|x| x.BLACKLIST_DOMAINS.as_ref())
.unwrap_or_default();
for domain_regex in blacklisted_domains.unwrap_or(&Vec::new()) {
let rgx = regex::Regex::new(domain_regex).unwrap();
if rgx.is_match(domain) {
check_regex(domain, blacklisted_domains.unwrap_or(&Vec::new()))
}
pub fn check_blacklist_path(domain: &str, path: &str) -> bool {
let conf = get_config();
let conf = conf.websites.as_ref();
if let Some(website) = conf {
let empty = Vec::new();
let domain_conf = website.domains.as_ref().unwrap_or(&empty);
if let Some(domain_conf) = domain_conf.iter().find(|x| x.domain == domain) {
let empty = Vec::new();
let blacklist = domain_conf.blacklist_paths.as_ref().unwrap_or(&empty);
return check_regex(path, blacklist);
}
}
false
}
pub fn check_regex(input: &str, regexes: &Vec<String>) -> bool {
for regex in regexes {
let rgx = regex::Regex::new(regex).unwrap();
if rgx.is_match(input) {
return true;
}
}