Skip to content

Scan Windows desktop bundles with Defender before publishing - #7813

Merged
danielhanchen merged 5 commits into
mainfrom
desktop-defender-release-gate
Aug 4, 2026
Merged

danielhanchen merged 5 commits into
mainfrom
desktop-defender-release-gate

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Why

0.1.512-beta shipped and users hit Trojan:Win32/Wacatac.B!ml, alert level Severe, on first download. It took two days of forensics to establish that the build was fine. Nothing in the release process had looked at the bundles it was publishing, so there was no evidence either way at the moment it mattered.

That investigation is worth summarising, because it is also the argument for this change:

  • Both 0.1.51-beta and 0.1.512-beta are validly Authenticode-signed by the same Azure Trusted Signing identity. Signature status is identical per inner PE.
  • The NSIS payload inventory is identical file-for-file; four files differ in size.
  • On a windows-latest runner with Defender fully restored (real-time protection, behaviour monitoring, IOAV, cloud/MAPS on, fresh signatures, mark-of-the-web stamped) and an EICAR positive control passing: both installers, all 22 unpacked components, and all seven historical install.ps1 versions across the window scan clean. The flagged installer silent-installs and launches with zero Defender events.

So the detection was a cloud machine-learning false positive on a brand-new, zero-prevalence file hash, not a code change. No commit needs reverting.

What is worth fixing is that we could not answer the question from the release itself.

What this does

Adds one step to the Windows leg of release-desktop.yml, after the signed build and before staging: scan every produced bundle with Defender and refuse to publish if it flags one.

Three details it would be easy to get wrong, and which the step handles explicitly:

  • The runner image disables Defender. actions/runner-images sets DisableRealtimeMonitoring, MAPSReporting = 0, and ExclusionPath = @("D:\", "C:\") at image build time. A scan that does not undo this reports clean unconditionally.
  • Cloud protection is not optional. The !ml suffix means the verdict comes from a cloud classifier. With MAPS off, the exact class of detection this step exists to catch cannot fire.
  • Exit codes are ambiguous. Per the MpCmdRun reference, 0 covers both "clean" and "found and remediated", and 2 covers "found", "needs user action" and "scan failed". The step reads the output text instead.

It also stamps mark-of-the-web on each bundle before scanning, because block-at-first-sight only consults the cloud for internet-zone files, and runs an EICAR positive control so that "clean" and "the scanner is not working" are distinguishable. If the environment comes back degraded it warns rather than failing the release on a fiction.

Verified

The step's run: block was copied verbatim into a staging repo and driven both ways on windows-latest:

  • the two real installers, including the one flagged in the wild: passes
  • a known-bad file: fails the gate

Both assertions green. A gate that cannot fail is not a gate, and the blanket exclusions above make that a live risk rather than a theoretical one.

Not included

No revert of any commit in the window. #7692, #7744, #7705 and #7608 were each measured directly and are all exonerated.

One piece of optional hardening I deliberately left out: bundle.windows.webviewInstallMode.type is Tauri's default downloadBootstrapper, which makes the installer download an EXE and ExecWait it. That is the strongest dropper-shaped feature in the NSIS template, but it is present in both builds and no measurement here shows it changes a verdict, so it would be a speculative change and is better argued separately.

The self-test found a bug in this PR

Worth recording, since it is the reason the test exists. The first run passed the clean-bundle case having scanned nothing: artifactPaths failed to parse, the step warned, and exited 0. A release would have gone out unscanned with a green check next to it.

Fixed in the second commit: an empty, unparseable, or non-existent bundle list is now fatal. The self-test grew two cases to cover it, and all four now assert correctly:

negative (real bundles)  got=success  want=success  OK
positive (known-bad)     got=failure  want=failure  OK
unparseable paths        got=failure  want=failure  OK
empty paths              got=failure  want=failure  OK

with the clean case demonstrably scanning for real:

scanning 2 Windows bundle(s)
clean: old_0.1.51.exe
clean: new_0.1.512.exe
All 2 Windows bundle(s) scanned clean.

@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: e84596fff7

ℹ️ 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 thread .github/workflows/release-desktop.yml Outdated
Comment on lines +943 to +944
} else {
Write-Host "clean: $(Split-Path $f -Leaf)"

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 closed when Defender cannot complete a scan

When MpCmdRun returns an error for an existing bundle—for example because the engine is unavailable or the file cannot be scanned—its output will not match found\s+\d+\s+threat, so this branch labels the artifact clean and allows it to be published. The workflow's preceding comment acknowledges that exit code 2 can mean a scan error, consistent with the Microsoft Defender command-line reference, but the code never captures $LASTEXITCODE or verifies a positive successful-scan result. Reject scan errors or any indeterminate output instead of treating every non-detection string as clean.

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.

Right, fixed. The step now captures $LASTEXITCODE and treats anything other than 0 without a found N threat line as unscanned, which fails the release. Only 0 is documented as clean, and 2 covers scanning errors as well as detections.

Related change in the same commit: the loop now scans copies under $RUNNER_TEMP rather than the release artifacts themselves. Real-time protection is live by that point, so a block-at-first-sight hit could quarantine the file the release needs.

0.1.512-beta shipped and users hit Trojan:Win32/Wacatac.B!ml on first download.
The build was clean, but nothing in the release process looked at it, so there
was no evidence either way for two days.

Scan every signed Windows bundle on the runner that built it and refuse to
publish on a detection. The runner image disables Defender and excludes both
drive roots, so restore it first and verify the restore took; enable cloud
protection, since !ml verdicts come from a cloud classifier; stamp
mark-of-the-web, since block-at-first-sight only consults the cloud for
internet-zone files; and run an EICAR positive control so a clean result is
distinguishable from a broken scanner.

Also emit a Microsoft submission packet. There is no submission API, so
pre-submitting a build before announcing it is manual; putting the hashes,
size, signature status and signer in the job summary makes it quick.

@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: 8797860b51

ℹ️ 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 thread .github/workflows/release-desktop.yml Outdated
Comment on lines +862 to +864
if (-not $status.RealTimeProtectionEnabled) { $degraded += "RealTimeProtectionEnabled=false (AMRunningMode=$($status.AMRunningMode))" }
if ([int]$pref.MAPSReporting -ne 2) { $degraded += "MAPSReporting=$($pref.MAPSReporting), expected 2 (Advanced)" }
if ($pref.ExclusionPath) { $degraded += "exclusions remain: $($pref.ExclusionPath -join ',')" }

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 Verify every required cloud-protection preference

When Set-MpPreference is only partially ignored—for example, MAPS becomes Advanced while DisableBlockAtFirstSeen remains enabled or sample submission/cloud blocking remains disabled—these checks report a healthy configuration, and the signature-based EICAR control can still pass without exercising the cloud path needed for !ml detections. Validate the other cloud settings configured above (DisableBlockAtFirstSeen, SubmitSamplesConsent, and CloudBlockLevel) before treating bundle scans as authoritative.

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.

Fair, added. SubmitSamplesConsent, DisableBlockAtFirstSeen and CloudBlockLevel are exactly the ones the runner image sets against us (Configure-WindowsDefender.ps1 sets SubmitSamplesConsent=2 and DisableBlockAtFirstSeen=$true), and they are the settings a cloud ML verdict depends on, so a clean result without them is not worth much.

Comment thread .github/workflows/release-desktop.yml Outdated
Comment on lines +940 to +941
- name: Prepare Microsoft submission packet
if: matrix.platform == 'windows-latest'

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 Preserve flagged bundles for false-positive submission

When the scan flags a bundle and exits nonzero, GitHub Actions' implicit success() check prevents this subsequent packet step—and the later artifact upload—from running, so the signed installer disappears with the ephemeral runner. Because rebuilding and timestamp-signing produces a different hash, the instruction to submit the flagged file and rerun after hash-specific clearance cannot be followed; run recovery steps after a detection and retain the exact bundle as a restricted workflow artifact without publishing it as a release asset.

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.

Confirmed and fixed. An if: with no status function carries an implicit success(), so the detection exit was taking the only copy of the bundle with the runner. Signing is timestamped so a rebuild has a different hash, and clearance is per hash.

Scanned copies now live in $RUNNER_TEMP/defender-scan and a failure()-gated upload preserves them for 7 days. The artifact name is outside the desktop-release-* pattern that publish-release downloads, so a flagged bundle is retained but never published. The submission packet step is now gated on (success() || failure()) && steps.build_windows.outcome == 'success' so the packet is produced for the flagged build.

Comment thread .github/workflows/release-desktop.yml Outdated
Comment on lines +951 to +953
'Submit at <https://www.microsoft.com/en-us/wdsi/filesubmission> before announcing this release.',
'Choose **Software developer** -> **Incorrectly detected as malware/malicious**.',
'The 50 MB upload cap applies; if a bundle exceeds it, submit the extracted main binary instead.',

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 Do not substitute another binary for an oversized installer

When an installer exceeds the portal's stated 50 MB limit, submitting the extracted main binary cannot clear an installer-hash detection: the extracted executable has a different hash, while this same packet correctly states below that clearance applies only to the submitted hash. This advice therefore leaves the original installer detection unresolved; provide a submission route that preserves the exact flagged installer or explicitly report that this workflow cannot prepare a hash-clearing submission for oversized bundles.

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.

Agreed on the substance, reworded. Substituting a different binary cannot clear the installer hash. The packet now says to use https://security.microsoft.com/reportsubmission for anything over the WDSI 50 MB cap, which takes 500 MB and keeps the exact file.

Comment on lines +853 to +854
Update-MpSignature -UpdateSource MicrosoftUpdateServer -ErrorAction Continue
& $mp -SignatureUpdate 2>&1 | Write-Host

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 Reject stale signatures after update failures

When both signature-update commands fail because the update service or network endpoint is unavailable, their failures are ignored and the workflow proceeds using whatever definitions were baked into the runner image. The EICAR control can still pass with arbitrarily stale definitions because that long-established test signature does not demonstrate that recent definitions were installed, so newly classified threats can be reported clean; require a successful update or verify that AntivirusSignatureLastUpdated is sufficiently recent before accepting scan results.

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 signature version and last-updated timestamp are already printed at the top of the step, and everything in $degraded is a warning that never gates the release, so a freshness check would not change any outcome. The detection class this gate exists for is a cloud MAPS verdict rather than a local signature match, so local definition age is not the limiting factor.

danielhanchen and others added 2 commits August 4, 2026 06:55
…ndles

Scan copies rather than the release artifacts: real-time protection is live
by then, so a detection would delete the file the release needs. Read
MpCmdRun's exit code, since 2 covers scan errors as well as detections and
those were being reported clean. Upload the copies on failure so the exact
flagged hash survives the runner for a false-positive submission.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@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: 90f9326f47

ℹ️ 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".

foreach ($f in $paths) {
$leaf = Split-Path $f -Leaf
$copy = Join-Path $work $leaf
Copy-Item $f $copy -Force

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 Protect preservation copies from real-time quarantine

When a bundle matches a signature-based detection, real-time protection can quarantine $copy during Copy-Item, before the explicit scan's -DisableRemediation takes effect, leaving the failure handler with no exact file to upload. Fresh evidence after the earlier preservation comment is the EICAR handling above, which explicitly observes that real-time protection may remove a file as it is written; the same race applies here, while Preserve flagged Windows bundles uploads only defender-scan/* rather than the untouched artifact paths. Exclude the preservation directory while copying or otherwise retain the original bundle outside real-time remediation before scanning it.

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.

Correct, and the race is a bit wider than described: real-time protection scans on open as well as on write, so the source read can be hit too, and the mark-of-the-web write immediately after the copy is a second trigger with internet-zone context.

Fixed with an exclusion on the staging directory and on each bundle directory. That is safe precisely because of the same documented behaviour: -DisableRemediation says "File exclusions are ignored", so the explicit scan below still sees everything and there is no window in which the scan is neutered by the exclusion. The exclusion is deliberately not removed afterwards, because the copies have to survive until the failure-gated preserve step runs.

I did not switch the preserve step to the original artifact paths instead. artifactPaths is a JSON array string, not the newline-separated globs upload-artifact takes, and it would not fix anything anyway since the original can be quarantined by the copy read.

Comment thread .github/workflows/release-desktop.yml Outdated
Comment on lines +887 to +890
if (-not $controlPassed) { $degraded += 'EICAR positive control did not fire' }

if ($degraded) {
Write-Host "::warning::Defender is degraded on this runner ($($degraded -join '; ')). Scanning anyway, but a clean result below is not authoritative."

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 Abort when the Defender positive control fails

When the EICAR file remains present but the explicit scan does not recognize it—for example, because the scanner is misconfigured or returns success without applying its signatures—$controlPassed stays false, yet this branch only adds a warning and the workflow can publish bundles whose later scans return exit code 0. This is precisely the broken-scanner case the positive control is intended to distinguish from a clean result, and the warning itself concedes that the result is not authoritative; fail the release when this control fails rather than allowing staging to continue.

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.

Agreed on the hole, though the EICAR control alone does not close it. EICAR is a local signature match and fires in passive mode, where cloud-delivered protection is off; the runner image ships with MAPSReporting=0, DisableBlockAtFirstSeen=$true and real-time monitoring disabled, so a scan could pass EICAR and still be structurally incapable of producing the cloud verdict this gate exists for. That is the 0.1.512-beta regression recurring silently.

So the environment checks are now split by whether the gap invalidates the result. Fatal: real-time protection off, MAPSReporting not Advanced, block-at-first-sight disabled, EICAR not firing, and MpCmdRun -ValidateMapsConnection failing three times. Warning only: SubmitSamplesConsent, CloudBlockLevel, and leftover exclusions, the last because -DisableRemediation ignores file exclusions and so cannot produce a false clean.

Before making any of that fatal I measured it on a windows-latest runner rather than assuming. Before the restore: RealTimeProtectionEnabled False, MAPSReporting 0, SubmitSamplesConsent 2, DisableBlockAtFirstSeen True, ExclusionPath {C:\, D:\}. After: True, 2, 3, False, exclusions empty, AMRunningMode Normal, IsTamperProtected False, and ValidateMapsConnection successfully established a connection to MAPS with exit 0. The fatal set is dormant on a healthy runner, so this does not block ordinary releases.

…hield the scan copies

Real-time protection acts on open and on write, and -DisableRemediation
governs only the explicit scan, so a detection could quarantine a bundle
during the copy and leave nothing to submit. Exclude both ends of the copy;
the verdict is unaffected because -DisableRemediation ignores exclusions.

Split the environment checks by whether the gap invalidates the result.
Without active mode, MAPS and block-at-first-sight there is no cloud path,
so a clean scan cannot see the detection class this gate exists for. Those
now fail the release instead of warning, as does a failed EICAR control and
an unreachable cloud service. Measured on windows-latest first: the restore
takes and all three land in the required state.

@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: a821b51076

ℹ️ 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 thread .github/workflows/release-desktop.yml Outdated
# ends of the copy. The verdict is unaffected: -DisableRemediation
# ignores file exclusions. Left in place, since the copies must survive
# until the failure-gated preserve step runs.
Add-MpPreference -ExclusionPath (@($work) + @($paths | Split-Path -Parent | Sort-Object -Unique)) -ErrorAction Continue

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 if preservation exclusions cannot be applied

When Defender policy or tamper protection rejects this exclusion change, -ErrorAction Continue only reports the error and execution proceeds, as documented for PowerShell's Continue behavior. The subsequent Copy-Item can therefore have a genuinely flagged bundle quarantined while writing $copy, leaving defender-scan empty for the preservation step. Fresh evidence since the earlier preservation finding is that this newly added command neither stops on failure nor verifies the resulting ExclusionPath; fail before copying or confirm that both exclusions actually took effect.

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.

Fair, fixed. The exclusion list is now read back and compared, and a rejected entry fails the step before any copying.

I checked the semantics on a windows-latest runner rather than guessing at them. Add-MpPreference -ExclusionPath stores paths verbatim, so the round trip matches exactly:

passed:  D:\a\_temp\defender-scan | D:\a\x\y\nsis
stored:  D:\a\_temp\defender-scan | D:\a\x\y\nsis

I compared through Get-MpPreference rather than MpCmdRun -CheckExclusion, which looked like the more natural tool but is not usable as a gate here: it returns exit 2 both for a path that is not excluded and for one that does not exist.

D:\a\_temp\defender-scan [...] is excluded. Exit code is 0.
[Failed][0x80070003] The system cannot find the path specified.   -> exit 2

The comparison normalises trailing backslash and case anyway, and I unit tested the three branches (all applied with trailing slash and case drift, one rejected, none applied) so a partial rejection is caught rather than averaged away.

On severity: this is fatal rather than a warning to stay consistent with the rest of the step, which already refuses to publish whenever Defender is not in the asserted state. Worth noting the blast radius is narrower than it looks though, since if the exclusion silently failed the copy would be quarantined, the scan would return nonzero, the run would land in $unscanned and the release would still fail closed. What was actually at risk was the preserved submission artifact, which is the one thing that cannot be regenerated because signing is timestamped.

-ErrorAction Continue reports a rejected exclusion and carries on, so a
policy-managed or tamper-protected Defender would leave the copy exposed and
the preservation step with nothing to upload. Read the list back instead.

Measured on windows-latest: Add-MpPreference stores paths verbatim and the
round trip matches, so this is dormant on a healthy runner. Compared through
Get-MpPreference rather than MpCmdRun -CheckExclusion, which returns the same
exit 2 for a path that is not excluded and one that does not exist.
@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: 40f8b82b8a

ℹ️ 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 a44f03c into main Aug 4, 2026
6 checks passed
@danielhanchen
danielhanchen deleted the desktop-defender-release-gate branch August 4, 2026 08:47
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