Skip to content

Commit

Permalink
feat(apub/object): verify public (#20)
Browse files Browse the repository at this point in the history
closed #20
  • Loading branch information
kwaa committed Mar 20, 2024
1 parent cfd5875 commit 31aa292
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions crates/apub/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ activitypub_federation = { workspace = true }
anyhow = { workspace = true }
async-recursion = { workspace = true }
async-trait = { workspace = true }
axum = { workspace = true }
chrono = { workspace = true }
enum_delegate = { workspace = true }
feed-rs = { workspace = true }
Expand Down
17 changes: 16 additions & 1 deletion crates/apub/src/objects/db_post.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ use std::ops::Deref;

use activitypub_federation::{
config::Data,
kinds::public,
protocol::verification::verify_domains_match,
traits::Object,
};
use axum::http::StatusCode;
use chrono::{DateTime, Utc};
use hatsu_db_schema::{post::Model as DbPost, prelude::Post};
use hatsu_utils::{AppData, AppError};
Expand Down Expand Up @@ -68,7 +70,20 @@ impl Object for ApubPost {
_data: &Data<Self::DataType>,
) -> Result<(), Self::Error> {
verify_domains_match(json.id.inner(), expected_domain)?;
Ok(())

// https://github.com/LemmyNet/lemmy/blob/2fd81067c7130a23cabfff8bfa76b349b87e8426/crates/apub/src/activities/mod.rs#L127-L133
if [json.to.as_slice(), json.cc.as_slice()]
.concat()
.contains(&public())
{
Ok(())
} else {
Err(AppError::new(
String::from("Post is not Public"),
None,
Some(StatusCode::BAD_REQUEST),
))
}
}

// 转换为本地格式
Expand Down

0 comments on commit 31aa292

Please sign in to comment.