Browse Source

Don't send activities to ourselves

fix-1325
Felix Ableitner 1 month ago
parent
commit
ecd3061d82
3 changed files with 26 additions and 8 deletions
  1. +8
    -1
      lemmy_apub/src/activity_queue.rs
  2. +1
    -7
      lemmy_apub/src/lib.rs
  3. +17
    -0
      lemmy_utils/src/settings.rs

+ 8
- 1
lemmy_apub/src/activity_queue.rs View File

@ -219,6 +219,13 @@ where
return Ok(());
}
// Don't send anything to ourselves
let hostname = Settings::get().get_hostname_without_port()?;
let inboxes: Vec<&Url> = inboxes
.iter()
.filter(|i| i.domain().unwrap() != hostname)
.collect();
let activity = activity.into_any_base()?;
let serialised_activity = serde_json::to_string(&activity)?;
@ -232,7 +239,7 @@ where
for i in inboxes {
let message = SendActivityTask {
activity: serialised_activity.to_owned(),
inbox: i,
inbox: i.to_owned(),
actor_id: actor.actor_id()?,
private_key: actor.private_key().context(location_info!())?,
};


+ 1
- 7
lemmy_apub/src/lib.rs View File

@ -61,13 +61,7 @@ pub static APUB_JSON_CONTENT_TYPE: &str = "application/activity+json";
fn check_is_apub_id_valid(apub_id: &Url) -> Result<(), LemmyError> {
let settings = Settings::get();
let domain = apub_id.domain().context(location_info!())?.to_string();
let local_instance = settings
.hostname
.split(':')
.collect::<Vec<&str>>()
.first()
.context(location_info!())?
.to_string();
let local_instance = settings.get_hostname_without_port()?;
if !settings.federation.enabled {
return if domain == local_instance {


+ 17
- 0
lemmy_utils/src/settings.rs View File

@ -1,3 +1,5 @@
use crate::location_info;
use anyhow::Context;
use config::{Config, ConfigError, Environment, File};
use serde::Deserialize;
use std::{env, fs, io::Error, net::IpAddr, path::PathBuf, sync::RwLock};
@ -178,6 +180,21 @@ impl Settings {
format!("{}://{}", self.get_protocol_string(), self.hostname)
}
/// When running the federation test setup in `api_tests/` or `docker/federation`, the `hostname`
/// variable will be like `lemmy-alpha:8541`. This method removes the port and returns
/// `lemmy-alpha` instead. It has no effect in production.
pub fn get_hostname_without_port(&self) -> Result<String, anyhow::Error> {
Ok(
self
.hostname
.split(':')
.collect::<Vec<&str>>()
.first()
.context(location_info!())?
.to_string(),
)
}
pub fn save_config_file(data: &str) -> Result<String, Error> {
fs::write(CONFIG_FILE, data)?;


Loading…
Cancel
Save