The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
feat(inbound): add prompt injection screening for pinned events
Steven Enamakel93903c276cb6
diff --git a/crates/openhuman-core/src/inbound/pinned.rs b/crates/openhuman-core/src/inbound/pinned.rsindex 0d336a33fb..8958b8db44 100644--- a/crates/openhuman-core/src/inbound/pinned.rs+++ b/crates/openhuman-core/src/inbound/pinned.rs@@ -29,7 +29,7 @@ use async_trait::async_trait;use tinyeventqueues_bus::Turn;use super::events::{external_of, ExternalItem};-use super::results::{ResultStatus, Results, Stored};+use super::results::{BlockedEvent, ResultStatus, Results, Stored};use crate::config::schema::InboundSourceConfig;use crate::core::bus::BUS;use crate::core::events::DomainEvent;@@ -120,6 +120,50 @@ pub fn render_prompt(}}+/// Split `items` into those the prompt-injection guard lets through and those+/// it blocks. Each event's text is screened on its own with the guard+/// `inference.agent_chat` applies to the whole message, so one injected+/// event is left out instead of failing its batch; the reason is the guard's+/// verdict and rule codes, never the text.+fn screen(items: Vec<ExternalItem>) -> (Vec<ExternalItem>, Vec<BlockedEvent>) {+ use crate::security::prompt_injection::{+ enforce_prompt_input, PromptEnforcementAction, PromptEnforcementContext,+ };+ let mut kept = Vec::with_capacity(items.len());+ let mut blocked = Vec::new();+ for item in items {+ let decision = enforce_prompt_input(+ &item.text,+ PromptEnforcementContext {+ source: "inbound.pinned",+ request_id: Some(&item.id),+ user_id: None,+ session_id: Some("inbound"),+ },+ );+ let verdict = match decision.action {+ PromptEnforcementAction::Allow => {+ kept.push(item);+ continue;+ }+ PromptEnforcementAction::Blocked => "blocked",+ PromptEnforcementAction::ReviewBlocked => "flagged for review",+ };+ let codes: Vec<&str> = decision.reasons.iter().map(|r| r.code.as_str()).collect();+ let reason = if codes.is_empty() {+ verdict.to_owned()+ } else {+ format!("{verdict}: {}", codes.join(", "))+ };+ tracing::info!(event_id = %item.id, reason = %reason, "[inbound] event kept out of the pinned prompt");+ blocked.push(BlockedEvent {+ event_id: item.id,+ reason,+ });+ }+ (kept, blocked)+}+/// Turns being run, so a redelivery and a resume never run one twice at/// once.type InFlight = Arc<Mutex<HashSet<String>>>;@@ -224,12 +268,18 @@ impl Pinned {return Delivered::Running;};let items: Vec<ExternalItem> = turn.events.iter().filter_map(external_of).collect();+ let event_ids: Vec<String> = items.iter().map(|item| item.id.clone()).collect();+ let (items, blocked) = screen(items);let key = turn.events.first().map_or_else(|| turn.conversation_key.clone(),|e| e.conversation_key.clone(),);- let event_ids = items.iter().map(|item| item.id.clone()).collect();- let message = render_prompt(name, &key, source, &items);+ // Nothing left to run: the turn completes empty, without the model.+ let message = if items.is_empty() {+ String::new()+ } else {+ render_prompt(name, &key, source, &items)+ };let fresh = Stored::running(&turn.turn_id,name,diff --git a/crates/openhuman-core/src/inbound/results.rs b/crates/openhuman-core/src/inbound/results.rsindex e881a52574..c9e0cc3d02 100644--- a/crates/openhuman-core/src/inbound/results.rs+++ b/crates/openhuman-core/src/inbound/results.rs@@ -89,6 +89,9 @@ pub struct InboundResult {pub error: Option<String>,/// The source's ids of the events the turn carried, in order.pub event_ids: Vec<String>,+ /// The events the prompt-injection guard kept out of the agent's prompt.+ #[serde(default)]+ pub blocked: Vec<BlockedEvent>,/// When the turn was first started, Unix epoch milliseconds.pub created_ms: u64,/// When it completed or failed.@@ -96,6 +99,16 @@ pub struct InboundResult {pub completed_ms: Option<u64>,}+/// An event the prompt-injection guard kept out of a turn's prompt.+#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]+pub struct BlockedEvent {+ /// The source's id of the event.+ pub event_id: String,+ /// The guard's verdict and rule codes (`blocked: instruction_override`);+ /// never the event's text.+ pub reason: String,+}+/// A result as stored: the wire form, the message the agent was given (so a/// run a previous process left unfinished can be run again) and whether the/// pusher acknowledged it.@@ -133,6 +146,7 @@ impl Stored {text: None,error: None,event_ids,+ blocked: Vec::new(),created_ms,completed_ms: None,},@@ -142,6 +156,15 @@ impl Stored {}}+impl Stored {+ /// With `blocked` recorded as kept out of the prompt.+ #[must_use]+ pub fn with_blocked(mut self, blocked: Vec<BlockedEvent>) -> Self {+ self.result.blocked = blocked;+ self+ }+}+/// Which results `inbound.results` lists.#[derive(Debug, Clone, PartialEq, Eq)]pub struct ResultQuery {