mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2025-09-12 09:02:58 +02:00
Compare commits
No commits in common. "d4049a79bfa1542c656ccac3f66e74ed63879b10" and "ca263af321dd0552c01a4a3e3b79765598b96351" have entirely different histories.
d4049a79bf
...
ca263af321
3 changed files with 16 additions and 41 deletions
|
@ -26,11 +26,20 @@ pub async fn policyserv_check(&self, pdu: &PduEvent, room_id: &RoomId) -> Result
|
||||||
return Ok(());
|
return Ok(());
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
// TODO: dont do *this*
|
||||||
|
let pdu_json = self.services.timeline.get_pdu_json(pdu.event_id()).await?;
|
||||||
let outgoing = self
|
let outgoing = self
|
||||||
.services
|
.services
|
||||||
.sending
|
.sending
|
||||||
.convert_to_outgoing_federation_event(pdu.to_canonical_object())
|
.convert_to_outgoing_federation_event(pdu_json)
|
||||||
.await;
|
.await;
|
||||||
|
// let s = match serde_json::to_string(outgoing.as_ref()) {
|
||||||
|
// | Ok(s) => s,
|
||||||
|
// | Err(e) => {
|
||||||
|
// warn!("Failed to convert pdu {} to outgoing federation event: {e}",
|
||||||
|
// pdu.event_id()); return Err!(Request(InvalidParam("Failed to convert PDU
|
||||||
|
// to outgoing event."))); },
|
||||||
|
// };
|
||||||
debug!("Checking pdu {outgoing:?} for spam with policy server {via} for room {room_id}");
|
debug!("Checking pdu {outgoing:?} for spam with policy server {via} for room {room_id}");
|
||||||
let response = self
|
let response = self
|
||||||
.services
|
.services
|
||||||
|
@ -43,21 +52,14 @@ pub async fn policyserv_check(&self, pdu: &PduEvent, room_id: &RoomId) -> Result
|
||||||
let response = match response {
|
let response = match response {
|
||||||
| Ok(response) => response,
|
| Ok(response) => response,
|
||||||
| Err(e) => {
|
| Err(e) => {
|
||||||
warn!(
|
warn!("Failed to contact policy server {via} for room {room_id}: {e}");
|
||||||
via = %via,
|
|
||||||
event_id = %pdu.event_id(),
|
|
||||||
room_id = %room_id,
|
|
||||||
"Failed to contact policy server: {e}"
|
|
||||||
);
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
if response.recommendation == "spam" {
|
if response.recommendation == "spam" {
|
||||||
warn!(
|
warn!(
|
||||||
via = %via,
|
"Event {} in room {room_id} was marked as spam by policy server {via}",
|
||||||
event_id = %pdu.event_id(),
|
pdu.event_id().to_owned()
|
||||||
room_id = %room_id,
|
|
||||||
"Event was marked as spam by policy server",
|
|
||||||
);
|
);
|
||||||
return Err!(Request(Forbidden("Event was marked as spam by policy server")));
|
return Err!(Request(Forbidden("Event was marked as spam by policy server")));
|
||||||
}
|
}
|
||||||
|
|
|
@ -222,7 +222,9 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
// 14-pre. If the event is not a state event, ask the policy server about it
|
// 14-pre. If the event is not a state event, ask the policy server about it
|
||||||
if incoming_pdu.state_key.is_none() {
|
if incoming_pdu.state_key.is_none()
|
||||||
|
&& incoming_pdu.sender().server_name() != self.services.globals.server_name()
|
||||||
|
{
|
||||||
debug!("Checking policy server for event {}", incoming_pdu.event_id);
|
debug!("Checking policy server for event {}", incoming_pdu.event_id);
|
||||||
let policy = self.policyserv_check(&incoming_pdu, room_id);
|
let policy = self.policyserv_check(&incoming_pdu, room_id);
|
||||||
if let Err(e) = policy.await {
|
if let Err(e) = policy.await {
|
||||||
|
@ -234,24 +236,6 @@ where
|
||||||
debug!("Policy server check passed for event {}", incoming_pdu.event_id);
|
debug!("Policy server check passed for event {}", incoming_pdu.event_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Additionally, if this is a redaction for a soft-failed event, we soft-fail it
|
|
||||||
// also
|
|
||||||
if let Some(redact_id) = incoming_pdu.redacts_id(&room_version_id) {
|
|
||||||
debug!("Checking if redaction {} is for a soft-failed event", redact_id);
|
|
||||||
if self
|
|
||||||
.services
|
|
||||||
.pdu_metadata
|
|
||||||
.is_event_soft_failed(&redact_id)
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
warn!(
|
|
||||||
"Redaction {} is for a soft-failed event, soft failing the redaction",
|
|
||||||
redact_id
|
|
||||||
);
|
|
||||||
soft_fail = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 14. Check if the event passes auth based on the "current state" of the room,
|
// 14. Check if the event passes auth based on the "current state" of the room,
|
||||||
// if not soft fail it
|
// if not soft fail it
|
||||||
if soft_fail {
|
if soft_fail {
|
||||||
|
|
|
@ -165,17 +165,6 @@ pub async fn create_hash_and_sign_event(
|
||||||
return Err!(Request(Forbidden("Event is not authorized.")));
|
return Err!(Request(Forbidden("Event is not authorized.")));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check with the policy server
|
|
||||||
if self
|
|
||||||
.services
|
|
||||||
.event_handler
|
|
||||||
.policyserv_check(&pdu, room_id)
|
|
||||||
.await
|
|
||||||
.is_err()
|
|
||||||
{
|
|
||||||
return Err!(Request(Forbidden(debug_warn!("Policy server marked this event as spam"))));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Hash and sign
|
// Hash and sign
|
||||||
let mut pdu_json = utils::to_canonical_object(&pdu).map_err(|e| {
|
let mut pdu_json = utils::to_canonical_object(&pdu).map_err(|e| {
|
||||||
err!(Request(BadJson(warn!("Failed to convert PDU to canonical JSON: {e}"))))
|
err!(Request(BadJson(warn!("Failed to convert PDU to canonical JSON: {e}"))))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue