YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
fix: POST /notify validates pipe actions exist before accepting
Louis Beaumont423349dc7c75
diff --git a/crates/screenpipe-engine/src/notifications_api.rs b/crates/screenpipe-engine/src/notifications_api.rsindex 9d49242cd..1e2bc4dba 100644--- a/crates/screenpipe-engine/src/notifications_api.rs+++ b/crates/screenpipe-engine/src/notifications_api.rs@@ -16,11 +16,15 @@ use std::collections::VecDeque;use std::sync::Arc;use tokio::sync::Mutex;+use crate::pipes_api::SharedPipeManager;+/// Max pending notifications in the queue before oldest get dropped.const MAX_QUEUE_SIZE: usize = 50;/// Shared notification queue state.pub type SharedNotificationQueue = Arc<Mutex<VecDeque<PipeNotification>>>;+/// Combined state for notify handler: queue + optional pipe manager for validation.+pub type NotifyState = (SharedNotificationQueue, Option<SharedPipeManager>);pub fn new_notification_queue() -> SharedNotificationQueue {Arc::new(Mutex::new(VecDeque::new()))@@ -82,14 +86,27 @@ pub struct PipeNotification {/// POST /notify — enqueue a notification from a pipe.pub async fn notify_handler(- State(queue): State<SharedNotificationQueue>,+ State((queue, pm)): State<NotifyState>,Json(req): Json<NotifyRequest>,) -> Json<Value> {- // Validate: max 5 actions, context size capped+ // Validate: max 5 actionsif req.actions.len() > 5 {return Json(json!({ "error": "max 5 actions per notification" }));}+ // Validate: pipe actions reference existing pipes+ if let Some(ref pm) = pm {+ let mgr = pm.lock().await;+ for action in &req.actions {+ if action.action_type == "pipe" {+ let pipe_name = action.pipe.as_deref().unwrap_or(&req.pipe_name);+ if mgr.get_pipe(pipe_name).await.is_none() {+ return Json(json!({ "error": format!("pipe '{}' not found", pipe_name) }));+ }+ }+ }+ }+let id = format!("pipe-{}-{}", req.pipe_name, chrono::Utc::now().timestamp_millis());let notification = PipeNotification {@@ -104,7 +121,6 @@ pub async fn notify_handler(let mut q = queue.lock().await;q.push_back(notification);- // Drop oldest if over capacitywhile q.len() > MAX_QUEUE_SIZE {q.pop_front();}@@ -114,7 +130,7 @@ pub async fn notify_handler(/// GET /notifications/pending — drain all pending notifications.pub async fn pending_notifications_handler(- State(queue): State<SharedNotificationQueue>,+ State((queue, _pm)): State<NotifyState>,) -> Json<Value> {let mut q = queue.lock().await;let notifications: Vec<PipeNotification> = q.drain(..).collect();diff --git a/crates/screenpipe-engine/src/server.rs b/crates/screenpipe-engine/src/server.rsindex 6ea299adb..7c3e55187 100644--- a/crates/screenpipe-engine/src/server.rs+++ b/crates/screenpipe-engine/src/server.rs@@ -669,6 +669,8 @@ impl SCServer {// Notification routes (pipes can send notifications to the UI)let nq = self.notification_queue.clone();+ let notify_state: crate::notifications_api::NotifyState =+ (nq, self.pipe_manager.clone());let notif_routes = Router::new().route("/",@@ -678,13 +680,14 @@ impl SCServer {"/pending",axum::routing::get(crate::notifications_api::pending_notifications_handler),)- .with_state(nq.clone());+ .with_state(notify_state.clone());let router = router.nest("/notifications", notif_routes)// Top-level alias: POST /notify.route("/notify",- axum::routing::post(crate::notifications_api::notify_handler).with_state(nq),+ axum::routing::post(crate::notifications_api::notify_handler)+ .with_state(notify_state),);// Connections routes (pipe-facing integrations: Telegram, Slack, etc.)