mirror of
https://github.com/dani-garcia/vaultwarden.wiki.git
synced 2026-07-26 09:45:05 +03:00
deduplicate send validation
This commit is contained in:
+8
-22
@@ -453,6 +453,9 @@ async fn post_access(headers: SendHeaders, conn: DbConn, nt: Notify<'_>) -> Json
|
|||||||
let Some(send) = Send::find_by_uuid(&headers.send_id, &conn).await else {
|
let Some(send) = Send::find_by_uuid(&headers.send_id, &conn).await else {
|
||||||
err_code!(SEND_INACCESSIBLE_MSG, 404)
|
err_code!(SEND_INACCESSIBLE_MSG, 404)
|
||||||
};
|
};
|
||||||
|
if !send.is_accessible() {
|
||||||
|
err_code!(SEND_INACCESSIBLE_MSG, 404)
|
||||||
|
}
|
||||||
process_access(send, conn, nt).await
|
process_access(send, conn, nt).await
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -483,17 +486,7 @@ async fn post_access_legacy(
|
|||||||
err_code!(SEND_INACCESSIBLE_MSG, 404);
|
err_code!(SEND_INACCESSIBLE_MSG, 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(expiration) = send.expiration_date
|
if !send.is_accessible() {
|
||||||
&& Utc::now().naive_utc() >= expiration
|
|
||||||
{
|
|
||||||
err_code!(SEND_INACCESSIBLE_MSG, 404)
|
|
||||||
}
|
|
||||||
|
|
||||||
if Utc::now().naive_utc() >= send.deletion_date {
|
|
||||||
err_code!(SEND_INACCESSIBLE_MSG, 404)
|
|
||||||
}
|
|
||||||
|
|
||||||
if send.disabled {
|
|
||||||
err_code!(SEND_INACCESSIBLE_MSG, 404)
|
err_code!(SEND_INACCESSIBLE_MSG, 404)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -541,6 +534,9 @@ async fn post_access_file(
|
|||||||
let Some(send) = Send::find_by_uuid(&headers.send_id, &conn).await else {
|
let Some(send) = Send::find_by_uuid(&headers.send_id, &conn).await else {
|
||||||
err_code!(SEND_INACCESSIBLE_MSG, 404)
|
err_code!(SEND_INACCESSIBLE_MSG, 404)
|
||||||
};
|
};
|
||||||
|
if !send.is_accessible() {
|
||||||
|
err_code!(SEND_INACCESSIBLE_MSG, 404)
|
||||||
|
}
|
||||||
process_access_file(send, file_id, host, conn, nt).await
|
process_access_file(send, file_id, host, conn, nt).await
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -567,17 +563,7 @@ async fn post_access_file_legacy(
|
|||||||
err_code!(SEND_INACCESSIBLE_MSG, 404)
|
err_code!(SEND_INACCESSIBLE_MSG, 404)
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(expiration) = send.expiration_date
|
if !send.is_accessible() {
|
||||||
&& Utc::now().naive_utc() >= expiration
|
|
||||||
{
|
|
||||||
err_code!(SEND_INACCESSIBLE_MSG, 404)
|
|
||||||
}
|
|
||||||
|
|
||||||
if Utc::now().naive_utc() >= send.deletion_date {
|
|
||||||
err_code!(SEND_INACCESSIBLE_MSG, 404)
|
|
||||||
}
|
|
||||||
|
|
||||||
if send.disabled {
|
|
||||||
err_code!(SEND_INACCESSIBLE_MSG, 404)
|
err_code!(SEND_INACCESSIBLE_MSG, 404)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-12
@@ -85,18 +85,8 @@ impl SendTokens {
|
|||||||
return Self::invalid_error(&format!("Send {send_id}, max access reached"), "send_id_invalid", true);
|
return Self::invalid_error(&format!("Send {send_id}, max access reached"), "send_id_invalid", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(expiration) = send.expiration_date
|
if !send.is_accessible() {
|
||||||
&& Utc::now().naive_utc() >= expiration
|
return Self::invalid_error(&format!("Send {send_id}, not accessible"), "send_id_invalid", true);
|
||||||
{
|
|
||||||
return Self::invalid_error(&format!("Send {send_id}, expired"), "send_id_invalid", true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if Utc::now().naive_utc() >= send.deletion_date {
|
|
||||||
return Self::invalid_error(&format!("Send {send_id}, past deletion"), "send_id_invalid", true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if send.disabled {
|
|
||||||
return Self::invalid_error(&format!("Send {send_id}, disabled"), "send_id_invalid", true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if send.password_hash.is_some() {
|
if send.password_hash.is_some() {
|
||||||
|
|||||||
@@ -262,6 +262,22 @@ impl Send {
|
|||||||
Ok(true)
|
Ok(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Whether the Send is currently within its validity window: not disabled, not past its
|
||||||
|
/// expiration date, and not past its deletion date. Does not consider `max_access_count`
|
||||||
|
/// (consumed at token issuance) or the password.
|
||||||
|
pub fn is_accessible(&self) -> bool {
|
||||||
|
let now = Utc::now().naive_utc();
|
||||||
|
if self.disabled {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if let Some(expiration) = self.expiration_date
|
||||||
|
&& now >= expiration
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
now < self.deletion_date
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn delete(&self, conn: &DbConn) -> EmptyResult {
|
pub async fn delete(&self, conn: &DbConn) -> EmptyResult {
|
||||||
self.update_users_revision(conn).await;
|
self.update_users_revision(conn).await;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user