From c082574efc2fcbc655745cf6afe58f2e6ea73b9c Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Tue, 1 Dec 2026 13:04:48 -0500 Subject: [PATCH] fix(desktop): refuse an invalid withheld-file handle as invalid, not as no free handle (#15571) DesktopBuildSecrets.keep stops at the first candidate handle that is not a secret's handle. When that was the computer's own handle, such as ../escaped, the refusal said REA had no handle free and told the person to delete old secret files. Refuse the invalid handle up front and say so. --- src/application/desktop/DesktopBuildSecrets.test.ts | 7 ++++++- src/application/desktop/DesktopBuildSecrets.ts | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/application/desktop/DesktopBuildSecrets.test.ts b/src/application/desktop/DesktopBuildSecrets.test.ts index d0b3e9419b8..07fe1fc19fa 100644 --- a/src/application/desktop/DesktopBuildSecrets.test.ts +++ b/src/application/desktop/DesktopBuildSecrets.test.ts @@ -70,7 +70,12 @@ describe("build secrets of one server", () => { const secrets = new DesktopBuildSecrets(directory); await expect( secrets.keep("../escaped", Buffer.from(FIRST)), - ).rejects.toThrow(); + ).rejects.toMatchObject({ + _tag: "ProviderAdapterError", + userMessage: expect.stringContaining( + "\"../escaped\" as a withheld file's handle, which is not a secret's handle", + ), + }); expect(await readdir(dirname(directory))).toEqual(["s"]); }); }); diff --git a/src/application/desktop/DesktopBuildSecrets.ts b/src/application/desktop/DesktopBuildSecrets.ts index dfa1bacc763..57bb5b0f8f0 100644 --- a/src/application/desktop/DesktopBuildSecrets.ts +++ b/src/application/desktop/DesktopBuildSecrets.ts @@ -97,6 +97,14 @@ export class DesktopBuildSecrets { /** Keep a withheld file's bytes, in base64, for a witness to supply, as a secret of their own: `handle`, or the first `handle-` that holds no other value, never replacing one; the handle that keeps them. */ async keep(handle: string, bytes: Buffer): Promise { + // The handle comes from the computer's export report; refuse one that + // cannot name a file here rather than reporting that none is free. + if (!buildSecretHandleSchema.safeParse(handle).success) + throw new ProviderAdapterError(AGENTENV_PROVIDER, "build_secret_file", { + userMessage: `The computer named ${JSON.stringify(handle)} as a withheld file's handle, which is not a secret's handle; REA kept nothing.`, + remediationAction: + "Export again; a handle is lowercase letters, digits, dot, dash and underscore, at most 63 characters.", + }); const value = bytes.toString("base64"); for (let count = 1; count <= MAX_KEPT_HANDLES; count += 1) { const candidate = count === 1 ? handle : `${handle}-${String(count)}`;