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)}`;