Compare commits
2 Commits
b58c96b843
...
9e795eefdc
| Author | SHA1 | Date | |
|---|---|---|---|
| 9e795eefdc | |||
| 18cf2c9f54 |
@@ -4,6 +4,7 @@ use activitypub_federation::{
|
|||||||
kinds::activity::{
|
kinds::activity::{
|
||||||
AcceptType, CreateType, DeleteType, FollowType, RejectType, UndoType, UpdateType,
|
AcceptType, CreateType, DeleteType, FollowType, RejectType, UndoType, UpdateType,
|
||||||
},
|
},
|
||||||
|
protocol::verification::verify_domains_match,
|
||||||
traits::Activity,
|
traits::Activity,
|
||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
@@ -239,6 +240,14 @@ impl Activity for UndoActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn verify(&self, _data: &Data<Self::DataType>) -> Result<(), Self::Error> {
|
async fn verify(&self, _data: &Data<Self::DataType>) -> Result<(), Self::Error> {
|
||||||
|
// The actor undoing must be the same as the actor in the wrapped activity.
|
||||||
|
if let Some(inner_actor) = self.object.get("actor").and_then(|v| v.as_str()) {
|
||||||
|
if inner_actor != self.actor.inner().as_str() {
|
||||||
|
return Err(Error::bad_request(anyhow::anyhow!(
|
||||||
|
"Undo actor does not match inner activity actor"
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -570,6 +579,7 @@ impl Activity for AnnounceActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn verify(&self, _data: &Data<Self::DataType>) -> Result<(), Self::Error> {
|
async fn verify(&self, _data: &Data<Self::DataType>) -> Result<(), Self::Error> {
|
||||||
|
verify_domains_match(&self.id, self.actor.inner())?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -633,6 +643,7 @@ impl Activity for LikeActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn verify(&self, _data: &Data<Self::DataType>) -> Result<(), Self::Error> {
|
async fn verify(&self, _data: &Data<Self::DataType>) -> Result<(), Self::Error> {
|
||||||
|
verify_domains_match(&self.id, self.actor.inner())?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -692,6 +703,14 @@ impl Activity for AddActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn verify(&self, _data: &Data<Self::DataType>) -> Result<(), Self::Error> {
|
async fn verify(&self, _data: &Data<Self::DataType>) -> Result<(), Self::Error> {
|
||||||
|
if let Some(attributed_to) = self.object.get("attributedTo").and_then(|v| v.as_str())
|
||||||
|
&& let Ok(attributed_url) = Url::parse(attributed_to)
|
||||||
|
&& &attributed_url != self.actor.inner()
|
||||||
|
{
|
||||||
|
return Err(Error::bad_request(anyhow::anyhow!(
|
||||||
|
"Add actor does not match object attributedTo"
|
||||||
|
)));
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -742,6 +761,7 @@ impl Activity for BlockActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn verify(&self, _data: &Data<Self::DataType>) -> Result<(), Self::Error> {
|
async fn verify(&self, _data: &Data<Self::DataType>) -> Result<(), Self::Error> {
|
||||||
|
verify_domains_match(&self.id, self.actor.inner())?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ pub struct ThoughtNote {
|
|||||||
#[serde(rename = "type")]
|
#[serde(rename = "type")]
|
||||||
pub kind: NoteType,
|
pub kind: NoteType,
|
||||||
pub id: Url,
|
pub id: Url,
|
||||||
pub url: Url, // Mastodon uses this as the clickable link
|
#[serde(skip_serializing_if = "Option::is_none", default)]
|
||||||
|
pub url: Option<Url>,
|
||||||
pub attributed_to: Url,
|
pub attributed_to: Url,
|
||||||
pub content: String,
|
pub content: String,
|
||||||
pub published: DateTime<Utc>,
|
pub published: DateTime<Utc>,
|
||||||
@@ -42,7 +43,7 @@ impl ThoughtNote {
|
|||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
kind: Default::default(),
|
kind: Default::default(),
|
||||||
url: id.clone(),
|
url: Some(id.clone()),
|
||||||
id,
|
id,
|
||||||
attributed_to: actor_url,
|
attributed_to: actor_url,
|
||||||
content,
|
content,
|
||||||
|
|||||||
Reference in New Issue
Block a user