Skip to content

Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.

fix(host): keep the host's location and state off the network

leepokai53db238f2040
diff --git a/host/src/api/http.rs b/host/src/api/http.rs
index 3c4411df..7e80581e 100644
--- a/host/src/api/http.rs
+++ b/host/src/api/http.rs
@@ -62,17 +62,23 @@ impl IntoResponse for ApiError {
}
}
-async fn health(State(hub): State<Arc<Hub>>) -> Json<Value> {
- Json(json!({
+/// `GET /health`, open to the network. Where the binary lives (a path with the user's name) and whether
+/// a turn is running are for this computer's updater and desktop app only.
+async fn health(State(hub): State<Arc<Hub>>, ConnectInfo(peer): ConnectInfo<SocketAddr>) -> Json<Value> {
+ let mut health = json!({
"ok": true,
"hostId": hub.host_id,
"computerId": hub.identity.computer_id(),
"version": env!("CARGO_PKG_VERSION"),
- "binaryPath": crate::service::binary_identity().map(|(path, _)| path),
"environment": crate::environment::Environment::current().name(),
- "binaryHash": crate::service::binary_identity().map(|(_, hash)| hash),
- "busy": hub.busy(),
- }))
+ });
+ if is_loopback(peer.ip()) {
+ let binary = crate::service::binary_identity();
+ health["binaryPath"] = json!(binary.map(|(path, _)| path));
+ health["binaryHash"] = json!(binary.map(|(_, hash)| hash));
+ health["busy"] = hub.busy().into();
+ }
+ Json(health)
}
async fn statusline(
@@ -234,9 +240,9 @@ async fn routine_hook(
mod tests {
use super::*;
- #[test]
- fn phone_streams_hold_pushes_until_the_last_one_closes() {
- let dir = std::env::temp_dir().join(format!("codync-phone-events-{}", uuid::Uuid::new_v4()));
+ /// A hub on an in-memory store, with its identity in a temp folder the test removes.
+ fn temp_hub() -> (Arc<Hub>, std::path::PathBuf) {
+ let dir = std::env::temp_dir().join(format!("codync-http-{}", uuid::Uuid::new_v4()));
std::fs::create_dir_all(&dir).expect("temp dir");
let hub = Hub::new(
crate::store::Store::open(std::path::Path::new(":memory:")).expect("store"),
@@ -245,6 +251,12 @@ mod tests {
"test".into(),
19222,
);
+ (hub, dir)
+ }
+
+ #[test]
+ fn phone_streams_hold_pushes_until_the_last_one_closes() {
+ let (hub, dir) = temp_hub();
let desktop = events_stream(&hub, 0, Some("macos"), &Caller::Local).expect("desktop events");
assert!(!hub.phone_connected());
let android = events_stream(&hub, 0, Some("android"), &Caller::Local).expect("Android events");
@@ -258,6 +270,21 @@ mod tests {
let _ = std::fs::remove_dir_all(dir);
}
+ #[tokio::test]
+ async fn health_keeps_the_binary_and_busy_state_on_this_computer() {
+ let (hub, dir) = temp_hub();
+ let at = |addr: &str| ConnectInfo(addr.parse::<SocketAddr>().expect("address"));
+ let lan = health(State(hub.clone()), at("192.168.1.20:50000")).await.0;
+ assert!(lan["computerId"].is_string());
+ for key in ["binaryPath", "binaryHash", "busy"] {
+ assert!(lan.get(key).is_none(), "{key} reached the network");
+ }
+ let local = health(State(hub), at("[::ffff:127.0.0.1]:50000")).await.0;
+ assert_eq!(local["busy"], false);
+ assert!(local.get("binaryPath").is_some());
+ let _ = std::fs::remove_dir_all(dir);
+ }
+
#[test]
fn only_loopback_counts_as_this_computer() {
let ip = |s: &str| s.parse::<IpAddr>().expect("test addresses are valid");