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

fix(api-auth): readable + regeneratable API key UI; remove user-set custom key

Louis Beaumont3329f70e3f43
diff --git a/Cargo.toml b/Cargo.toml
index dbee6c22c..8d98a9711 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -6,7 +6,7 @@ exclude = ["apps/screenpipe-app-tauri/src-tauri", "crates/screenpipe-integration
resolver = "2"
[workspace.package]
-version = "0.3.293"
+version = "0.3.294"
authors = ["louis030195 <[email protected]>"]
description = ""
repository = "https://github.com/screenpipe/screenpipe"
diff --git a/apps/screenpipe-app-tauri/components/settings/privacy-section.tsx b/apps/screenpipe-app-tauri/components/settings/privacy-section.tsx
index a105a1c34..7e71de752 100644
--- a/apps/screenpipe-app-tauri/components/settings/privacy-section.tsx
+++ b/apps/screenpipe-app-tauri/components/settings/privacy-section.tsx
@@ -203,6 +203,27 @@ export function PrivacySection() {
const [filterView, setFilterView] = useState<"all" | "personal" | "team">("all");
const [pushingFilter, setPushingFilter] = useState<string | null>(null);
+ // Live API auth key — fetched from the running server, not user-editable.
+ // Letting users set their own opens the door to weak/known keys; the server
+ // auto-generates a strong `sp-<uuid8>` and persists it to the secret store.
+ const [liveApiKey, setLiveApiKey] = useState<string | null>(null);
+ const [revealApiKey, setRevealApiKey] = useState(false);
+ const [regeneratingKey, setRegeneratingKey] = useState(false);
+
+ const loadLiveApiKey = useCallback(async () => {
+ try {
+ const { invoke } = await import("@tauri-apps/api/core");
+ const config = await invoke<{ key: string | null }>("get_local_api_config");
+ setLiveApiKey(config.key ?? null);
+ } catch {
+ setLiveApiKey(null);
+ }
+ }, []);
+
+ useEffect(() => {
+ void loadLiveApiKey();
+ }, [loadLiveApiKey]);
+
const { items: windowItems, isLoading: isWindowItemsLoading } =
useSqlAutocomplete("window");
const { items: urlItems, isLoading: isUrlItemsLoading } =
@@ -508,48 +529,90 @@ export function PrivacySection() {
<div className="mt-2.5 flex items-center space-x-2.5 pl-6.5">
<Input
type="text"
- placeholder="custom API key (leave empty to auto-generate)"
- value={settings.apiKey ?? ""}
- onChange={(e) => {
- handleSettingsChange({ apiKey: e.target.value });
- }}
- className="h-8 text-xs font-mono"
+ readOnly
+ placeholder={liveApiKey ? "" : "(loading…)"}
+ value={
+ liveApiKey
+ ? revealApiKey
+ ? liveApiKey
+ : "•".repeat(Math.min(liveApiKey.length, 32))
+ : ""
+ }
+ onClick={(e) => (e.target as HTMLInputElement).select()}
+ className="h-8 text-xs font-mono cursor-text select-all"
/>
<Button
variant="outline"
size="sm"
className="h-8 px-2 shrink-0"
+ title={revealApiKey ? "Hide key" : "Reveal key"}
+ onClick={() => setRevealApiKey((v) => !v)}
+ disabled={!liveApiKey}
+ >
+ {revealApiKey ? <EyeOff className="h-3.5 w-3.5" /> : <Eye className="h-3.5 w-3.5" />}
+ </Button>
+ <Button
+ variant="outline"
+ size="sm"
+ className="h-8 px-2 shrink-0"
+ title="Copy key"
+ disabled={!liveApiKey}
onClick={async () => {
- let key = settings.apiKey;
- if (!key) {
- try {
- const { invoke } = await import("@tauri-apps/api/core");
- const config = await invoke<{ key: string | null }>("get_local_api_config");
- key = config.key ?? undefined;
- } catch {}
- }
- if (key) {
- try {
- await navigator.clipboard.writeText(key);
- } catch {
- // Fallback: create a temporary input and use execCommand
- const el = document.createElement("textarea");
- el.value = key;
- el.style.position = "fixed";
- el.style.opacity = "0";
- document.body.appendChild(el);
- el.select();
- document.execCommand("copy");
- document.body.removeChild(el);
- }
- toast({ title: "API key copied to clipboard" });
- } else {
- toast({ title: "No API key available", description: "Restart the app to auto-generate a key", variant: "destructive" });
+ if (!liveApiKey) return;
+ try {
+ await navigator.clipboard.writeText(liveApiKey);
+ } catch {
+ const el = document.createElement("textarea");
+ el.value = liveApiKey;
+ el.style.position = "fixed";
+ el.style.opacity = "0";
+ document.body.appendChild(el);
+ el.select();
+ document.execCommand("copy");
+ document.body.removeChild(el);
}
+ toast({ title: "API key copied to clipboard" });
}}
>
<Copy className="h-3.5 w-3.5" />
</Button>
+ <Button
+ variant="outline"
+ size="sm"
+ className="h-8 px-2 shrink-0"
+ title="Regenerate key"
+ disabled={regeneratingKey}
+ onClick={async () => {
+ if (
+ !window.confirm(
+ "Regenerate API key? The browser extension and any other clients will need the new key. The new key takes effect after you Apply & Restart.",
+ )
+ ) {
+ return;
+ }
+ setRegeneratingKey(true);
+ try {
+ const { invoke } = await import("@tauri-apps/api/core");
+ const newKey = await invoke<string>("regenerate_api_auth_key");
+ setLiveApiKey(newKey);
+ setRevealApiKey(true);
+ toast({
+ title: "API key regenerated",
+ description: "Click Apply & Restart for the new key to take effect.",
+ });
+ } catch (e: any) {
+ toast({
+ title: "Failed to regenerate API key",
+ description: String(e?.message ?? e),
+ variant: "destructive",
+ });
+ } finally {
+ setRegeneratingKey(false);
+ }
+ }}
+ >
+ <RefreshCw className={cn("h-3.5 w-3.5", regeneratingKey && "animate-spin")} />
+ </Button>
</div>
)}
</LockedSetting>
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/commands.rs b/apps/screenpipe-app-tauri/src-tauri/src/commands.rs
index 01d040fdc..8139cf098 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/commands.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/commands.rs
@@ -259,6 +259,18 @@ pub async fn get_local_api_config(app_handle: tauri::AppHandle) -> serde_json::V
})
}
+/// Wipe the persisted API auth key and write a fresh `sp-<uuid8>` to the
+/// secret store. Returns the new key. The running server keeps its old key
+/// in memory until restart — the UI should prompt the user to apply & restart.
+#[tauri::command]
+#[specta::specta]
+pub async fn regenerate_api_auth_key() -> Result<String, String> {
+ let data_dir = screenpipe_core::paths::default_screenpipe_data_dir();
+ screenpipe_engine::auth_key::regenerate_api_auth_key(&data_dir)
+ .await
+ .map_err(|e| e.to_string())
+}
+
/// Read the enterprise license key from `enterprise.json`.
/// Checks in order:
/// 1. Next to executable (pushed via Intune/MDM to Program Files / .app bundle)
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/main.rs b/apps/screenpipe-app-tauri/src-tauri/src/main.rs
index 3790f189a..2657d5555 100755
--- a/apps/screenpipe-app-tauri/src-tauri/src/main.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/main.rs
@@ -912,6 +912,7 @@ async fn main() {
.invoke_handler(tauri::generate_handler![
commands::is_enterprise_build_cmd,
commands::get_local_api_config,
+ commands::regenerate_api_auth_key,
commands::get_enterprise_license_key,
enterprise_policy::set_enterprise_policy,
commands::save_enterprise_license_key,
diff --git a/crates/screenpipe-engine/src/auth_key.rs b/crates/screenpipe-engine/src/auth_key.rs
index 03639e9f6..88254fd12 100644
--- a/crates/screenpipe-engine/src/auth_key.rs
+++ b/crates/screenpipe-engine/src/auth_key.rs
@@ -79,6 +79,28 @@ fn resolve_without_env(
(k, "auto-generated")
}
+/// Wipe the persisted key and write a fresh `sp-<uuid8>` to the secret store.
+/// The running server will keep using its in-memory key until restart — caller
+/// is responsible for prompting the user to apply & restart for the new key
+/// to take effect.
+pub async fn regenerate_api_auth_key(data_dir: &Path) -> Result<String> {
+ let new_key = format!("sp-{}", &uuid::Uuid::new_v4().simple().to_string()[..8]);
+ if let Ok(store) = open_secret_store(data_dir).await {
+ store
+ .set("api_auth_key", new_key.as_bytes())
+ .await
+ .map_err(|e| anyhow::anyhow!("failed to persist regenerated key: {e}"))?;
+ } else {
+ anyhow::bail!("could not open secret store to persist regenerated key");
+ }
+ // Best-effort cleanup of legacy file so it doesn't shadow the new key.
+ if let Some(home) = dirs::home_dir() {
+ let _ = std::fs::remove_file(home.join(".screenpipe/auth.json"));
+ }
+ tracing::info!("api auth: key regenerated (new prefix: {})", &new_key[..6]);
+ Ok(new_key)
+}
+
async fn open_secret_store(data_dir: &Path) -> Result<screenpipe_secrets::SecretStore> {
let db_path = data_dir.join("db.sqlite");
let db_url = format!("sqlite:{}?mode=rwc", db_path.display());
diff --git a/packages/browser-extension/dist/manifest.json b/packages/browser-extension/dist/manifest.json
index 706ec6f36..c584e7f96 100644
--- a/packages/browser-extension/dist/manifest.json
+++ b/packages/browser-extension/dist/manifest.json
@@ -2,7 +2,7 @@
"manifest_version": 3,
"name": "Screenpipe Browser Bridge",
"description": "Connects your browser to Screenpipe for AI-powered web automation and data sync.",
- "version": "0.2.1",
+ "version": "0.2.2",
"background": {
"service_worker": "worker.js",
"type": "module"
diff --git a/packages/browser-extension/dist/options.html b/packages/browser-extension/dist/options.html
index 04eaafe3e..2b7657dff 100644
--- a/packages/browser-extension/dist/options.html
+++ b/packages/browser-extension/dist/options.html
@@ -149,8 +149,9 @@
<label for="token">API token</label>
<input id="token" type="password" placeholder="paste your screenpipe API token" autocomplete="off" spellcheck="false" />
<span class="help">
- Find it in screenpipe → Settings → Privacy → API key, or run
- <code>screenpipe auth token</code> in a terminal.
+ In screenpipe: Settings → Privacy → Security → "Require API
+ Authentication" — click the eye icon to reveal, then the copy icon.
+ Or run <code>screenpipe auth token</code> in a terminal.
</span>
</div>
diff --git a/packages/browser-extension/package.json b/packages/browser-extension/package.json
index f48ead0e9..83f3dfce0 100644
--- a/packages/browser-extension/package.json
+++ b/packages/browser-extension/package.json
@@ -1,6 +1,6 @@
{
"name": "@screenpipe/browser-extension",
- "version": "0.2.1",
+ "version": "0.2.2",
"private": true,
"scripts": {
"build": "bun build src/worker.ts src/options.ts src/popup.ts --outdir dist --target browser --format esm",