avoid leaking the token in events

This commit is contained in:
Zomatree
2023-03-11 23:24:10 +00:00
parent fca91e1560
commit 01577fd798

View File

@@ -10,7 +10,11 @@ impl Webhook {
pub async fn create(&self, db: &Database) -> Result<()> { pub async fn create(&self, db: &Database) -> Result<()> {
db.insert_webhook(self).await?; db.insert_webhook(self).await?;
EventV1::WebhookCreate(self.clone()) // Avoid leaking the token to people who receive the event
let mut webhook = self.clone();
webhook.token = None;
EventV1::WebhookCreate(webhook)
.p(self.channel.clone()).await; .p(self.channel.clone()).await;
Ok(()) Ok(())
@@ -28,7 +32,7 @@ impl Webhook {
pub async fn update( pub async fn update(
&mut self, &mut self,
db: &Database, db: &Database,
partial: PartialWebhook, mut partial: PartialWebhook,
remove: Vec<FieldsWebhook> remove: Vec<FieldsWebhook>
) -> Result<()> { ) -> Result<()> {
for field in &remove { for field in &remove {
@@ -39,6 +43,8 @@ impl Webhook {
db.update_webook(&self.id, &partial, &remove).await?; db.update_webook(&self.id, &partial, &remove).await?;
partial.token = None; // Avoid leaking the token to people who receive the event
EventV1::WebhookUpdate { EventV1::WebhookUpdate {
id: self.id.clone(), id: self.id.clone(),
data: partial, data: partial,