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(core): add dev-only /dev/connect endpoint for Vite renderer handoff
Steven Enamakel1340ddb3ac6c
diff --git a/crates/openhuman-core/src/core/auth.rs b/crates/openhuman-core/src/core/auth.rsindex 9b8a602982..0cbd434b76 100644--- a/crates/openhuman-core/src/core/auth.rs+++ b/crates/openhuman-core/src/core/auth.rs@@ -31,6 +31,7 @@//! - `GET /` — public info page//! - `GET /health` — liveness probe//! - `GET /schema` — read-only schema discovery+//! - `GET /dev/connect` — dev-only core handoff; see `core::dev_connect`//! - `GET /events` — SSE stream; browser `EventSource` cannot set//! headers, so the handler enforces a bind-token ///! bearer credential itself@@ -105,6 +106,10 @@ const PUBLIC_PATHS: &[&str] = &[// authorization server posts back here with `?code=…&state=…` and no// bearer; the one-time `state` (minted in `oauth_begin`) is the guard."/oauth/mcp/callback",+ // Dev-only handoff to a loopback Vite renderer. Guards live in the handler+ // (`core::dev_connect`): debug build or explicit opt-in, loopback `app`+ // origin and `Host`, no cross-site navigation.+ "/dev/connect","/schema","/events",];diff --git a/crates/openhuman-core/src/core/dev_connect_tests.rs b/crates/openhuman-core/src/core/dev_connect_tests.rsnew file mode 100644index 0000000000..dd0d0c4431--- /dev/null+++ b/crates/openhuman-core/src/core/dev_connect_tests.rs@@ -0,0 +1,76 @@+use super::*;++#[test]+fn enabled_in_debug_builds_or_with_opt_in() {+ assert!(dev_connect_enabled_with(true, None));+ assert!(dev_connect_enabled_with(false, Some("1")));+ assert!(dev_connect_enabled_with(false, Some(" true ")));+ assert!(!dev_connect_enabled_with(false, None));+ assert!(!dev_connect_enabled_with(false, Some("0")));+ assert!(!dev_connect_enabled_with(false, Some("")));+}++#[test]+fn app_origin_accepts_only_bare_http_loopback() {+ assert_eq!(+ normalize_app_origin("http://localhost:1420").as_deref(),+ Some("http://localhost:1420")+ );+ assert_eq!(+ normalize_app_origin("http://127.0.0.1:1430/").as_deref(),+ Some("http://127.0.0.1:1430")+ );+ assert_eq!(+ normalize_app_origin("http://[::1]:1420").as_deref(),+ Some("http://[::1]:1420")+ );+ for bad in [+ "https://localhost:1420",+ "http://evil.example:1420",+ "http://localhost.evil.example",+ "http://user:pw@localhost:1420",+ "http://localhost:1420/other",+ "http://localhost:1420/?x=1",+ "javascript:alert(1)",+ "",+ ] {+ assert_eq!(normalize_app_origin(bad), None, "{bad} must be rejected");+ }+}++#[test]+fn rpc_url_comes_from_a_loopback_host_header() {+ assert_eq!(+ rpc_url_from_host("127.0.0.1:7788").as_deref(),+ Some("http://127.0.0.1:7788/rpc")+ );+ assert_eq!(+ rpc_url_from_host("localhost:7790").as_deref(),+ Some("http://localhost:7790/rpc")+ );+ assert_eq!(rpc_url_from_host("192.168.1.5:7788"), None);+ assert_eq!(rpc_url_from_host("evil.example:7788"), None);+ // No explicit port means we cannot say where the core listens.+ assert_eq!(rpc_url_from_host("127.0.0.1"), None);+}++#[test]+fn cross_site_navigations_are_refused() {+ assert!(is_direct_navigation(None));+ assert!(is_direct_navigation(Some("none")));+ assert!(is_direct_navigation(Some("same-origin")));+ assert!(!is_direct_navigation(Some("cross-site")));+ assert!(!is_direct_navigation(Some("same-site")));+}++#[test]+fn redirect_carries_credentials_in_the_fragment_only() {+ let target = build_redirect("http://localhost:1420", "http://127.0.0.1:7788/rpc", "a+b/c");+ let (before_hash, fragment) = target.split_once('#').expect("fragment");+ assert_eq!(before_hash, "http://localhost:1420/__dev-connect");+ assert!(!before_hash.contains("token"));+ assert_eq!(+ fragment,+ "rpcUrl=http%3A%2F%2F127.0.0.1%3A7788%2Frpc&token=a%2Bb%2Fc"+ );+}diff --git a/crates/openhuman-core/src/core/jsonrpc.rs b/crates/openhuman-core/src/core/jsonrpc.rsindex 51907888ea..5056aa02ba 100644--- a/crates/openhuman-core/src/core/jsonrpc.rs+++ b/crates/openhuman-core/src/core/jsonrpc.rs@@ -797,6 +797,8 @@ pub fn build_core_http_router(socketio_enabled: bool) -> Router {).route("/ws/dictation", get(dictation_ws_handler)).route("/oauth/mcp/callback", get(oauth_mcp_callback_handler))+ // Dev-only: hand this core (URL + bearer) to a loopback Vite renderer.+ .route("/dev/connect", get(crate::core::dev_connect::dev_connect_handler))// OpenAI-compatible inference endpoint (/v1/chat/completions, /v1/models).nest("/v1", crate::inference::http::router())// Apply `AppState` here so the outer router becomes `Router<()>` anddiff --git a/crates/openhuman-core/src/core/mod.rs b/crates/openhuman-core/src/core/mod.rsindex 012408af7f..b1abdfa08c 100644--- a/crates/openhuman-core/src/core/mod.rs+++ b/crates/openhuman-core/src/core/mod.rs@@ -13,6 +13,8 @@ pub mod bus;pub mod bus_testing;pub mod cli;pub mod cli_capability;+#[cfg(feature = "http-server")]+pub mod dev_connect;pub mod dispatch;pub mod event_bind_tokens;pub mod events;