summaryrefslogtreecommitdiffstats
path: root/server/src/apub/mod.rs
diff options
context:
space:
mode:
authorFelix <me@nutomic.com>2020-04-17 19:34:18 +0200
committerFelix <me@nutomic.com>2020-04-17 19:34:18 +0200
commitb1b97db11a130a063768169ba7ce90798ef4d659 (patch)
treeba4efccca8792841a163c9aacf1e118130b33b5b /server/src/apub/mod.rs
parentc5ced6fa5e0a5f80c9e58c3a4bf199434194195a (diff)
Implement instance whitelist
Diffstat (limited to 'server/src/apub/mod.rs')
-rw-r--r--server/src/apub/mod.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/server/src/apub/mod.rs b/server/src/apub/mod.rs
index a7f0668a..634f3510 100644
--- a/server/src/apub/mod.rs
+++ b/server/src/apub/mod.rs
@@ -88,3 +88,26 @@ pub fn gen_keypair_str() -> (String, String) {
fn vec_bytes_to_str(bytes: Vec<u8>) -> String {
String::from_utf8_lossy(&bytes).into_owned()
}
+
+// Checks if the ID has a valid format, correct scheme, and is in the whitelist.
+fn is_apub_id_valid(apub_id: &str) -> bool {
+ let url = match Url::parse(apub_id) {
+ Ok(u) => u,
+ Err(_) => return false,
+ };
+
+ if url.scheme() != get_apub_protocol_string() {
+ return false;
+ }
+
+ let whitelist: Vec<String> = Settings::get()
+ .federation
+ .instance_whitelist
+ .split(',')
+ .map(|d| d.to_string())
+ .collect();
+ match url.domain() {
+ Some(d) => whitelist.contains(&d.to_owned()),
+ None => false,
+ }
+}