mirror of
https://github.com/morluto/rea.git
synced 2026-12-03 21:46:01 +00:00
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.
This commit is contained in:
1 parent
751b97ad12
commit
c082574efc
2 files changed
+14
-1
No files matched your search
@@ -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"]);
|
||||
});
|
||||
});
|
||||
@@ -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-<n>` that holds no other value, never replacing one; the handle that keeps them. */
|
||||
async keep(handle: string, bytes: Buffer): Promise<string> {
|
||||
// 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)}`;
|
||||
|
||||
Reference in new issue
Block a user