Repository navigation
fix(desktop): retry a timed-out Windows update signature check once #22357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
49d6f63
fix(desktop): retry a timed-out Windows update signature check once (…
only21mil e097fe6
Merge main (05696c636e) into r9/rl-21273
only21mil 0a7f1ef
chore(desktop): merge main into Windows signature retry
maria-rcks d42d4a9
test(desktop): cover signature retry rejection and cleanup
maria-rcks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| import { assert, describe, it } from "@effect/vitest"; | ||
| import * as Effect from "effect/Effect"; | ||
| import type { VerifyUpdateCodeSignature } from "electron-updater"; | ||
| import { vi } from "vite-plus/test"; | ||
|
|
||
| const { autoUpdaterMock } = vi.hoisted(() => ({ | ||
| autoUpdaterMock: { | ||
| channel: "latest", | ||
| downloadUpdate: async (): Promise<string[]> => [], | ||
| logger: { | ||
| info: (_message: unknown) => {}, | ||
| warn: (_message: unknown) => {}, | ||
| error: (_message: unknown) => {}, | ||
| }, | ||
| verifyUpdateCodeSignature: undefined as VerifyUpdateCodeSignature | undefined, | ||
| }, | ||
| })); | ||
|
|
||
| vi.mock("electron-updater", () => ({ autoUpdater: autoUpdaterMock })); | ||
|
|
||
| import * as ElectronUpdater from "./ElectronUpdater.ts"; | ||
|
|
||
| describe("Windows update signature check", () => { | ||
| const publisherNames = ["T3 Tools Inc"]; | ||
| const installerPath = "C:\\updater\\pending\\temp-T3-Code-x64.exe"; | ||
| // execFile marks a timeout kill; no clock or PowerShell process is needed here. | ||
| const timedOut = () => | ||
| Object.assign(new Error("Command failed: powershell.exe"), { killed: true }); | ||
|
|
||
| const setup = () => { | ||
| autoUpdaterMock.verifyUpdateCodeSignature = undefined; | ||
| autoUpdaterMock.downloadUpdate = async () => { | ||
| const rejection = await autoUpdaterMock.verifyUpdateCodeSignature?.( | ||
| publisherNames, | ||
| installerPath, | ||
| ); | ||
| if (rejection != null) throw new Error(`Invalid signature: ${rejection}`); | ||
| return [installerPath]; | ||
| }; | ||
| }; | ||
|
|
||
| const downloadVerifyingSignature = () => | ||
| Effect.flatMap(ElectronUpdater.ElectronUpdater, (updater) => updater.downloadUpdate); | ||
|
|
||
| it.effect( | ||
| "downloads after a timeout only when the same installer and publisher pass verification", | ||
| () => | ||
| Effect.gen(function* () { | ||
| setup(); | ||
| const logger = autoUpdaterMock.logger; | ||
| let firstCheck = true; | ||
| autoUpdaterMock.verifyUpdateCodeSignature = async (names, path) => { | ||
| if (path !== installerPath || names.length !== 1 || names[0] !== publisherNames[0]) { | ||
| return "Unexpected installer or publisher"; | ||
| } | ||
| if (firstCheck) { | ||
| firstCheck = false; | ||
| throw timedOut(); | ||
| } | ||
| return null; | ||
| }; | ||
|
|
||
| assert.isUndefined(yield* downloadVerifyingSignature()); | ||
| assert.strictEqual(autoUpdaterMock.logger, logger); | ||
| }).pipe(Effect.provide(ElectronUpdater.layer)), | ||
| ); | ||
|
|
||
| it.effect("rejects invalid signatures, other errors and two timeouts on repeated downloads", () => | ||
| Effect.gen(function* () { | ||
| setup(); | ||
| const logger = autoUpdaterMock.logger; | ||
| const outcomes = [ | ||
| () => Promise.resolve("Invalid publisher"), | ||
| () => Promise.reject(new Error("Cannot execute PowerShell")), | ||
| () => Promise.reject(timedOut()), | ||
| ]; | ||
| for (const outcome of outcomes) { | ||
| let failures: Array<() => Promise<string | null>> = []; | ||
| autoUpdaterMock.verifyUpdateCodeSignature = () => | ||
| failures.shift()?.() ?? Promise.resolve(null); | ||
|
|
||
| // An extra retry would accept the installer, including if wrappers stack on download two. | ||
| for (const retry of [false, true]) { | ||
| for (let download = 0; download < 2; download++) { | ||
| failures = retry || outcome === outcomes[2] ? [outcomes[2]!, outcome] : [outcome]; | ||
| const error = yield* downloadVerifyingSignature().pipe(Effect.flip); | ||
| assert.instanceOf(error, ElectronUpdater.ElectronUpdaterDownloadUpdateError); | ||
| assert.strictEqual(autoUpdaterMock.logger, logger); | ||
| } | ||
| } | ||
| } | ||
| }).pipe(Effect.provide(ElectronUpdater.layer)), | ||
| ); | ||
|
|
||
| it.effect("rejects a retry when the upstream capability probe skips verification", () => | ||
| Effect.gen(function* () { | ||
| setup(); | ||
| const logger = autoUpdaterMock.logger; | ||
| let firstCheck = true; | ||
| autoUpdaterMock.verifyUpdateCodeSignature = async () => { | ||
| if (firstCheck) { | ||
| firstCheck = false; | ||
| throw timedOut(); | ||
| } | ||
| // electron-updater resolves null after this warning despite skipping validation. | ||
| autoUpdaterMock.logger.warn( | ||
| "Cannot execute ConvertTo-Json: spawnSync powershell.exe ETIMEDOUT. Ignoring signature validation due to unsupported powershell version. Please upgrade to powershell 3 or higher.", | ||
| ); | ||
| return null; | ||
| }; | ||
|
|
||
| const error = yield* downloadVerifyingSignature().pipe(Effect.flip); | ||
| assert.instanceOf(error, ElectronUpdater.ElectronUpdaterDownloadUpdateError); | ||
| assert.instanceOf(error.cause, Error); | ||
| assert.include(error.cause.message, "Signature validation was skipped"); | ||
| assert.strictEqual(autoUpdaterMock.logger, logger); | ||
| }).pipe(Effect.provide(ElectronUpdater.layer)), | ||
| ); | ||
|
|
||
| it.effect("downloads without a Windows signature hook", () => | ||
| Effect.gen(function* () { | ||
| setup(); | ||
| assert.isUndefined(yield* downloadVerifyingSignature()); | ||
| }).pipe(Effect.provide(ElectronUpdater.layer)), | ||
| ); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔒 Security & Privacy | 🛡️ Detected with Advanced Tier | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🌐 Web query:
electron-updater windowsExecutableCodeSignatureVerifier handleError "Ignoring signature validation" resolve(null)💡 Result:
🏁 Script executed:
Repository: pingdotgg/t3code
Length of output: 20026
🌐 Web query:
electron-builder electron-updater v6.8.1 windowsExecutableCodeSignatureVerifier.ts "Ignoring signature validation"💡 Result:
🏁 Script executed:
Repository: pingdotgg/t3code
Length of output: 20026
🏁 Script executed:
Repository: pingdotgg/t3code
Length of output: 13705
🏁 Script executed:
Repository: pingdotgg/t3code
Length of output: 6003
Reachability: External
Exploitability: Difficult
CWE: CWE-347
The first signature check can still skip validation and pass the update.
The wrapper calls
verifybefore installing the logger proxy. electron-updater 6.8.9 callshandleErrorand then resolvesnullwhen the capability probe fails. NSIS treatsnullas a successful signature check, so the first call can accept an unverified update.🛡️ Proposed fix: check for skipped validation on both calls
📝 Committable suggestion
🤖 Prompt for AI Agents