mirror of
https://github.com/dani-garcia/vaultwarden.git
synced 2025-08-21 10:15:24 +00:00
Addressed remarks given and some updates
- Addressed comments given during review - Updated crates, including Rocket to the latest merged v0.5 changes - Removed an extra header which should not be sent for websocket connections
This commit is contained in:
parent
f44fec3bd1
commit
917fb507d6
4 changed files with 29 additions and 26 deletions
|
@ -84,8 +84,8 @@
|
||||||
### WebSocket ###
|
### WebSocket ###
|
||||||
#################
|
#################
|
||||||
|
|
||||||
## Disable websocket notifications
|
## Enable websocket notifications
|
||||||
# WEBSOCKET_DISABLED=false
|
# ENABLE_WEBSOCKET=true
|
||||||
|
|
||||||
##########################
|
##########################
|
||||||
### Push notifications ###
|
### Push notifications ###
|
||||||
|
|
|
@ -316,7 +316,7 @@ async fn test_smtp(data: Json<InviteData>, _token: AdminToken) -> EmptyResult {
|
||||||
|
|
||||||
#[get("/logout")]
|
#[get("/logout")]
|
||||||
fn logout(cookies: &CookieJar<'_>) -> Redirect {
|
fn logout(cookies: &CookieJar<'_>) -> Redirect {
|
||||||
cookies.remove(Cookie::build(COOKIE_NAME).path(admin_path()));
|
cookies.remove(Cookie::build(COOKIE_NAME, "").path(admin_path()).finish());
|
||||||
Redirect::to(admin_path())
|
Redirect::to(admin_path())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -797,7 +797,7 @@ impl<'r> FromRequest<'r> for AdminToken {
|
||||||
|
|
||||||
if decode_admin(access_token).is_err() {
|
if decode_admin(access_token).is_err() {
|
||||||
// Remove admin cookie
|
// Remove admin cookie
|
||||||
cookies.remove(Cookie::build(COOKIE_NAME).path(admin_path()));
|
cookies.remove(Cookie::build(COOKIE_NAME, "").path(admin_path()).finish());
|
||||||
error!("Invalid or expired admin JWT. IP: {}.", &ip.ip);
|
error!("Invalid or expired admin JWT. IP: {}.", &ip.ip);
|
||||||
return Outcome::Error((Status::Unauthorized, "Session expired"));
|
return Outcome::Error((Status::Unauthorized, "Session expired"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,12 +35,14 @@ use super::{
|
||||||
push_send_update, push_user_update,
|
push_send_update, push_user_update,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static NOTIFICATIONS_DISABLED: Lazy<bool> = Lazy::new(|| !CONFIG.enable_websocket() && !CONFIG.push_enabled());
|
||||||
|
|
||||||
pub fn routes() -> Vec<Route> {
|
pub fn routes() -> Vec<Route> {
|
||||||
if CONFIG.websocket_disabled() {
|
if CONFIG.enable_websocket() {
|
||||||
|
routes![websockets_hub, anonymous_websockets_hub]
|
||||||
|
} else {
|
||||||
info!("WebSocket are disabled, realtime sync functionality will not work!");
|
info!("WebSocket are disabled, realtime sync functionality will not work!");
|
||||||
routes![]
|
routes![]
|
||||||
} else {
|
|
||||||
routes![websockets_hub, anonymous_websockets_hub]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -339,7 +341,7 @@ impl WebSocketUsers {
|
||||||
// NOTE: The last modified date needs to be updated before calling these methods
|
// NOTE: The last modified date needs to be updated before calling these methods
|
||||||
pub async fn send_user_update(&self, ut: UpdateType, user: &User) {
|
pub async fn send_user_update(&self, ut: UpdateType, user: &User) {
|
||||||
// Skip any processing if both WebSockets and Push are not active
|
// Skip any processing if both WebSockets and Push are not active
|
||||||
if CONFIG.websocket_disabled() && !CONFIG.push_enabled() {
|
if *NOTIFICATIONS_DISABLED {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let data = create_update(
|
let data = create_update(
|
||||||
|
@ -348,7 +350,7 @@ impl WebSocketUsers {
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
|
||||||
if !CONFIG.websocket_disabled() {
|
if CONFIG.enable_websocket() {
|
||||||
self.send_update(&user.uuid, &data).await;
|
self.send_update(&user.uuid, &data).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -359,7 +361,7 @@ impl WebSocketUsers {
|
||||||
|
|
||||||
pub async fn send_logout(&self, user: &User, acting_device_uuid: Option<String>) {
|
pub async fn send_logout(&self, user: &User, acting_device_uuid: Option<String>) {
|
||||||
// Skip any processing if both WebSockets and Push are not active
|
// Skip any processing if both WebSockets and Push are not active
|
||||||
if CONFIG.websocket_disabled() && !CONFIG.push_enabled() {
|
if *NOTIFICATIONS_DISABLED {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let data = create_update(
|
let data = create_update(
|
||||||
|
@ -368,7 +370,7 @@ impl WebSocketUsers {
|
||||||
acting_device_uuid.clone(),
|
acting_device_uuid.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
if !CONFIG.websocket_disabled() {
|
if CONFIG.enable_websocket() {
|
||||||
self.send_update(&user.uuid, &data).await;
|
self.send_update(&user.uuid, &data).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -385,7 +387,7 @@ impl WebSocketUsers {
|
||||||
conn: &mut DbConn,
|
conn: &mut DbConn,
|
||||||
) {
|
) {
|
||||||
// Skip any processing if both WebSockets and Push are not active
|
// Skip any processing if both WebSockets and Push are not active
|
||||||
if CONFIG.websocket_disabled() && !CONFIG.push_enabled() {
|
if *NOTIFICATIONS_DISABLED {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let data = create_update(
|
let data = create_update(
|
||||||
|
@ -398,7 +400,7 @@ impl WebSocketUsers {
|
||||||
Some(acting_device_uuid.into()),
|
Some(acting_device_uuid.into()),
|
||||||
);
|
);
|
||||||
|
|
||||||
if !CONFIG.websocket_disabled() {
|
if CONFIG.enable_websocket() {
|
||||||
self.send_update(&folder.user_uuid, &data).await;
|
self.send_update(&folder.user_uuid, &data).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -417,7 +419,7 @@ impl WebSocketUsers {
|
||||||
conn: &mut DbConn,
|
conn: &mut DbConn,
|
||||||
) {
|
) {
|
||||||
// Skip any processing if both WebSockets and Push are not active
|
// Skip any processing if both WebSockets and Push are not active
|
||||||
if CONFIG.websocket_disabled() && !CONFIG.push_enabled() {
|
if *NOTIFICATIONS_DISABLED {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let org_uuid = convert_option(cipher.organization_uuid.clone());
|
let org_uuid = convert_option(cipher.organization_uuid.clone());
|
||||||
|
@ -445,7 +447,7 @@ impl WebSocketUsers {
|
||||||
Some(acting_device_uuid.into()),
|
Some(acting_device_uuid.into()),
|
||||||
);
|
);
|
||||||
|
|
||||||
if !CONFIG.websocket_disabled() {
|
if CONFIG.enable_websocket() {
|
||||||
for uuid in user_uuids {
|
for uuid in user_uuids {
|
||||||
self.send_update(uuid, &data).await;
|
self.send_update(uuid, &data).await;
|
||||||
}
|
}
|
||||||
|
@ -465,7 +467,7 @@ impl WebSocketUsers {
|
||||||
conn: &mut DbConn,
|
conn: &mut DbConn,
|
||||||
) {
|
) {
|
||||||
// Skip any processing if both WebSockets and Push are not active
|
// Skip any processing if both WebSockets and Push are not active
|
||||||
if CONFIG.websocket_disabled() && !CONFIG.push_enabled() {
|
if *NOTIFICATIONS_DISABLED {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let user_uuid = convert_option(send.user_uuid.clone());
|
let user_uuid = convert_option(send.user_uuid.clone());
|
||||||
|
@ -480,7 +482,7 @@ impl WebSocketUsers {
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
|
|
||||||
if !CONFIG.websocket_disabled() {
|
if CONFIG.enable_websocket() {
|
||||||
for uuid in user_uuids {
|
for uuid in user_uuids {
|
||||||
self.send_update(uuid, &data).await;
|
self.send_update(uuid, &data).await;
|
||||||
}
|
}
|
||||||
|
@ -498,7 +500,7 @@ impl WebSocketUsers {
|
||||||
conn: &mut DbConn,
|
conn: &mut DbConn,
|
||||||
) {
|
) {
|
||||||
// Skip any processing if both WebSockets and Push are not active
|
// Skip any processing if both WebSockets and Push are not active
|
||||||
if CONFIG.websocket_disabled() && !CONFIG.push_enabled() {
|
if *NOTIFICATIONS_DISABLED {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let data = create_update(
|
let data = create_update(
|
||||||
|
@ -506,7 +508,7 @@ impl WebSocketUsers {
|
||||||
UpdateType::AuthRequest,
|
UpdateType::AuthRequest,
|
||||||
Some(acting_device_uuid.to_string()),
|
Some(acting_device_uuid.to_string()),
|
||||||
);
|
);
|
||||||
if !CONFIG.websocket_disabled() {
|
if CONFIG.enable_websocket() {
|
||||||
self.send_update(user_uuid, &data).await;
|
self.send_update(user_uuid, &data).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -523,7 +525,7 @@ impl WebSocketUsers {
|
||||||
conn: &mut DbConn,
|
conn: &mut DbConn,
|
||||||
) {
|
) {
|
||||||
// Skip any processing if both WebSockets and Push are not active
|
// Skip any processing if both WebSockets and Push are not active
|
||||||
if CONFIG.websocket_disabled() && !CONFIG.push_enabled() {
|
if *NOTIFICATIONS_DISABLED {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let data = create_update(
|
let data = create_update(
|
||||||
|
@ -531,7 +533,7 @@ impl WebSocketUsers {
|
||||||
UpdateType::AuthRequestResponse,
|
UpdateType::AuthRequestResponse,
|
||||||
approving_device_uuid.clone().into(),
|
approving_device_uuid.clone().into(),
|
||||||
);
|
);
|
||||||
if !CONFIG.websocket_disabled() {
|
if CONFIG.enable_websocket() {
|
||||||
self.send_update(auth_response_uuid, &data).await;
|
self.send_update(auth_response_uuid, &data).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -557,14 +559,15 @@ impl AnonymousWebSocketSubscriptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn send_auth_response(&self, user_uuid: &String, auth_response_uuid: &str) {
|
pub async fn send_auth_response(&self, user_uuid: &String, auth_response_uuid: &str) {
|
||||||
|
if !CONFIG.enable_websocket() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
let data = create_anonymous_update(
|
let data = create_anonymous_update(
|
||||||
vec![("Id".into(), auth_response_uuid.to_owned().into()), ("UserId".into(), user_uuid.clone().into())],
|
vec![("Id".into(), auth_response_uuid.to_owned().into()), ("UserId".into(), user_uuid.clone().into())],
|
||||||
UpdateType::AuthRequestResponse,
|
UpdateType::AuthRequestResponse,
|
||||||
user_uuid.to_string(),
|
user_uuid.to_string(),
|
||||||
);
|
);
|
||||||
if !CONFIG.websocket_disabled() {
|
self.send_update(auth_response_uuid, &data).await;
|
||||||
self.send_update(auth_response_uuid, &data).await;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -369,8 +369,8 @@ make_config! {
|
||||||
web_vault_folder: String, false, def, "web-vault/".to_string();
|
web_vault_folder: String, false, def, "web-vault/".to_string();
|
||||||
},
|
},
|
||||||
ws {
|
ws {
|
||||||
/// Disable websocket notifications
|
/// Enable websocket notifications
|
||||||
websocket_disabled: bool, false, def, false;
|
enable_websocket: bool, false, def, true;
|
||||||
},
|
},
|
||||||
push {
|
push {
|
||||||
/// Enable push notifications
|
/// Enable push notifications
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue