Skip to content

Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.

fix(local-installation): keep a running TeamHub's identity key readable

claude-opus-5-5-medium0d3f5ce88f9d
diff --git a/apps/desktop/AGENTS.md b/apps/desktop/AGENTS.md
index 6ad9594d..41a6113c 100644
--- a/apps/desktop/AGENTS.md
+++ b/apps/desktop/AGENTS.md
@@ -90,7 +90,10 @@ Gateway and runs Agents. The daemon exits with the app.
instance's private `local-identity.key`, read by `readLocalIdentity`) over
the nonce and the window's origin. The installer puts the key only in
TeamHub's process environment, never in `services.env`, `native.env` or
- another service's environment, so no other local service can answer. It asks TeamHub's port rather than the web
+ another service's environment, so no other local service can answer. An
+ earlier version kept it in `services.env`; the installer moves it out
+ unchanged, and until then `readLocalIdentity` reads it there, because a
+ TeamHub that version started still uses it. It asks TeamHub's port rather than the web
port, which a program could take and relay through. "Sign in with this
computer's account": `localAccount.signIn()` reads the file in the main
process and signs the window's session in with `signInWithPassword`,
diff --git a/packages/local-installation/src/account.test.ts b/packages/local-installation/src/account.test.ts
index 720dd0c4..3aceebf3 100644
--- a/packages/local-installation/src/account.test.ts
+++ b/packages/local-installation/src/account.test.ts
@@ -272,18 +272,20 @@ it("reads the server identity from the private instance files", async () => {
JSON.stringify({ source: { ports: { teamhub: 4100, web: 3000 } } }),
{ mode: 0o600 },
);
- // An instance the installer has not upgraded yet has no key; one left in
- // services.env by an earlier version is not used until the installer
- // moves it.
+ const services = path.join(f.instance.root, "services.env");
+ await writeFile(services, "LINGER_SECRET_SEED=x\n", { mode: 0o600 });
+ // An instance the installer has not upgraded yet has no key.
+ await expect(readLocalIdentity(f.instance)).rejects.toThrow(/identity/);
+ // A TeamHub an earlier version started still uses the key it kept in
+ // services.env until the installer moves it.
+ const legacy = Buffer.alloc(32, 3);
await writeFile(
- path.join(f.instance.root, "services.env"),
- `TEAMHUB_LOCAL_IDENTITY_KEY=${key.toString("base64")}\n`,
+ services,
+ `TEAMHUB_LOCAL_IDENTITY_KEY=${legacy.toString("base64")}\n`,
{ mode: 0o600 },
);
- await expect(readLocalIdentity(f.instance)).rejects.toThrow(/identity/);
+ expect((await readLocalIdentity(f.instance)).key).toEqual(legacy);
const keyFile = path.join(f.instance.root, "local-identity.key");
- await writeFile(keyFile, "not a key\n", { mode: 0o600 });
- await expect(readLocalIdentity(f.instance)).rejects.toThrow(/identity/);
await writeFile(keyFile, `${key.toString("base64")}\n`, { mode: 0o600 });
expect(await readLocalIdentity(f.instance)).toEqual({
teamhub: "http://127.0.0.1:4100",
diff --git a/packages/local-installation/src/account.ts b/packages/local-installation/src/account.ts
index 09a51724..f5151fef 100644
--- a/packages/local-installation/src/account.ts
+++ b/packages/local-installation/src/account.ts
@@ -2,6 +2,7 @@ import { windowsPrivatePath } from "./windows-private.js";
import { randomBytes } from "node:crypto";
import { lstat, readFile } from "node:fs/promises";
import path from "node:path";
+import { parseEnv } from "node:util";
import { readLocalIdentityKey, type Instance } from "./instance.js";
import { atomicPrivate, readPrivate } from "./private-files.js";
@@ -59,6 +60,8 @@ export async function readLocalLogin(
// How the desktop app checks that the server it sends the owner password to
// is this instance's TeamHub: TeamHub's own loopback address and the key
// only TeamHub's process and this file's owner hold (see TeamHub's /v0/local/identity).
+// Until the installer next starts the services, a TeamHub an earlier
+// version started still uses the key that version kept in services.env.
export interface LocalIdentity {
teamhub: string;
key: Buffer;
@@ -68,11 +71,16 @@ export async function readLocalIdentity(
): Promise<LocalIdentity> {
const unavailable = () =>
new Error("Linger on this computer has no server identity yet.");
- const [settings, encoded] = await Promise.all([
+ const [settings, encoded, services] = await Promise.all([
readPrivate(path.join(instance.root, "instance.json")),
readLocalIdentityKey(instance.root),
+ readPrivate(path.join(instance.root, "services.env")),
]);
- if (settings === undefined || encoded === undefined) throw unavailable();
+ const key = Buffer.from(
+ encoded ?? parseEnv(services ?? "").TEAMHUB_LOCAL_IDENTITY_KEY ?? "",
+ "base64",
+ );
+ if (settings === undefined || key.length !== 32) throw unavailable();
let port: unknown;
try {
port = (JSON.parse(settings) as Partial<Instance>).source?.ports?.teamhub;
@@ -85,7 +93,6 @@ export async function readLocalIdentity(
(port as number) > 65535
)
throw unavailable();
- const key = Buffer.from(encoded, "base64");
return { teamhub: `http://127.0.0.1:${port as number}`, key };
}
interface LocalAccount {