Skip to content

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

feat(api): add LAN-access toggle — bind 0.0.0.0 with api_auth force-enabled

Louis Beaumontc8d9c83f0cad
diff --git a/apps/screenpipe-app-tauri/components/settings/privacy-section.tsx b/apps/screenpipe-app-tauri/components/settings/privacy-section.tsx
index 598298858..e8af82d12 100644
--- a/apps/screenpipe-app-tauri/components/settings/privacy-section.tsx
+++ b/apps/screenpipe-app-tauri/components/settings/privacy-section.tsx
@@ -550,6 +550,45 @@ export function PrivacySection() {
</CardContent>
</Card>
</LockedSetting>
+
+ {/* LAN access — off by default. Toggling on force-enables api_auth
+ (the backend mirrors this guard in RecordingConfig::from_settings
+ so the API is never exposed to the network unauthenticated). */}
+ <LockedSetting settingKey="listen_on_lan">
+ <Card className="border-border bg-card">
+ <CardContent className="px-3 py-2.5">
+ <div className="flex items-center justify-between">
+ <div className="flex items-center space-x-2.5">
+ <Shield className="h-4 w-4 text-muted-foreground shrink-0" />
+ <div>
+ <h3 className="text-sm font-medium text-foreground">
+ Allow LAN access
+ </h3>
+ <p className="text-xs text-muted-foreground mt-0.5">
+ Bind the API to <code className="text-[10px]">0.0.0.0</code> so other devices on your local
+ network can query it. API authentication is force-enabled
+ whenever this is on. Restart the app to apply.
+ </p>
+ </div>
+ </div>
+ <Switch
+ checked={settings.listenOnLan ?? false}
+ onCheckedChange={(checked) => {
+ // Keep the UI consistent with the backend guard: flipping
+ // LAN on also flips api_auth on, so the user can't
+ // accidentally leave themselves open.
+ if (checked) {
+ handleSettingsChange({ listenOnLan: true, apiAuth: true });
+ } else {
+ handleSettingsChange({ listenOnLan: false });
+ }
+ }}
+ />
+ </div>
+ </CardContent>
+ </Card>
+ </LockedSetting>
+
<EncryptDataCard
encryptStore={settings.encryptStore ?? false}
onEncryptStoreChange={(checked) => {
diff --git a/apps/screenpipe-app-tauri/lib/hooks/use-settings.tsx b/apps/screenpipe-app-tauri/lib/hooks/use-settings.tsx
index c888bde01..688b4c720 100644
--- a/apps/screenpipe-app-tauri/lib/hooks/use-settings.tsx
+++ b/apps/screenpipe-app-tauri/lib/hooks/use-settings.tsx
@@ -197,6 +197,14 @@ export type Settings = SettingsStore & {
}>;
apiAuth?: boolean;
apiKey?: string;
+ /**
+ * When true the backend binds the HTTP API to 0.0.0.0 instead of 127.0.0.1
+ * so other devices on the LAN can reach it. api_auth is force-enabled
+ * whenever this is true — the backend mirrors the guard in
+ * RecordingConfig::from_settings so the two flags stay consistent even
+ * if someone edits the settings file by hand.
+ */
+ listenOnLan?: boolean;
encryptStore?: boolean;
}
diff --git a/crates/screenpipe-config/src/recording.rs b/crates/screenpipe-config/src/recording.rs
index 82e197108..c88afe8f7 100644
--- a/crates/screenpipe-config/src/recording.rs
+++ b/crates/screenpipe-config/src/recording.rs
@@ -277,6 +277,15 @@ pub struct RecordingSettings {
/// Custom API key for remote authentication. If empty, a key is auto-generated.
#[serde(rename = "apiKey", default)]
pub api_key: String,
+
+ /// When true, the HTTP server binds to `0.0.0.0` so other devices on the
+ /// LAN can reach the screenpipe API. Off by default — the server binds
+ /// `127.0.0.1` (localhost only) which is the safe choice.
+ ///
+ /// `api_auth` is force-enabled whenever this is true; [`RecordingConfig::from_settings`]
+ /// overrides it, so a user can't accidentally expose the API unauthenticated on their network.
+ #[serde(rename = "listenOnLan", default)]
+ pub listen_on_lan: bool,
}
impl RecordingSettings {
@@ -354,6 +363,7 @@ impl Default for RecordingSettings {
schedule_rules: vec![],
api_auth: true,
api_key: String::new(),
+ listen_on_lan: false,
}
}
}
diff --git a/crates/screenpipe-engine/src/cli/mod.rs b/crates/screenpipe-engine/src/cli/mod.rs
index 3a2e1580f..9ce3e73af 100644
--- a/crates/screenpipe-engine/src/cli/mod.rs
+++ b/crates/screenpipe-engine/src/cli/mod.rs
@@ -378,6 +378,13 @@ pub struct RecordArgs {
#[arg(long, default_value_t = true)]
pub api_auth: bool,
+ /// Bind the HTTP server to 0.0.0.0 so other devices on the LAN can
+ /// reach it. Off by default — the server binds 127.0.0.1 only.
+ /// `--api-auth` is forced on whenever this flag is used; you can't
+ /// accidentally expose an unauthenticated API on your network.
+ #[arg(long, default_value_t = false)]
+ pub listen_on_lan: bool,
+
/// Encrypt secrets (API keys, OAuth tokens) at rest using the OS keychain.
/// Creates a keychain key if one doesn't exist. Without this flag, the CLI
/// will use an existing key (created by the desktop app) but won't create one.
@@ -457,6 +464,7 @@ impl RecordArgs {
analytics_enabled: !self.disable_telemetry,
ignore_incognito_windows: true,
pause_on_drm_content: self.pause_on_drm_content,
+ listen_on_lan: self.listen_on_lan,
..screenpipe_config::RecordingSettings::default()
}
}
@@ -538,7 +546,16 @@ impl RecordArgs {
let mut config =
crate::recording_config::RecordingConfig::from_settings(&settings, data_dir, None);
- config.api_auth = self.api_auth;
+ // Mirror the CLI flag, but never let the user turn auth OFF when
+ // the API is bound to the LAN — that would publish an unauthenticated
+ // service. `from_settings` already enforces this; we reapply it
+ // here so a `--no-api-auth --listen-on-lan` combo still authenticates.
+ config.api_auth = self.api_auth || self.listen_on_lan;
+ if self.listen_on_lan && !self.api_auth {
+ tracing::warn!(
+ "--listen-on-lan was set but --api-auth=false — forcing api_auth on for safety. Use `screenpipe auth token` to view your key."
+ );
+ }
if config.api_auth {
let settings_key = if settings.api_key.is_empty() {
None
diff --git a/crates/screenpipe-engine/src/recording_config.rs b/crates/screenpipe-engine/src/recording_config.rs
index 9f37b36ca..1e0b27b4f 100644
--- a/crates/screenpipe-engine/src/recording_config.rs
+++ b/crates/screenpipe-engine/src/recording_config.rs
@@ -221,9 +221,19 @@ impl RecordingConfig {
schedule_enabled: settings.schedule_enabled,
schedule_rules: settings.schedule_rules.clone(),
max_snapshot_width: settings.max_snapshot_width,
- api_auth: settings.api_auth,
+ // LAN exposure is opt-in. We force `api_auth` on whenever
+ // `listen_on_lan` is true so a user can never accidentally
+ // publish an unauthenticated API on their local network. The
+ // UI makes the dependency explicit; this guard is the safety
+ // net if someone edits the settings JSON by hand or flips the
+ // field via an older frontend that doesn't know about it.
+ api_auth: settings.api_auth || settings.listen_on_lan,
api_auth_key: None,
- listen_address: std::net::Ipv4Addr::LOCALHOST,
+ listen_address: if settings.listen_on_lan {
+ std::net::Ipv4Addr::UNSPECIFIED // 0.0.0.0 — all interfaces
+ } else {
+ std::net::Ipv4Addr::LOCALHOST
+ },
encrypt_secrets: false, // desktop app handles keychain via Tauri commands
}
}
@@ -289,3 +299,55 @@ impl RecordingConfig {
}
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use std::net::Ipv4Addr;
+
+ fn settings_with(lan: bool, api_auth: bool) -> screenpipe_config::RecordingSettings {
+ let mut s = screenpipe_config::RecordingSettings::default();
+ s.listen_on_lan = lan;
+ s.api_auth = api_auth;
+ s
+ }
+
+ fn build(s: &screenpipe_config::RecordingSettings) -> RecordingConfig {
+ RecordingConfig::from_settings(s, std::path::PathBuf::from("/tmp/sp_test"), None)
+ }
+
+ #[test]
+ fn defaults_to_loopback() {
+ let c = build(&screenpipe_config::RecordingSettings::default());
+ assert_eq!(c.listen_address, Ipv4Addr::LOCALHOST);
+ assert!(c.api_auth, "api_auth defaults to true for safety");
+ }
+
+ #[test]
+ fn listen_on_lan_binds_unspecified() {
+ let c = build(&settings_with(true, true));
+ assert_eq!(c.listen_address, Ipv4Addr::UNSPECIFIED);
+ assert!(c.api_auth);
+ }
+
+ #[test]
+ fn listen_on_lan_forces_api_auth_on_even_if_disabled() {
+ // The UI or a hand-edited settings file might flip api_auth off
+ // while listen_on_lan is on — we refuse to let that combo ship.
+ let c = build(&settings_with(true, false));
+ assert_eq!(c.listen_address, Ipv4Addr::UNSPECIFIED);
+ assert!(
+ c.api_auth,
+ "api_auth must be forced on when LAN access is enabled"
+ );
+ }
+
+ #[test]
+ fn listen_on_lan_off_respects_api_auth_off() {
+ // If the user has explicitly disabled auth AND kept the bind on
+ // loopback, leave them alone — localhost-only is already safe.
+ let c = build(&settings_with(false, false));
+ assert_eq!(c.listen_address, Ipv4Addr::LOCALHOST);
+ assert!(!c.api_auth);
+ }
+}