Skip to content

Commit 6ea1752

Browse files
only21milclaude
andcommitted
fix(desktop): fail a retried update signature check that electron-updater skipped
When a signature check fails and its PowerShell capability probe also fails, electron-updater logs that it is ignoring signature validation and resolves null, which NsisUpdater accepts. The first check keeps that upstream behavior. The retry runs only after a timed-out check, so it now returns a rejection when it sees that warning or any result other than a rejection string or a clean null. Also cover a verifier reused across downloads, so the retry wrapper does not stack. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent badd70c commit 6ea1752

2 files changed

Lines changed: 67 additions & 3 deletions

File tree

‎apps/desktop/src/electron/ElectronUpdater.test.ts‎

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { assert, describe, it } from "@effect/vitest";
22
import * as Effect from "effect/Effect";
3-
import type { VerifyUpdateCodeSignature } from "electron-updater";
3+
import type { Logger, VerifyUpdateCodeSignature } from "electron-updater";
44
import { beforeEach, vi } from "vite-plus/test";
55

66
const { autoUpdaterMock } = vi.hoisted(() => ({
@@ -14,6 +14,7 @@ const { autoUpdaterMock } = vi.hoisted(() => ({
1414
fullChangelog: false,
1515
checkForUpdates: vi.fn(() => Promise.resolve(null)),
1616
downloadUpdate: vi.fn(() => Promise.resolve([])),
17+
logger: { info: vi.fn(), warn: vi.fn(), error: vi.fn() } as Logger | null,
1718
on: vi.fn(),
1819
quitAndInstall: vi.fn(),
1920
removeListener: vi.fn(),
@@ -148,7 +149,7 @@ describe("ElectronUpdater", () => {
148149
Object.assign(new Error("Command failed: powershell.exe"), { killed: true });
149150

150151
// NsisUpdater runs the verifier after the download and fails on any non-null result.
151-
const downloadVerifyingSignature = (verify: VerifyUpdateCodeSignature) => {
152+
const downloadVerifyingSignature = (verify = autoUpdaterMock.verifyUpdateCodeSignature) => {
152153
autoUpdaterMock.verifyUpdateCodeSignature = verify;
153154
autoUpdaterMock.downloadUpdate.mockImplementationOnce(async () => {
154155
const rejection = await autoUpdaterMock.verifyUpdateCodeSignature?.(
@@ -193,5 +194,36 @@ describe("ElectronUpdater", () => {
193194
}
194195
}).pipe(Effect.provide(ElectronUpdater.layer)),
195196
);
197+
198+
it.effect("rejects a retried check that electron-updater skipped", () =>
199+
Effect.gen(function* () {
200+
// After a failed check, electron-updater resolves null when its PowerShell probe also fails.
201+
const verify = vi
202+
.fn<VerifyUpdateCodeSignature>()
203+
.mockRejectedValueOnce(timedOut())
204+
.mockImplementationOnce(async () => {
205+
autoUpdaterMock.logger?.warn(
206+
"Cannot execute ConvertTo-Json: spawnSync powershell.exe ETIMEDOUT. Ignoring signature validation due to unsupported powershell version. Please upgrade to powershell 3 or higher.",
207+
);
208+
return null;
209+
});
210+
211+
const error = yield* downloadVerifyingSignature(verify).pipe(Effect.flip);
212+
213+
assert.instanceOf(error, ElectronUpdater.ElectronUpdaterDownloadUpdateError);
214+
assert.equal(verify.mock.calls.length, 2);
215+
}).pipe(Effect.provide(ElectronUpdater.layer)),
216+
);
217+
218+
it.effect("retries once per download when the verifier is reused", () =>
219+
Effect.gen(function* () {
220+
const verify = vi.fn<VerifyUpdateCodeSignature>(() => Promise.reject(timedOut()));
221+
222+
yield* downloadVerifyingSignature(verify).pipe(Effect.flip);
223+
yield* downloadVerifyingSignature().pipe(Effect.flip);
224+
225+
assert.equal(verify.mock.calls.length, 4);
226+
}).pipe(Effect.provide(ElectronUpdater.layer)),
227+
);
196228
});
197229
});

‎apps/desktop/src/electron/ElectronUpdater.ts‎

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,36 @@ const isTimedOutChildProcess = (error: unknown) =>
8686

8787
const signatureChecksWithRetry = new WeakSet<VerifyUpdateCodeSignature>();
8888

89+
// When a check fails and its PowerShell capability probe fails too, electron-updater logs this,
90+
// skips the check and resolves null, which NsisUpdater accepts as a valid signature.
91+
const skippedSignatureCheck = "Ignoring signature validation";
92+
93+
// The retry follows a failed check, so it passes only on a null that was not a skipped check.
94+
const retryTimedOutSignatureCheck = async (
95+
verify: VerifyUpdateCodeSignature,
96+
publisherNames: string[],
97+
path: string,
98+
) => {
99+
const logger = autoUpdater.logger;
100+
let skipped = false;
101+
autoUpdater.logger = {
102+
info: (message) => logger?.info(message),
103+
warn: (message) => {
104+
skipped ||= String(message).includes(skippedSignatureCheck);
105+
logger?.warn(message);
106+
},
107+
error: (message) => logger?.error(message),
108+
debug: (message) => logger?.debug?.(message),
109+
};
110+
try {
111+
const result = await verify(publisherNames, path);
112+
if (typeof result === "string" || (result === null && !skipped)) return result;
113+
return "the signature could not be verified after a timed-out check was retried";
114+
} finally {
115+
autoUpdater.logger = logger;
116+
}
117+
};
118+
89119
// electron-updater's Windows signature check kills PowerShell after 20 s. Endpoint security
90120
// scanning a freshly downloaded installer can exceed that on the first check, while a repeat
91121
// check of the scanned file is fast. Retry a timed-out check once; any other outcome, including
@@ -98,7 +128,9 @@ const retrySignatureCheckAfterTimeout = () => {
98128
if (verify === undefined || signatureChecksWithRetry.has(verify)) return;
99129
const verifyWithRetry: VerifyUpdateCodeSignature = (publisherNames, path) =>
100130
verify(publisherNames, path).catch((error: unknown) =>
101-
isTimedOutChildProcess(error) ? verify(publisherNames, path) : Promise.reject(error),
131+
isTimedOutChildProcess(error)
132+
? retryTimedOutSignatureCheck(verify, publisherNames, path)
133+
: Promise.reject(error),
102134
);
103135
signatureChecksWithRetry.add(verifyWithRetry);
104136
updater.verifyUpdateCodeSignature = verifyWithRetry;

0 commit comments

Comments
 (0)