From 2619a936439129f07633393ef8fc22a72782b5a1 Mon Sep 17 00:00:00 2001 From: asonix Date: Wed, 10 Feb 2021 00:14:42 -0600 Subject: [PATCH] Fix rdnn block checks --- .env | 1 + src/db.rs | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.env b/.env index 49cf5c0..6535b40 100644 --- a/.env +++ b/.env @@ -1,2 +1,3 @@ HOSTNAME=localhost:8079 PORT=8079 +RESTRICTED_MODE=true diff --git a/src/db.rs b/src/db.rs index 569179f..2b94976 100644 --- a/src/db.rs +++ b/src/db.rs @@ -169,20 +169,24 @@ impl Inner { fn is_allowed(&self, domain: &str) -> bool { let prefix = domain_prefix(domain); + let reverse_domain = domain_key(domain); if self.restricted_mode { self.allowed_domains .scan_prefix(prefix) .keys() .filter_map(|res| res.ok()) - .any(|rdnn| domain.starts_with(String::from_utf8_lossy(&rdnn).as_ref())) + .any(|rdnn| { + let rdnn_string = String::from_utf8_lossy(&rdnn); + reverse_domain.starts_with(rdnn_string.as_ref()) + }) } else { !self .blocked_domains .scan_prefix(prefix) .keys() .filter_map(|res| res.ok()) - .any(|rdnn| domain.starts_with(String::from_utf8_lossy(&rdnn).as_ref())) + .any(|rdnn| reverse_domain.starts_with(String::from_utf8_lossy(&rdnn).as_ref())) } } }