Skip to content

Sign the NSIS plugin DLLs, and fail the release on any unsigned file - #7819

Merged
danielhanchen merged 9 commits into
mainfrom
desktop-sign-nsis-plugins
Aug 4, 2026
Merged

danielhanchen merged 9 commits into
mainfrom
desktop-sign-nsis-plugins

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Aug 4, 2026 •

Copy link
Copy Markdown
Member

What is wrong

Both 0.1.51-beta and 0.1.512-beta ship four unsigned DLLs inside the installer:

file 0.1.51-beta 0.1.512-beta
nsis_tauri_utils.dll signed, Unsloth AI Inc. signed, Unsloth AI Inc.
NSISdl.dll unsigned unsigned
System.dll unsigned unsigned
StartMenu.dll unsigned unsigned
nsDialogs.dll unsigned unsigned

NSIS extracts these to $PLUGINSDIR at install time and runs them from there. An unsigned DLL appearing in a temp directory and being loaded by an installer is a well known false positive trigger, and it is the exact shape reported in tauri-apps/tauri#11673, where signing the plugins stopped Defender blocking, and in tauri-apps/nsis-tauri-utils#37.

Why it happens

This is not a misconfiguration on our side. tauri-bundler already does the work and then discards it.

In crates/tauri-bundler/src/bundle/windows/nsis/mod.rs, when a signing identity is configured the bundler:

  1. copies Plugins/x86-unicode aside so it does not modify the system install,
  2. signs all five files listed in NSIS_PLUGIN_FILES, which is exactly NSISdl.dll, StartMenu.dll, System.dll, nsDialogs.dll and additional/nsis_tauri_utils.dll,
  3. exports the copy's path to makensis as the NSISPLUGINS environment variable.

Nothing consumes it. No NSIS template, upstream or ours, references $%NSISPLUGINS%. The only plugin directory added is ADDITIONALPLUGINSPATH, and that points at the copy's additional subdirectory, which contains exactly one file. So nsis_tauri_utils.dll resolves from the signed copy and the other four fall back to the default, unsigned plugin directory.

That predicts precisely the signed and unsigned split measured in both shipped bundles.

The fix

Three lines in our template, guarded because NSISPLUGINS is only set when signing is configured:

!if "$%NSISPLUGINS%" != ""
  !addplugindir "$%NSISPLUGINS%\x86-unicode"
!endif

Plus assert-bundle-signed.ps1, wired into the Windows release leg: it unpacks each bundle and fails listing every unsigned executable rather than stopping at the first, so one run gives the whole list.

Verified

Tested on windows-latest with a minimal NSIS script and a self signed certificate, which isolates the variable properly, no Rust and no frontend:

case expectation result
NSISPLUGINS set, with this fix embedded plugins come from the signed copy System.dll and nsDialogs.dll embed with signer='CN=NSIS Plugin Signing Test'
NSISPLUGINS unset still compiles, unsigned builds unaffected compiles clean, System.dll -> status=NotSigned

The second case matters: without the guard this would break every local and unsigned build.

A full end to end run is also in flight on a real Tauri build with all of this applied, checking the four DLLs come out signed and the bundle still installs and launches. I will follow up with the result.

Notes

This is worth reporting upstream as well. Any Tauri app that signs its Windows installer currently ships four unsigned plugin DLLs, and the signing work is already being done and thrown away.

Stacked on #7813 because both touch release-desktop.yml. Merge that first.

Update: the bundled install script is now signed too

Same problem, different file. install.ps1 ships as a Tauri bundle.resources entry, lands on disk at install, and is the first thing the app executes on first run, but the bundler never signs resources and the gate only looked at PE extensions. So the release could pass a gate named "no unsigned file ships" while shipping exactly that.

Two halves, and they have to land together or the gate fails the release:

  • a step that signs install.ps1 with the existing sign-with-trusted-signing.ps1 before the bundler packs it, asserting the result is Valid
  • .ps1 and .psm1 added to the checked extension set

Checked on a windows-latest runner rather than assumed: signtool signs a .ps1 (exit 0, Successfully signed, signer subject readable via Get-AuthenticodeSignature), and trusted-signing-cli lists ps1 among its supported types and does not filter by extension by default.

The signature is an appended comment block and is applied in CI only, so the repo copy served for irm https://unsloth.ai/install.ps1 | iex is untouched and its behaviour is unchanged.

install.sh stays out of the checked set: Authenticode does not cover shell scripts, so requiring it would be a false failure.

@danielhanchen

Copy link
Copy Markdown
Member Author

Marking this draft for the moment. The end to end run on a real bundler build caught a placement bug in the first version of this patch:

Plugin command System::Call conflicts with a plugin in another directory!
Error in macro __NSD_FreeImage on macroline 2
Error in macro MUI_FUNCTION_WELCOMEPAGE on macroline 50

With !addplugindir sitting next to the existing ADDITIONALPLUGINSPATH line, which is below the includes, the MUI macros resolve System:: against both the signed copy and the default plugin directory at insertion time and makensis aborts. The isolated NSIS test did not catch it because there the directive was already above the includes.

Moving it above the !include block fixes it, which is also where upstream emits its own equivalent. Rebuilding now and I will push the corrected patch once the full build, sign, unpack and launch run is green.

@danielhanchen
danielhanchen marked this pull request as draft August 4, 2026 06:24

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 24bc282ccd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +50 to +52
if (-not $inner) {
Write-Host "::warning::no executable payload found inside $name"
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Fail when no payload executables are extracted

When extraction produces no recognized inner executables—for example, because 7-Zip's NSIS handling changes or extraction yields only metadata—this branch emits a warning and the script later exits successfully after validating only the outer installer. That makes the release gate claim every bundled executable is signed without inspecting any payload, including the plugin DLLs this change is intended to protect; treat an empty $inner result as a fatal verification failure.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, and it is reachable rather than theoretical. Forcing 7-Zip onto its PE handler (-tPE) against the same installer exits 0 and yields .text .rdata .data .ndata CERTIFICATE version.txt plus numbered resources, none of which match the executable extensions, so the gate printed a warning and exited 0 having checked only the outer file. 7-Zip already reports SubType = NSIS-3 Unicode BadCmd=13 on this bundle, so its NSIS parser is partly out of step with what tauri emits. An empty payload list is now a hard failure.

Comment on lines +42 to +45
& $SevenZip x -y "-o$dest" $bundle | Out-Null
if (-not (Test-Path $dest)) {
Write-Host "::error::could not unpack $name; cannot verify its contents"
exit 1

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Reject partial 7-Zip extraction failures

When 7-Zip extracts only part of an installer and returns a warning or fatal exit code, this invocation ignores $LASTEXITCODE and tests only whether the destination directory was created. If the extracted subset contains signed files while an unextracted plugin is unsigned, the gate reports success; 7-Zip documents exit code 1 for warnings and 2 for fatal errors in its exit-code table, so require a zero exit code before inspecting the output.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reproduced and fixed. Truncating the real installer to 200 KB, 500 KB, 2 MB and 20 MB all give 7-Zip exit 2 with Unexpected end of archive, and in every case the destination directory is still created with a partial tree, so Test-Path $dest passes. The intact bundle exits 0, so -ne 0 does not false-fail today.

@danielhanchen
danielhanchen force-pushed the desktop-sign-nsis-plugins branch 2 times, most recently from 9b6f9f3 to 54f8df2 Compare August 4, 2026 07:02
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: d8d8ec4df6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c43f63cd76

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

AZURE_CERTIFICATE_PROFILE_NAME: ${{ secrets.AZURE_CERTIFICATE_PROFILE_NAME }}
run: |
$script = (Resolve-Path 'install.ps1').Path
studio/src-tauri/windows/sign-with-trusted-signing.ps1 -Path $script

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep the post-signature verification reachable

Invoking this helper in the current PowerShell process prevents the rest of the step from running because sign-with-trusted-signing.ps1 executes exit on both its success and failure paths. Consequently, the $LASTEXITCODE check and Get-AuthenticodeSignature validation below this line are unreachable; if trusted-signing-cli returns 0 without producing a valid signature—the exact case the validation is intended to catch—the workflow proceeds through the expensive build and Defender scan before the later bundle gate detects it. Invoke the signer in a child process or refactor the helper to return rather than exit.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not taking this one, the premise does not hold. exit inside a script invoked from another script terminates only the invoked script and returns control to the caller, setting $LASTEXITCODE. It ends the session only at the top level of the entry script, which is how the helper is used from the bundler's signCommand (powershell -File ...).

Reproduced under the exact invocation GitHub Actions uses for shell: pwsh, which is pwsh -command ". <file>", with an inner script whose last statement is exit 7:

$ pwsh -NoProfile -command ". ./outer.ps1"
inner ran
AFTER: LASTEXITCODE=7
would error+exit 1 here
Get-AuthenticodeSignature check would run
process rc=0

Both the $LASTEXITCODE check and the Get-AuthenticodeSignature validation run, and the exit code propagates intact. Same result for the exit 0 path.

The underlying concern is a good one though, and it is already covered: trusted-signing-cli returning 0 without producing a valid signature is exactly why the step asserts $sig.Status -eq 'Valid' rather than trusting the exit code, and that assertion runs before the build rather than after it.

Base automatically changed from desktop-defender-release-gate to main August 4, 2026 08:47
danielhanchen and others added 5 commits August 4, 2026 08:49
Both 0.1.51-beta and 0.1.512-beta ship four unsigned DLLs: NSISdl.dll,
System.dll, StartMenu.dll and nsDialogs.dll. Only nsis_tauri_utils.dll carries
the Unsloth AI Inc. signature.

tauri-bundler is doing the work already. When a signing identity is configured
it copies Plugins/x86-unicode aside, signs all five files listed in
NSIS_PLUGIN_FILES, and exports the copy as the NSISPLUGINS environment
variable. Nothing consumes it: no NSIS template references $%NSISPLUGINS%, and
the only plugin directory added is ADDITIONALPLUGINSPATH, which points at the
copy's additional subdirectory and holds exactly one file. So one DLL resolves
from the signed copy and the other four fall back to the default unsigned one.

Add the directory in our template, guarded so unsigned local builds still
compile, and add a check that unpacks each bundle and fails listing every
unsigned executable rather than stopping at the first.
7-Zip leaves a partial tree behind on error and can fall back to its PE
handler, which yields sections rather than the payload. Both cases passed
the gate having verified nothing. Move !addplugindir above the includes so
the signed copy is registered before any plugin is packed.
install.ps1 ships as a bundle resource and is the first thing the app runs
after install, but the bundler never signs it and the gate did not look at
scripts. Sign it before the build packs it in, and add .ps1/.psm1 to the
checked set. Verified on a Windows runner that signtool attaches a valid
signature to a .ps1; trusted-signing-cli lists ps1 as supported and does
not filter by extension.
@danielhanchen
danielhanchen force-pushed the desktop-sign-nsis-plugins branch from 458778e to a1ca411 Compare August 4, 2026 08:50
danielhanchen and others added 3 commits August 4, 2026 08:50
Three changes, none of which alter behaviour:

install.rs no longer passes -WindowStyle Hidden -ExecutionPolicy Bypass to
powershell.exe. CREATE_NO_WINDOW already suppresses the console and the
NSIS-extracted script carries no mark-of-the-web, so RemoteSigned loads it.
That flag pair is the command line Microsoft ships as a detection test.

install.ps1 installs uv from a pinned, SHA-256 verified release archive
instead of evaluating a downloaded script in-process.

installer.nsi fills in CompanyName and InternalName, which upstream's
template leaves empty.
… probe

UV_UNMANAGED_INSTALL forces no-modify-path in astral's installer, so it must
here too, and honour UV_INSTALLER_GHE_BASE_URL / UV_INSTALLER_GITHUB_BASE_URL
so a mirrored environment still works. Every mirror serves the same asset, so
the pinned hash is unchanged; UV_DOWNLOAD_URL stays unhonoured because it
points at an arbitrary version the pin would then reject.

Record where uv actually landed. Refresh-SessionPath rebuilds PATH machine
first and drops the in-process prepend, and the recovery probe never checked
the XDG_DATA_HOME or unmanaged destinations, so a good install could still
report failure. Required by the change above, which leaves that prepend as
the only thing putting uv on PATH.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 380b5010fd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: 668c4d2600

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit 3c6343b into main Aug 4, 2026
19 of 75 checks passed
@danielhanchen
danielhanchen deleted the desktop-sign-nsis-plugins branch August 4, 2026 11:12
danielhanchen added a commit that referenced this pull request Aug 4, 2026
main #7819 replaced the in-process `Invoke-Expression (Invoke-RestMethod
astral.sh/uv/install.ps1)` with Install-UvFromRelease, which fetches a
pinned-SHA archive. This branch's offline fix was written against the call it
deleted, so the rebase kept the behaviour but stranded the tests on a stub for
a function that is no longer called.

The harness now stubs Invoke-WebRequest, Get-HostMachineArch and
Add-ToUserPath, and the escape-path assertion targets the release download's
own try/catch instead of the removed Invoke-Expression. The invariant is
unchanged and is the point of the file: the block runs under
$ErrorActionPreference = Stop, so an unreachable host must surface as a return
value rather than a script-terminating error that skips Exit-InstallFailure
and leaves the venv unrolled-back.

Verified the retarget still bites: replacing the download's try with a bare
`if ($true)` fails 3 of the 4 tests.
danielhanchen added a commit that referenced this pull request Aug 6, 2026
…#7969)

The windows-unit-tests leg added in #7943 pins powershell_script_path as a pure
function. That cannot see the regression that actually shipped: #7819's entire
install.rs diff was Bypass -> RemoteSigned, and dropping the
powershell_script_path call from spawn_script leaves every existing assertion
passing while first-run install is broken on every Windows bundle.

Lift the argument vector into powershell_launch_args so the call site itself is
testable, then run the real interpreter with those flags against a script
addressed the way Tauri addresses it (fs::canonicalize, which resource
resolution bottoms out in and which is documented to return extended-length
syntax). The test asserts it reproduced a verbatim path before using it, so it
cannot pass vacuously. A second test pins the flag set so a policy swap shows
up as a diff.

No behaviour change: the arguments spawn_script passes are byte for byte the
ones it passed before.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant