Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Scan Windows bundles with MpCmdRun when the Defender cmdlets are down (#8358)
Daniel Hane8d0d39b0881
diff --git a/.github/workflows/release-desktop.yml b/.github/workflows/release-desktop.ymlindex 6b0feb97a89..4563362f118 100644--- a/.github/workflows/release-desktop.yml+++ b/.github/workflows/release-desktop.yml@@ -1213,18 +1213,18 @@ jobs:if (-not $unavailable -and -not $status) { $unavailable += 'Get-MpComputerStatus returned nothing' }if (-not $unavailable -and -not $pref) { $unavailable += 'Get-MpPreference returned nothing' }- # Absent scanner vs. bad verdict. Everything below this point assumes a- # Defender that answers; when it does not answer at all there is no scan- # to interpret, so skip instead of failing closed. This is deliberately- # narrow: it triggers only when the cmdlets themselves fail, which is an- # unavailable engine. A Defender that IS present but misconfigured still- # fails below, and an actual detection still fails the job.- if ($unavailable) {- Write-Host "::warning::Defender is unavailable on this runner ($($unavailable -join '; ')); skipping the bundle scan. This is a missing scanner, not a clean verdict - these bundles were not scanned."- exit 0+ # Absent scanner vs. bad verdict: only a missing scanner may skip; a+ # misconfigured one or a real detection still fails. Dead cmdlets are not+ # a missing scanner - WMI and service RPC back them, MpCmdRun talks to+ # the engine directly - and conflating the two shipped three releases+ # unscanned since 2026-08-06. Let the EICAR control below decide.+ $cmdletsDown = [bool]$unavailable+ if ($cmdletsDown) {+ Write-Host "::warning::Defender cmdlets are unavailable on this runner ($($unavailable -join '; ')); configuration cannot be read or enforced. Falling back to a direct MpCmdRun scan."+ }+ if ($status) {+ Write-Host "engine $($status.AMEngineVersion), signatures $($status.AntivirusSignatureVersion) ($($status.AntivirusSignatureLastUpdated))"}-- Write-Host "engine $($status.AMEngineVersion), signatures $($status.AntivirusSignatureVersion) ($($status.AntivirusSignatureLastUpdated))"# Set-MpPreference can return cleanly and still be ignored, so verify.# Split by whether the gap invalidates the verdict: cloud-delivered@@ -1232,14 +1232,21 @@ jobs:# sight, and "!ml" is a cloud verdict, so a clean result without them# cannot see what this gate exists to catch. Leftover exclusions only# weaken it, since -DisableRemediation ignores file exclusions.+ # Guard each check on the cmdlet that read it, not a blanket flag: the+ # two fail independently (live WMI call vs. registry), so a blanket+ # guard drops a readable $pref's MAPS and block-at-first-sight checks.$fatal = @()$degraded = @()- if (-not $status.RealTimeProtectionEnabled) { $fatal += "RealTimeProtectionEnabled=false (AMRunningMode=$($status.AMRunningMode))" }- if ([int]$pref.MAPSReporting -ne 2) { $fatal += "MAPSReporting=$($pref.MAPSReporting), expected 2 (Advanced)" }- if ($pref.DisableBlockAtFirstSeen) { $fatal += 'DisableBlockAtFirstSeen=true' }- if ([int]$pref.SubmitSamplesConsent -ne 3) { $degraded += "SubmitSamplesConsent=$($pref.SubmitSamplesConsent), expected 3 (SendAllSamples)" }- if ([int]$pref.CloudBlockLevel -eq 0) { $degraded += "CloudBlockLevel=$($pref.CloudBlockLevel), expected High" }- if ($pref.ExclusionPath) { $degraded += "exclusions remain: $($pref.ExclusionPath -join ',')" }+ if ($status) {+ if (-not $status.RealTimeProtectionEnabled) { $fatal += "RealTimeProtectionEnabled=false (AMRunningMode=$($status.AMRunningMode))" }+ }+ if ($pref) {+ if ([int]$pref.MAPSReporting -ne 2) { $fatal += "MAPSReporting=$($pref.MAPSReporting), expected 2 (Advanced)" }+ if ($pref.DisableBlockAtFirstSeen) { $fatal += 'DisableBlockAtFirstSeen=true' }+ if ([int]$pref.SubmitSamplesConsent -ne 3) { $degraded += "SubmitSamplesConsent=$($pref.SubmitSamplesConsent), expected 3 (SendAllSamples)" }+ if ([int]$pref.CloudBlockLevel -eq 0) { $degraded += "CloudBlockLevel=$($pref.CloudBlockLevel), expected High" }+ if ($pref.ExclusionPath) { $degraded += "exclusions remain: $($pref.ExclusionPath -join ',')" }+ }# Configuration is not connectivity. Retried, so one network blip does# not block a release.@@ -1250,7 +1257,12 @@ jobs:Write-Host " MAPS check $try failed: $($mapsOut.Trim())"Start-Sleep -Seconds (5 * $try)}- if (-not $maps) { $fatal += 'cannot reach the Defender cloud service' }+ # Cmdlets down: losing the cloud degrades rather than blocks the release+ # outright - signature detections still fire, only "!ml" verdicts do not.+ if (-not $maps) {+ if ($cmdletsDown) { $degraded += 'cannot reach the Defender cloud service, so "!ml" cloud verdicts cannot fire' }+ else { $fatal += 'cannot reach the Defender cloud service' }+ }# Positive control: clean and broken-scanner look identical. Split into# fragments so this file is not itself a sample.@@ -1265,12 +1277,32 @@ jobs:if (Test-Path $eicarPath) {$controlOut = (& $mp -Scan -ScanType 3 -File $eicarPath -DisableRemediation 2>&1 | Out-String)$controlPassed = [bool](($controlOut -match 'found\s+\d+\s+threat') -or ($controlOut -match 'EICAR'))+ # Remediation is asynchronous: the sample can pass Test-Path and still+ # be quarantined mid-scan. Vanishing means the control fired, not a+ # missing scanner - nothing else deletes it and -DisableRemediation+ # stops this scan from doing so, so a dead engine leaves it on disk.+ if (-not $controlPassed -and -not (Test-Path $eicarPath)) {+ Write-Host 'EICAR positive control quarantined before the scan could open it; real-time protection is live.'+ $controlPassed = $true+ }Remove-Item $eicarPath -Force -ErrorAction SilentlyContinue} else {Write-Host 'EICAR positive control blocked on write; real-time protection is live.'$controlPassed = $true}- if (-not $controlPassed) { $fatal += 'EICAR positive control did not fire' }+ # The real test of whether a scanner exists, and the only one left with+ # the cmdlets down: a control that does not fire means MpCmdRun cannot+ # scan either, so skip as before rather than fail on a missing engine.+ if (-not $controlPassed) {+ if ($cmdletsDown) {+ Write-Host "::warning::Defender is unavailable on this runner ($($unavailable -join '; ')) and MpCmdRun could not fire the EICAR positive control either; skipping the bundle scan. This is a missing scanner, not a clean verdict - these bundles were not scanned."+ exit 0+ }+ $fatal += 'EICAR positive control did not fire'+ }+ if ($cmdletsDown) {+ Write-Host 'EICAR positive control fired via MpCmdRun; scanning with the cmdlets unavailable.'+ }if ($degraded) {Write-Host "::warning::Defender is not fully configured on this runner ($($degraded -join '; ')). Scanning anyway."@@ -1321,12 +1353,17 @@ jobs:# -ErrorAction Continue does not stop on a rejected exclusion, so read# it back. Defender stores these verbatim; normalise anyway.- $norm = { param($p) $p.TrimEnd('\').ToLowerInvariant() }- $applied = @(@((Get-MpPreference).ExclusionPath) | ForEach-Object { & $norm $_ })- $notApplied = @($exclude | Where-Object { $applied -notcontains (& $norm $_) })- if ($notApplied) {- Write-Host "::error::Defender refused these exclusions: $($notApplied -join ', '); a detection would quarantine the bundle mid-copy and leave nothing to submit"- exit 1+ # Keyed on the reading cmdlet, not the blanket flag: $pref can be live+ # while $status is down. With $pref unreadable there is nothing to read+ # back, and a mid-scan quarantine still fails below as unscannable.+ if ($pref) {+ $norm = { param($p) $p.TrimEnd('\').ToLowerInvariant() }+ $applied = @(@((Get-MpPreference).ExclusionPath) | ForEach-Object { & $norm $_ })+ $notApplied = @($exclude | Where-Object { $applied -notcontains (& $norm $_) })+ if ($notApplied) {+ Write-Host "::error::Defender refused these exclusions: $($notApplied -join ', '); a detection would quarantine the bundle mid-copy and leave nothing to submit"+ exit 1+ }}$detected = @()diff --git a/tests/security/test_release_desktop_integrity.py b/tests/security/test_release_desktop_integrity.pyindex 0f3932f79c0..77faed7b707 100644--- a/tests/security/test_release_desktop_integrity.py+++ b/tests/security/test_release_desktop_integrity.py@@ -462,3 +462,132 @@ def test_the_promotion_guard_fails_closed_on_a_failed_latest_lookup():assert "refusing to promote" in fallback.lower()assert "exit 1" in fallbackassert "2>/dev/null" not in guard.split("releases/latest", 1)[1].split("\n", 1)[0]+++def _guarded_bodies(script, header):+ """Return the body of every `header` block, delimited by matching braces."""+ bodies = []+ at = script.find(header)+ while at != -1:+ start = at + len(header)+ depth = 1+ for index in range(start, len(script)):+ if script[index] == "{":+ depth += 1+ elif script[index] == "}":+ depth -= 1+ if depth == 0:+ bodies.append(script[start:index])+ break+ else:+ raise AssertionError(f"unbalanced braces after {header!r}")+ at = script.find(header, start)+ assert bodies, f"{header!r} is gone"+ return bodies+++def test_dead_defender_cmdlets_do_not_skip_the_bundle_scan():+ """Dead cmdlets must not read as "no scanner"; only a dead engine may.++ The escape hatch added for a one-off runner incident became the permanent+ path: the Defender WMI provider and service RPC endpoint have been down on+ every Windows runner since 2026-08-06, so `Get-MpComputerStatus` throws and+ three releases shipped unscanned. MpCmdRun.exe answers independently of the+ cmdlets, so an unavailable cmdlet surface may only cost the configuration+ checks, never the scan itself.+ """+ scan = _step(_workflow(), "build", "Scan Windows bundles with Defender")["run"]++ # The unavailable branch records the fact and keeps going.+ unavailable = scan.split("$cmdletsDown = [bool]$unavailable", 1)+ assert len(unavailable) == 2, "the cmdlet-unavailable branch no longer sets $cmdletsDown"+ before_control = unavailable[1].split("EICAR positive control", 1)[0]+ assert (+ "exit 0" not in before_control+ ), "unavailable cmdlets still short-circuit the scan before the positive control"++ # The two cmdlets fail independently, so each probe must sit under its OWN+ # guard, not merely some guard: pooling both bodies would accept+ # $pref.MAPSReporting under `if ($status)`, where a dead status cmdlet again+ # discards a readable MAPSReporting=0 and scans blind to the "!ml" cloud+ # verdicts this gate exists to catch.+ guards = {+ "$status": _guarded_bodies(scan, "if ($status) {"),+ "$pref": _guarded_bodies(scan, "if ($pref) {"),+ }+ for probe in (+ "$status.RealTimeProtectionEnabled",+ "$pref.MAPSReporting",+ "$pref.DisableBlockAtFirstSeen",+ "$pref.SubmitSamplesConsent",+ "$pref.CloudBlockLevel",+ "$pref.ExclusionPath",+ ):+ owner = probe.split(".", 1)[0]+ assert any(+ probe in body for body in guards[owner]+ ), f"{probe} left the `if ({owner})` guard that proves it was read"+ for other, bodies in guards.items():+ if other != owner and any(probe in body for body in bodies):+ raise AssertionError(+ f"{probe} is gated on `if ({other})`, which fails independently "+ f"of {owner}; one dead cmdlet would discard the other cmdlet's "+ "readable result"+ )+ outside = scan+ for bodies in guards.values():+ for body in bodies:+ outside = outside.replace(body, "", 1)+ for held in ("$status.", "$pref."):+ assert held not in outside, f"a {held[:-1]} dereference sits outside its availability guard"++ config = scan.split("$fatal = @()", 1)[1].split("# Configuration is not connectivity", 1)[0]+ assert "$cmdletsDown" not in config, (+ "the configuration checks are gated on the blanket flag again; one dead "+ "cmdlet would discard the other cmdlet's readable result"+ )++ # The only remaining skip: a control that will not fire, the one signal that+ # MpCmdRun cannot scan either.+ skip = scan.split("MpCmdRun could not fire the EICAR positive control", 1)+ assert len(skip) == 2, "the missing-scanner skip no longer keys off the positive control"+ assert "exit 0" in skip[1].split("\n", 3)[1] + skip[1].split("\n", 3)[2]+ assert "not a clean verdict" in skip[0].rsplit("::warning::", 1)[1] + skip[1]++ # A detection still fails the job, cmdlets or not.+ assert "Refusing to publish a Windows bundle Defender flags" in scan+ assert "Refusing to publish bundles Defender could not scan" in scan+++def test_a_sample_quarantined_mid_scan_passes_the_positive_control():+ """A sample that vanishes during the scan is a live engine, not a missing one.++ Defender remediates asynchronously and MpCmdRun opening the sample is itself+ the trigger, so the write can succeed, `Test-Path` can see the file, and+ real-time protection can quarantine it mid-scan. MpCmdRun then reports no+ threat, `$controlPassed` stays false, and with the cmdlets down the skip branch+ exits 0, publishing every bundle unscanned on a runner whose scanner just+ proved itself. Only a sample that survives means no scanner.+ """+ scan = _step(_workflow(), "build", "Scan Windows bundles with Defender")["run"]++ body = _guarded_bodies(scan, "if (Test-Path $eicarPath) {")[0]+ _, scanned, after = body.partition("-DisableRemediation")+ assert scanned, "the positive control no longer scans the sample with MpCmdRun"+ # The re-check has to land after the scan and before this step's own cleanup,+ # or it proves nothing about who removed the file.+ recheck, cleaned, _ = after.partition("Remove-Item $eicarPath")+ assert cleaned, "the positive control no longer removes the sample afterwards"+ assert "-not (Test-Path $eicarPath)" in recheck, (+ "the positive control never re-checks the sample after the scan, so a "+ "sample quarantined mid-scan reads as a missing scanner and skips the "+ "bundle scan on a runner where Defender is demonstrably live"+ )+ assert (+ "$controlPassed = $true" in recheck+ ), "the vanished sample is noticed but still does not pass the control"+ # Only a vanished sample may pass this way. -DisableRemediation stops the scan+ # from deleting the file, so with no engine it survives and the skip applies.+ assert recheck.index("-not (Test-Path $eicarPath)") < recheck.index(+ "$controlPassed = $true"+ ), "the control passes without first confirming the sample is gone"