Skip to content

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.

Capture which antivirus product is actually blocking installs, and stop discarding the false-positive submission packets (#10986)

Daniel Han7e128c09e8f6
diff --git a/.github/ISSUE_TEMPLATE/install-blocked-windows.yml b/.github/ISSUE_TEMPLATE/install-blocked-windows.yml
new file mode 100644
index 00000000000..77362090632
--- /dev/null
+++ b/.github/ISSUE_TEMPLATE/install-blocked-windows.yml
@@ -0,0 +1,241 @@
+name: "Windows: antivirus or security software blocked the installer"
+description: The installer, updater or Studio was blocked, quarantined or deleted by security software on Windows
+title: "[Blocked] "
+# Every one of these must exist in the repository. GitHub does not error on an unknown label, it
+# silently drops it -- so a typo here costs the triage label the form exists to attach, and nothing
+# reports it. All three were created for this form; `test_the_labels_the_form_declares_are_real`
+# keeps the list and the repository in step.
+labels: [bug, windows, antivirus-false-positive]
+body:
+ - type: markdown
+ attributes:
+ value: |
+ Unsloth is not malware, and a block here is a false positive. To get it cleared we have to
+ tell the vendor **which product** flagged **which file** with **which detection name** -- per-hash
+ clearance is what vendors act on, and a report without those three cannot be submitted to anyone.
+
+ Every previous report of this (#8523, #6326, #6588, #6648, #10540, #10805) named none of them,
+ which is why none of them could be proven fixed. The fields below are marked required for that
+ reason. The last one is a script that collects them for you.
+
+ Please do not turn off your antivirus to work around this. If it is wrong, it should be
+ corrected, and that needs the evidence below.
+
+ - type: input
+ id: av-product
+ attributes:
+ label: Antivirus / security product and version
+ description: >
+ The product that blocked it, with a version if you can see one. If it was Windows Defender
+ itself, say so. "Not sure" is a valid answer only if the collection script below also fails.
+ placeholder: "Bitdefender Total Security 27.0.20"
+ validations:
+ required: true
+
+ - type: input
+ id: detection-name
+ attributes:
+ label: The detection name, exactly as displayed
+ description: >
+ Copy it character for character, including any prefix and suffix. This is the single most
+ useful field: it tells the vendor which rule fired. Examples of the shape:
+ `Gen:Variant.MSILHeracles.272113`, `Trojan:Script/Wacatac.B!ml`, `BehavesLike.PS.Suspicious.gr`,
+ `HEUR:Trojan.VBS.Agent.gen`.
+ placeholder: "Gen:Variant.MSILHeracles.272113"
+ validations:
+ required: true
+
+ - type: dropdown
+ id: stage
+ attributes:
+ label: What was blocked
+ description: These are different problems with different fixes, so please pick the closest.
+ options:
+ - The install script would not run at all (blocked while starting)
+ - The installer started, then something it downloaded or created was blocked
+ - The desktop app was blocked or would not start
+ - An update was blocked
+ - A model would not load, or the app said a file was missing
+ - Something else / not sure
+ validations:
+ required: true
+
+ - type: dropdown
+ id: entry-point
+ attributes:
+ label: How were you installing or updating
+ options:
+ - "Windows one-liner: irm https://unsloth.ai/install.ps1 | iex"
+ - Unsloth Desktop installer (the .exe)
+ - Unsloth Desktop, first run or "Get started"
+ - "unsloth studio update, or the CLI"
+ - A cloned repository (.\install.ps1)
+ - WSL
+ - Something else
+ validations:
+ required: true
+
+ - type: textarea
+ id: error-text
+ attributes:
+ label: The complete error, including the FullyQualifiedErrorId line
+ description: >
+ Paste the whole red block, not a summary. `FullyQualifiedErrorId` is the part that tells us
+ whether this was an AMSI content block, an execution-policy refusal or something else, and it
+ is usually the last line. If the failure was a dialog rather than text, leave this as "dialog
+ only" and use the screenshot field below.
+
+
+ This issue is public, and a PowerShell error usually quotes the script's location, so on a
+ cloned checkout it will contain your user name. Replace it if you would rather not publish
+ it; `C:\Users\<me>\...` tells us everything we need from that part of the path.
+ render: text
+ validations:
+ required: true
+
+ - type: textarea
+ id: screenshot
+ attributes:
+ label: A screenshot, if the failure was a dialog rather than text
+ description: >
+ Drag the image in here. Deliberately NOT a `render:` field: GitHub wraps everything in a
+ rendered textarea in a code fence, so an attachment pasted into one shows up as literal
+ markup instead of an image. That is why this is separate from the error field above rather
+ than part of it.
+ validations:
+ required: false
+
+ - type: textarea
+ id: probe
+ attributes:
+ label: Output of the collection script
+ description: |
+ Open PowerShell (no administrator rights needed) and paste the block below. It only reads:
+ registered antivirus products, the AMSI providers loaded into PowerShell, Defender's status,
+ and recent Defender events. It downloads nothing and changes nothing.
+
+ It does print file paths. Your user name and profile directory are replaced with
+ placeholders before anything is written, but a detection that happened to fire in the last
+ two hours is still listed even if it has nothing to do with Unsloth, and a path outside your
+ profile is printed as it is. **Read the output before you paste it, and delete any line you
+ would rather not publish** -- this issue is public. Removing a line we needed only costs us
+ one round trip asking for it.
+
+
+ ```powershell
+ & {
+ # Everything runs inside this block so the preference below is scoped to it. Setting
+ # $ErrorActionPreference at the prompt would change it for the rest of the session, and the
+ # field above promises this probe changes nothing.
+ $ErrorActionPreference = 'Continue'
+
+ # Replaces the two things in a Windows path that identify a person: the profile directory
+ # and the account name. Applied to every line below that can carry a path.
+ function Hide-Personal([string]$s) {
+ if (-not $s) { return $s }
+ if ($env:USERPROFILE) { $s = $s -replace ('(?i)' + [regex]::Escape($env:USERPROFILE)), '%USERPROFILE%' }
+ # Only where the account name is a whole path component or the account half of DOMAIN\user:
+ # it must be preceded by a separator and not run into more word characters. A bare
+ # substring replace corrupts the evidence this form exists to collect -- an account named
+ # "win" rewrites "Windows Defender", and one named "cat" rewrites "Wacatac".
+ if ($env:USERNAME) {
+ $s = $s -replace ('(?i)(?<=[\\/])' + [regex]::Escape($env:USERNAME) + '(?![\w-])'), '<user>'
+ }
+ return $s
+ }
+
+ "=== OS and host ==="
+ $ci = $null
+ try { $ci = Get-ComputerInfo -ErrorAction Stop } catch { "Get-ComputerInfo failed: $($_.Exception.Message)" }
+ if ($ci) { "{0} {1} build {2}.{3}" -f $ci.WindowsProductName, $ci.WindowsVersion, $ci.OsBuildNumber, $ci.WindowsUBR }
+ "PowerShell $($PSVersionTable.PSVersion) ($($PSVersionTable.PSEdition)), 64-bit process: $([Environment]::Is64BitProcess)"
+ "language mode: $($ExecutionContext.SessionState.LanguageMode)"
+ "execution policy: $(Get-ExecutionPolicy)"
+
+ "`n=== registered antivirus products ==="
+ try {
+ Get-CimInstance -Namespace root/SecurityCenter2 -ClassName AntiVirusProduct -ErrorAction Stop |
+ ForEach-Object { Hide-Personal ("{0} state=0x{1:X} {2}" -f $_.displayName, $_.productState, $_.pathToSignedProductExe) }
+ } catch { "SecurityCenter2 unavailable: $($_.Exception.Message)" }
+
+ "`n=== AMSI providers (the ones that can block a script) ==="
+ foreach ($view in @('HKLM:\SOFTWARE\Microsoft\AMSI\Providers','HKLM:\SOFTWARE\WOW6432Node\Microsoft\AMSI\Providers')) {
+ if (-not (Test-Path $view)) { continue }
+ foreach ($key in (Get-ChildItem $view -ErrorAction SilentlyContinue)) {
+ $clsid = Split-Path $key.Name -Leaf
+ $dll = $null
+ foreach ($root in @('HKLM:\SOFTWARE\Classes\CLSID','HKLM:\SOFTWARE\Classes\WOW6432Node\CLSID')) {
+ $p = Join-Path (Join-Path $root $clsid) 'InprocServer32'
+ if (Test-Path $p) {
+ $dll = (Get-ItemProperty -LiteralPath $p -ErrorAction SilentlyContinue).'(default)'
+ if ($dll) { break }
+ }
+ }
+ if (-not $dll) { "$clsid (no InprocServer32 registered)"; continue }
+ $dll = $dll.Trim('"')
+ $vi = $null
+ try { $vi = (Get-Item -LiteralPath $dll -ErrorAction Stop).VersionInfo } catch { }
+ if ($vi) { Hide-Personal "$clsid $dll company='$($vi.CompanyName)' product='$($vi.ProductName)' version=$($vi.FileVersion)" }
+ else { Hide-Personal "$clsid $dll (file not readable)" }
+ }
+ }
+
+ "`n=== Windows Defender status ==="
+ try {
+ $s = Get-MpComputerStatus -ErrorAction Stop
+ "AMRunningMode=$($s.AMRunningMode) RealTimeProtectionEnabled=$($s.RealTimeProtectionEnabled) IsTamperProtected=$($s.IsTamperProtected)"
+ "AMProductVersion=$($s.AMProductVersion) AMEngineVersion=$($s.AMEngineVersion)"
+ "signatures=$($s.AntivirusSignatureVersion) updated $($s.AntivirusSignatureLastUpdated)"
+ } catch { "Defender cmdlets unavailable: $($_.Exception.Message)" }
+
+ "`n=== Defender events in the last 2 hours ==="
+ try {
+ Get-WinEvent -FilterHashtable @{LogName='Microsoft-Windows-Windows Defender/Operational'; Id=1006,1007,1015,1116,1117,1121,1122; StartTime=(Get-Date).AddHours(-2)} -ErrorAction Stop |
+ Select-Object -First 15 |
+ ForEach-Object {
+ $lines = $_.Message -split "`r?`n"
+ $matched = @($lines | Where-Object { $_ -match '^\s*(Name|Severity|Path|Process Name|Detection Source|Action)\s*:' })
+ # Defender LOCALISES these labels, so on a non-English Windows most or all of them miss
+ # and the entry would be a timestamp and an id. Counting rather than testing for empty,
+ # because some labels coincide across languages -- German renders 'Name:' identically
+ # and 'Pfad:' for Path -- so a partial match is the common case and is worse than none:
+ # it looks like a successful extraction. An English event yields five or six.
+ if ($matched.Count -ge 2) {
+ $fields = $matched -join ' | '
+ } else {
+ $fields = '(labels are localised, full message) ' + (($lines | Where-Object { $_.Trim() }) -join ' | ')
+ }
+ if ($fields.Length -gt 600) { $fields = $fields.Substring(0, 600) + ' ...' }
+ Hide-Personal ("$($_.TimeCreated) id=$($_.Id) " + $fields)
+ }
+ } catch { "no matching events, or the log could not be read: $($_.Exception.Message)" }
+ }
+ ```
+
+
+ `AMRunningMode` matters more than it looks: anything other than `Normal` means another product
+ is the primary scanner, which on its own often answers "which product".
+ render: text
+ validations:
+ required: true
+
+ - type: input
+ id: file-path
+ attributes:
+ label: The full path of the file that was blocked or removed, if one was named
+ description: >
+ This issue is public. If the path runs through your profile, replace the user name with
+ `<me>`; what we need is which file and which directory, not who you are.
+ placeholder: 'C:\Program Files\Unsloth\install.ps1'
+ validations:
+ required: false
+
+ - type: textarea
+ id: anything-else
+ attributes:
+ label: Anything else
+ description: >
+ Whether it worked before, whether turning the product off changes it, whether a reboot changes
+ it, and anything you have already tried.
+ validations:
+ required: false
diff --git a/.github/workflows/release-desktop.yml b/.github/workflows/release-desktop.yml
index 26c3148b783..2ee647a7095 100644
--- a/.github/workflows/release-desktop.yml
+++ b/.github/workflows/release-desktop.yml
@@ -1517,6 +1517,17 @@ jobs:
# Later steps carry an implicit success(), so on a detection the flagged
# bundle would be discarded with the runner.
+ #
+ # 90 days, not 7. Clearance is per hash and a rebuild hashes differently, so these copies are
+ # the only submittable sample for this release -- and a vendor analyst round trip plus our own
+ # reaction routinely outlasts a week, at which point the evidence for the detection we are
+ # disputing is gone and the dispute has to start from a different build.
+ #
+ # The Microsoft submission packet that describes them is uploaded by its own step further
+ # down, NOT here. It cannot be added to this step's path: the packet is assembled ~60 lines
+ # below, and steps run top to bottom, so at this point the file does not exist yet. That was
+ # the first version of this change, and `if-no-files-found: ignore` would have hidden it
+ # forever -- an artefact silently missing the one document it exists to carry.
- name: Preserve flagged Windows bundles
if: failure() && matrix.platform == 'windows-latest'
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
@@ -1525,7 +1536,7 @@ jobs:
path: ${{ runner.temp }}/defender-scan/*
if-no-files-found: ignore
compression-level: 0
- retention-days: 7
+ retention-days: 90
# ── Windows: every executable in the bundle must be signed ──
# NSIS runs its plugin DLLs from $PLUGINSDIR; signing the installer misses them.
@@ -1583,6 +1594,22 @@ jobs:
$md -join "`n" | Out-File $env:GITHUB_STEP_SUMMARY -Append -Encoding utf8
Write-Host ($md -join "`n")
+ # Here, and not on the bundle-preserving step above, because the packet is written by the step
+ # immediately before this one. A job summary is ephemeral: it goes with the run, so the one
+ # document written for the purpose of disputing a detection was being discarded along with the
+ # detection it disputes. 90 days for the same reason the bundles get 90 -- clearance is per
+ # hash, and a vendor round trip outlasts a week.
+ - name: Preserve the Microsoft submission packet
+ if: always() && matrix.platform == 'windows-latest'
+ uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
+ with:
+ name: ms-submission-packet-${{ matrix.artifact }}
+ path: ${{ runner.temp }}/ms-submission-packet.md
+ # ignore, not warn: the packet is only assembled when there is something to submit, so its
+ # absence on a clean release is the normal case and must not add an annotation.
+ if-no-files-found: ignore
+ retention-days: 90
+
- name: Stage release assets
shell: bash
env:
@@ -2218,3 +2245,21 @@ jobs:
echo '' >> "$GITHUB_STEP_SUMMARY"
echo 'The scan step produced no summary.' >> "$GITHUB_STEP_SUMMARY"
fi
+
+ # The summary carries the false-positive submission packet that
+ # submission_packet_lines() builds: the flagged assets, their SHA-256s, the vendor routes and
+ # the note that clearance is per hash. A job summary is ephemeral, so the one document written
+ # for the purpose of disputing a detection was being thrown away along with the run, and the
+ # dispute then had to be reconstructed from a report nobody kept. Keeping it costs a few KB.
+ #
+ # No env and no secret here on purpose: test_post_publish_scan_job_holds_no_release_credentials
+ # asserts this job's complete secret set is VIRUS_TOTAL_API_TOKEN alone and that no step of it
+ # carries a token, so an upload step must add neither.
+ - name: Preserve the VirusTotal summary and submission packet
+ if: always()
+ uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
+ with:
+ name: virustotal-summary
+ path: ${{ runner.temp }}/virustotal-summary.md
+ if-no-files-found: warn
+ retention-days: 90
diff --git a/studio/backend/tests/test_diffusers_prewarm.py b/studio/backend/tests/test_diffusers_prewarm.py
index cb4920ebdbb..77359f29a36 100644
--- a/studio/backend/tests/test_diffusers_prewarm.py
+++ b/studio/backend/tests/test_diffusers_prewarm.py
@@ -467,7 +467,9 @@ def test_a_hooks_failure_after_a_good_parent_still_purges_the_hook_subtree(
), "the healthy parent was evicted; only the failed subtree should go"
-def test_the_parent_and_child_import_locks_are_never_held_together(warm, monkeypatch, restore_diffusers_modules):
+def test_the_parent_and_child_import_locks_are_never_held_together(
+ warm, monkeypatch, restore_diffusers_modules
+):
"""Holding both would invert CPython's own lock order and deadlock a concurrent import.
``import diffusers.hooks`` makes CPython take the CHILD lock first and import the parent from
@@ -504,12 +506,12 @@ def test_the_parent_and_child_import_locks_are_never_held_together(warm, monkeyp
assert both_held, "the prewarm imported nothing; this test would be vacuous"
offenders = [(n, p, c) for n, p, c in both_held if p and c]
- assert not offenders, (
- f"parent and child import locks held at the same time: {offenders}"
- )
+ assert not offenders, f"parent and child import locks held at the same time: {offenders}"
-def test_a_concurrent_submodule_import_does_not_deadlock_the_prewarm(warm, monkeypatch, restore_diffusers_modules):
+def test_a_concurrent_submodule_import_does_not_deadlock_the_prewarm(
+ warm, monkeypatch, restore_diffusers_modules
+):
"""The failure mode from the other side, with two real threads and the real locks.
One thread takes the hooks lock and then reaches for the parent, which is the order CPython
@@ -559,7 +561,9 @@ def test_a_concurrent_submodule_import_does_not_deadlock_the_prewarm(warm, monke
p.join(5)
-def test_the_lock_is_never_released_between_a_failed_import_and_its_purge(warm, monkeypatch, restore_diffusers_modules):
+def test_the_lock_is_never_released_between_a_failed_import_and_its_purge(
+ warm, monkeypatch, restore_diffusers_modules
+):
"""Held CONTINUOUSLY, not merely held again by the time the purge runs.
Writing the try around the ``with`` instead of inside it releases the lock when the scope
@@ -598,7 +602,12 @@ def test_the_lock_is_never_released_between_a_failed_import_and_its_purge(warm,
monkeypatch.setattr(warm, "purge_partial_import", _recording_purge)
class _Boom:
- def find_spec(self, name, path = None, target = None):
+ def find_spec(
+ self,
+ name,
+ path = None,
+ target = None,
+ ):
if name == "diffusers":
raise ImportError("simulated half-built diffusers")
return None
@@ -608,18 +617,17 @@ def test_the_lock_is_never_released_between_a_failed_import_and_its_purge(warm,
assert warm.prewarm_diffusers_if_image_models_exist() is False
purge_at = next(
- i for i, (what, name) in enumerate(timeline)
- if what == "purge" and name == "diffusers"
+ i for i, (what, name) in enumerate(timeline) if what == "purge" and name == "diffusers"
)
# Everything before the purge, from the first acquisition onwards, must be acquisitions:
# a matching release in there is the gap. Reentrant acquires (purge_partial_import takes the
# same lock through its own decorator) are fine and expected.
enter_at = next(
- i for i, (what, name) in enumerate(timeline)
- if what == "enter" and name == "diffusers"
+ i for i, (what, name) in enumerate(timeline) if what == "enter" and name == "diffusers"
)
released_early = [
- i for i, (what, name) in enumerate(timeline)
+ i
+ for i, (what, name) in enumerate(timeline)
if what == "exit" and name == "diffusers" and enter_at < i < purge_at
]
assert not released_early, (
diff --git a/studio/backend/utils/torch_warmup.py b/studio/backend/utils/torch_warmup.py
index 66c94491ead..f3bf090faed 100644
--- a/studio/backend/utils/torch_warmup.py
+++ b/studio/backend/utils/torch_warmup.py
@@ -672,7 +672,6 @@ def prewarm_diffusers_if_image_models_exist() -> bool:
# work this exists to do, and the load path calls the same idempotent helper anyway.
try:
from loggers.config import quiet_third_party_progress_bars # noqa: PLC0415
-
quiet_third_party_progress_bars()
except Exception as exc: # noqa: BLE001 -- cosmetic only
logger.debug("quieting third-party progress bars failed: %r", exc)
diff --git a/tests/python/test_amd_extras_contract.py b/tests/python/test_amd_extras_contract.py
index c0dd0c875e8..7108b3a1065 100644
--- a/tests/python/test_amd_extras_contract.py
+++ b/tests/python/test_amd_extras_contract.py
@@ -49,8 +49,13 @@ def _extras_referenced_by_the_audit_workflow() -> set[str]:
for node in ast.walk(ast.parse(block)):
if _is_optional_dependencies_lookup(node) and isinstance(node.slice, ast.Constant):
names.add(node.slice.value)
- elif (isinstance(node, ast.Call) and isinstance(node.func, ast.Name)
- and node.func.id == "extra" and node.args and isinstance(node.args[0], ast.Constant)):
+ elif (
+ isinstance(node, ast.Call)
+ and isinstance(node.func, ast.Name)
+ and node.func.id == "extra"
+ and node.args
+ and isinstance(node.args[0], ast.Constant)
+ ):
names.add(node.args[0].value)
for listed in re.findall(r"^\s*for extra in ([^;]+); do\s*$", source, re.MULTILINE):
names |= {word for word in listed.split() if word}
@@ -85,7 +90,9 @@ def _inline_python_blocks() -> list[str]:
"""Every `python ... <<PY` or `<<'PY'` heredoc in security-audit.yml, dedented."""
source = SECURITY_AUDIT.read_text(encoding = "utf-8")
blocks = re.findall(
- r"^[ \t]*python[^\n]*<<'?PY'?[^\n]*\n(.*?)^[ \t]*PY[ \t]*$", source, re.MULTILINE | re.DOTALL
+ r"^[ \t]*python[^\n]*<<'?PY'?[^\n]*\n(.*?)^[ \t]*PY[ \t]*$",
+ source,
+ re.MULTILINE | re.DOTALL,
)
assert blocks, "expected security-audit.yml to embed python heredocs"
return [textwrap.dedent(b) for b in blocks]
@@ -128,8 +135,12 @@ class TestAmdBitsandbytesFloor:
requirement = spec.split(";", 1)[0].strip()
allowed = SpecifierSet(requirement[len("bitsandbytes") :].strip())
# The whole broken range, not one release: `>=0.49.3` or `!=0.49.2` must fail too.
- floors = [Version(sp.version) for sp in allowed if sp.operator in (">=", ">", "==", "~=")]
- assert floors and min(floors) >= BNB_MIN, f"{requirement} has no lower bound at or above {BNB_MIN}"
+ floors = [
+ Version(sp.version) for sp in allowed if sp.operator in (">=", ">", "==", "~=")
+ ]
+ assert (
+ floors and min(floors) >= BNB_MIN
+ ), f"{requirement} has no lower bound at or above {BNB_MIN}"
for old in ("0.45.0", "0.49.2", "0.49.3", "0.49.99"):
assert not allowed.contains(Version(old)), f"{requirement} still admits bnb {old}"
assert allowed.contains(BNB_MIN), f"{requirement} excludes the fixed release {BNB_MIN}"
@@ -176,7 +187,9 @@ class TestSecurityAuditWorkflowStaysInSync:
# Guarded means inside the try BODY (not else/finally) of a try whose handler catches KeyError.
guarded, child, parent = False, node, getattr(node, "parent", None)
while parent is not None:
- if isinstance(parent, ast.Try) and any(_contains_node(stmt, child) for stmt in parent.body):
+ if isinstance(parent, ast.Try) and any(
+ _contains_node(stmt, child) for stmt in parent.body
+ ):
if any(_catches_key_error(h) for h in parent.handlers):
guarded = True
break
diff --git a/tests/python/test_virustotal_scan.py b/tests/python/test_virustotal_scan.py
index 200f1e3d812..b365b4e851c 100644
--- a/tests/python/test_virustotal_scan.py
+++ b/tests/python/test_virustotal_scan.py
@@ -951,12 +951,25 @@ class TestWorkflowOrdering:
"after one, and `needs:` already gates it correctly"
)
- # Nor may the individual steps be skipped, except the summary, which is `if: always()` precisely so the evidence
- # survives a failed scan.
+ # Nor may the individual steps be skipped, with one narrow exception: the steps whose whole purpose is to keep
+ # the evidence, which are `if: always()` precisely so it survives a failed scan. Named individually rather than
+ # allowed by shape, so a future step cannot inherit the exception by looking similar.
+ #
+ # Both are evidence, not measurement. The summary carries the false-positive submission packet
+ # submission_packet_lines() builds, and the upload keeps it past the run: a job summary is ephemeral, so
+ # without it the one document written for the purpose of disputing a detection is discarded along with the
+ # detection it describes. Skipping either on a failed scan loses exactly the run worth keeping.
+ evidence_steps = {
+ "Publish VirusTotal summary",
+ "Preserve the VirusTotal summary and submission packet",
+ }
for step in job["steps"]:
condition = step.get("if")
- if step.get("name") == "Publish VirusTotal summary":
- assert condition == "always()"
+ if step.get("name") in evidence_steps:
+ assert condition == "always()", (
+ f"{step.get('name')!r} must be `if: always()`: it exists to keep the evidence, and a "
+ f"failed scan is the run whose evidence matters most"
+ )
else:
assert condition is None, step.get("name")
diff --git a/tests/security/test_windows_blocked_issue_form.py b/tests/security/test_windows_blocked_issue_form.py
new file mode 100644
index 00000000000..c7b8cfa9fdf
--- /dev/null
+++ b/tests/security/test_windows_blocked_issue_form.py
@@ -0,0 +1,480 @@
+# SPDX-License-Identifier: AGPL-3.0-only
+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+"""The Windows-blocked issue form has to keep asking for the three fields a vendor needs.
+
+#8523, #6326, #6588, #6648, #10540 and #10805 all reported a security product blocking Unsloth and
+named no product, no detection name and no AMSI provider, so not one of them could be submitted to a
+vendor or proven fixed. The form exists to make those fields required; if a later edit relaxes them,
+or breaks the collection script that produces them, we are back to unactionable reports and nothing
+would otherwise fail.
+
+The collection script is checked by parsing it. A diagnostic that does not run is worse than none: it
+costs the user a round trip and produces an error message about our form instead of about their
+antivirus. That is not hypothetical here -- the first version of this form put the script in a YAML
+folded scalar (`>`), which joins the lines and silently destroyed every newline in it.
+"""
+
+from __future__ import annotations
+
+import re
+import shutil
+from pathlib import Path
+
+import pytest
+import yaml
+
+# The shared runner, not a direct subprocess call: a direct one shares a single
+# $XDG_CACHE_HOME/powershell startup cache with every other xdist worker, and an interpreter that
+# dies at startup then renders as this test failing rather than as the crash it was.
+# tests/studio/test_pwsh_calls_use_the_shared_runner.py enforces this.
+from unsloth_pwsh_runner import run_pwsh
+
+
+REPO = Path(__file__).resolve().parents[2]
+FORM = REPO / ".github" / "ISSUE_TEMPLATE" / "install-blocked-windows.yml"
+
+# The three things a false-positive submission cannot be made without, plus the error id that says
+# which mechanism blocked it.
+REQUIRED_FIELD_IDS = ("av-product", "detection-name", "error-text", "probe")
+
+
+def _form() -> dict:
+ return yaml.safe_load(FORM.read_text(encoding = "utf-8"))
+
+
+def _fields() -> dict:
+ return {item["id"]: item for item in _form()["body"] if isinstance(item, dict) and "id" in item}
+
+
+def _snippet() -> str:
+ """The PowerShell the form asks the reporter to run."""
+ for item in _form()["body"]:
+ description = (item.get("attributes") or {}).get("description") or ""
+ match = re.search(r"```powershell\n(.*?)```", description, re.S)
+ if match:
+ return match.group(1)
+ raise AssertionError(
+ "the form contains no ```powershell block with newlines in it. The overwhelmingly likely "
+ "cause is that its `description:` uses a YAML folded scalar (`>`) instead of a literal one "
+ "(`|`): folding joins every line, so the fence and the code end up on one line and the "
+ "script the reporter pastes is unusable. That exact mistake shipped in the first draft."
+ )
+
+
+def test_the_form_exists_and_is_valid_yaml() -> None:
+ assert FORM.is_file(), f"missing {FORM.relative_to(REPO)}"
+ form = _form()
+ assert form.get("name"), "an issue form needs a name or GitHub will not offer it"
+ assert isinstance(form.get("body"), list) and form["body"], "the form has no body"
+
+
[email protected]("field_id", REQUIRED_FIELD_IDS)
+def test_the_fields_a_vendor_needs_stay_required(field_id: str) -> None:
+ fields = _fields()
+ assert field_id in fields, (
+ f"the form no longer has a {field_id!r} field. Every report of this class before the form "
+ f"existed named no product and no detection name, and none of them could be submitted."
+ )
+ validations = fields[field_id].get("validations") or {}
+ assert validations.get("required") is True, (
+ f"{field_id!r} is no longer required. A markdown template could not enforce this, which is "
+ f"why this is a form; making the field optional gives that up for nothing."
+ )
+
+
+def test_the_collection_script_survived_the_yaml() -> None:
+ """A folded scalar joins lines and would ship a one-line, unusable script."""
+ snippet = _snippet()
+ assert snippet.count("\n") > 20, (
+ "the collection script has collapsed to almost nothing. Its `description` must use a "
+ "literal block scalar (`|`), not a folded one (`>`): folding joins the lines and destroys "
+ "every newline in the code block."
+ )
+ # Each section the triage actually reads. Losing one silently narrows what a report can answer.
+ for marker in (
+ "SecurityCenter2",
+ "AMSI\\Providers",
+ "InprocServer32",
+ "Get-MpComputerStatus",
+ "AMRunningMode",
+ ):
+ assert marker in snippet, f"the collection script no longer gathers {marker}"
+
+
+def test_the_collection_script_parses() -> None:
+ """Parsed, not eyeballed. It is pasted verbatim by people who are already stuck."""
+ pwsh = shutil.which("pwsh")
+ if pwsh is None:
+ pytest.skip("pwsh is unavailable")
+
+ snippet = _snippet()
+ probe = (
+ "$ErrorActionPreference = 'Stop'; $errors = $null; $tokens = $null; "
+ "$null = [System.Management.Automation.Language.Parser]::ParseInput("
+ "[System.IO.File]::ReadAllText($env:UNSLOTH_SNIPPET_PATH), [ref]$tokens, [ref]$errors); "
+ "if ($errors.Count) { $errors | ForEach-Object { $_.Message }; exit 1 }; "
+ 'Write-Output "OK $($tokens.Count)"'
+ )
+ # Through a file and an environment variable, so nothing about the snippet's own quoting can
+ # change how it is handed to the parser.
+ import tempfile
+
+ with tempfile.TemporaryDirectory() as tmp:
+ path = Path(tmp) / "snippet.ps1"
+ path.write_text(snippet, encoding = "utf-8")
+ result = run_pwsh(
+ [pwsh, "-NoProfile", "-NonInteractive", "-Command", probe],
+ capture_output = True,
+ text = True,
+ timeout = 120,
+ env = {**__import__("os").environ, "UNSLOTH_SNIPPET_PATH": str(path)},
+ )
+
+ assert (
+ result.returncode == 0
+ ), f"the collection script in {FORM.name} does not parse:\n{result.stdout}\n{result.stderr}"
+
+
+def test_the_collection_script_only_reads() -> None:
+ """It runs on a stranger's machine while they are already having a bad day.
+
+ No downloads, no execution of anything fetched, and nothing that writes. It also must not carry
+ the shapes the installers are being cleaned of, or the diagnostic gets blocked by the same
+ product that blocked the installer.
+ """
+ snippet = _snippet()
+ for banned, why in (
+ ("Invoke-WebRequest", "a diagnostic must not download"),
+ ("Invoke-RestMethod", "a diagnostic must not download"),
+ ("Invoke-Expression", "a diagnostic must not evaluate strings"),
+ ("iex", "a diagnostic must not evaluate strings"),
+ ("Add-Type", "that compiles C# through csc.exe, which is the shape being removed"),
+ ("FromBase64String", "encode-then-run is the shape being removed"),
+ ("Set-MpPreference", "a diagnostic must never change the scanner it is reporting on"),
+ ("Add-MpPreference", "a diagnostic must never change the scanner it is reporting on"),
+ ("Remove-Item", "a diagnostic must not delete"),
+ ("Set-Content", "a diagnostic must not write"),
+ ("Start-Process", "a diagnostic must not launch anything"),
+ ):
+ assert banned not in snippet, f"the collection script uses {banned}: {why}"
+
+
+def test_the_labels_the_form_declares_are_real() -> None:
+ """GitHub drops an unknown label silently rather than erroring.
+
+ All three of these were absent when the form was first written, so every issue filed through it
+ would have arrived with `bug` only -- losing exactly the two triage labels the form exists to
+ attach, with nothing anywhere reporting the loss.
+
+ Checked against a checked-in list rather than the GitHub API, because a test that needs the
+ network is a test that gets skipped. The list is the contract: if someone adds a label here they
+ must create it on the repository too.
+ """
+ KNOWN_REPOSITORY_LABELS = {"bug", "windows", "antivirus-false-positive"}
+ declared = set(_form().get("labels") or [])
+ assert declared, "the form declares no labels, so nothing routes it to triage"
+ unknown = declared - KNOWN_REPOSITORY_LABELS
+ assert not unknown, (
+ f"the form declares {sorted(unknown)}, which are not in the known-label list. Create them "
+ f"on the repository with `gh label create` and add them here; GitHub will otherwise drop "
+ f"them without a word and the issue will arrive unlabelled."
+ )
+
+
+def test_every_line_that_can_carry_a_path_is_redacted() -> None:
+ """The form is `required: true` and the issue is public, so this output gets published.
+
+ Three of the sections print file paths, and the Defender one prints `Path` and `Process Name`
+ for every detection in the last two hours, related to Unsloth or not. On a normal machine those
+ paths start with the profile directory and therefore carry the account name, and the file name
+ itself can be anything the person happened to have open. Redaction is applied at the point of
+ printing rather than trusted to the reporter, because the reporter is someone whose install is
+ already broken and who is pasting a block they did not write.
+ """
+ snippet = _snippet()
+ assert "function Hide-Personal" in snippet, (
+ "the collection script no longer defines the redaction helper, so the profile directory and "
+ "account name reach a public issue verbatim"
+ )
+ for carrier, why in (
+ ("pathToSignedProductExe", "the antivirus product's own path"),
+ ("$clsid $dll", "the AMSI provider DLL path"),
+ ("$($_.TimeCreated)", "the Defender event path and process name"),
+ ):
+ line = next((ln for ln in snippet.splitlines() if carrier in ln), None)
+ assert line is not None, f"the collection script no longer prints {why} ({carrier})"
+ assert (
+ "Hide-Personal" in line
+ ), f"the line printing {why} is no longer redacted: {line.strip()}"
+
+
+def test_the_form_does_not_promise_more_privacy_than_it_delivers() -> None:
+ """The old wording said it touches no personal data, which was not true of the event section.
+
+ An assurance that overstates is worse than none: it is read by exactly the people least placed
+ to check it, and it discourages the one thing that does work, which is reading the output first.
+ """
+ description = _fields()["probe"]["attributes"]["description"]
+ assert "touches no personal data" not in description, (
+ "the form claims again that the collection script touches no personal data, but it prints "
+ "detection paths from the last two hours"
+ )
+ assert (
+ "Read the output before you paste it" in description
+ ), "the form no longer tells the reporter to read the output before publishing it"
+
+
+def test_the_defender_event_fields_survive_a_real_message(tmp_path: Path) -> None:
+ """Defender indents its detail lines, so an anchor on the field name matches none of them.
+
+ The rendered message for 1116 and its siblings is a header line followed by indented
+ `Field: value` lines (Microsoft's own 1117 reference lists the field set, and real 1116 output
+ shows the same). Anchoring on `^Name:` therefore matched nothing at all, and the section that
+ exists to carry the detection name, its path and the process that triggered it emitted only a
+ timestamp and an event id. That is a silent loss of the single most useful field in the report.
+
+ Driven through the snippet's own filter against a message in the documented shape, rather than
+ asserting the regex text, so a future rewrite of the extraction is judged on what it extracts.
+ """
+ pwsh = shutil.which("pwsh")
+ if pwsh is None:
+ pytest.skip("pwsh is unavailable")
+
+ snippet = _snippet()
+ match = re.search(r"\$_ -match '([^']+)'", snippet)
+ assert match, "the collection script no longer filters the Defender event message lines"
+ pattern = match.group(1)
+
+ script = tmp_path / "fields.ps1"
+ script.write_text(
+ "\n".join(
+ [
+ '$msg = @"',
+ "Windows Defender Antivirus has detected malware or other potentially unwanted software.",
+ " Name: HackTool:Win64/Mimikatz.A",
+ " ID: 2147747903",
+ " Severity: High",
+ " Path: C:\\Users\\jsmith\\AppData\\Local\\Temp\\m64.exe",
+ " Detection Source: Real-Time Protection",
+ " Process Name: C:\\Windows\\System32\\cmd.exe",
+ " Action: Allowed",
+ '"@',
+ f"$sel = (($msg -split \"`r?`n\") | Where-Object {{ $_ -match '{pattern}' }}) -join ' | '",
+ 'Write-Output "SELECTED:$sel"',
+ ]
+ ),
+ encoding = "utf-8",
+ )
+ done = run_pwsh(
+ [pwsh, "-NoProfile", "-NonInteractive", "-File", str(script)],
+ capture_output = True,
+ text = True,
+ timeout = 120,
+ )
+ selected = done.stdout
+ for field in ("Name:", "Path:", "Process Name:", "Detection Source:", "Action:"):
+ assert field in selected, (
+ f"the filter dropped {field!r} from a Defender message in the documented indented shape, "
+ f"so the report would carry a timestamp and an event id and nothing else. Selected: "
+ f"{selected.strip()!r}"
+ )
+
+
+def test_a_localised_defender_message_still_reports_its_details(tmp_path: Path) -> None:
+ """Defender localises the field labels, and a partial match is worse than none.
+
+ On a non-English Windows the English labels miss, so the entry would be a timestamp and an
+ event id. Some labels coincide across languages -- German renders `Name:` identically -- so
+ testing for an empty result is not enough: one match out of six looks like a successful
+ extraction. The fallback is therefore count-based, and prints the whole message, redacted,
+ when too few fields resolve.
+ """
+ pwsh = shutil.which("pwsh")
+ if pwsh is None:
+ pytest.skip("pwsh is unavailable")
+
+ snippet = _snippet()
+ assert "localised" in snippet, "the collection script no longer has a localisation fallback"
+
+ german = [
+ "Windows Defender Antivirus hat Malware gefunden.",
+ " Name: HackTool:Win64/Mimikatz.A",
+ " Schweregrad: Hoch",
+ " Pfad: C:\\Users\\jsmith\\AppData\\Local\\Temp\\m64.exe",
+ ]
+ match = re.search(r"\$_ -match '([^']+)'", snippet)
+ assert match
+ script = tmp_path / "loc.ps1"
+ script.write_text(
+ "\n".join(
+ ["$lines = @(" + ", ".join(f"'{line}'" for line in german) + ")"]
+ + [
+ f"$matched = @($lines | Where-Object {{ $_ -match '{match.group(1)}' }})",
+ "if ($matched.Count -ge 2) { $fields = $matched -join ' | ' }",
+ "else { $fields = '(localised) ' + (($lines | Where-Object { $_.Trim() }) -join ' | ') }",
+ 'Write-Output "OUT:$fields"',
+ ]
+ ),
+ encoding = "utf-8",
+ )
+ done = run_pwsh(
+ [pwsh, "-NoProfile", "-NonInteractive", "-File", str(script)],
+ capture_output = True,
+ text = True,
+ timeout = 120,
+ )
+ assert (
+ "Schweregrad" in done.stdout and "Pfad" in done.stdout
+ ), f"a German Defender message lost its severity and path: {done.stdout.strip()!r}"
+
+
+def test_the_screenshot_field_is_not_a_rendered_textarea() -> None:
+ """A `render:` textarea wraps everything in a code fence, attachments included.
+
+ So an image dragged into one appears as literal markup rather than as a picture. The error
+ field keeps `render: text`, because it carries pasted console output where the monospace block
+ is worth having; screenshots get their own unrendered field instead.
+ """
+ fields = _fields()
+ assert "screenshot" in fields, (
+ "there is no screenshot field, so a reporter whose failure was a dialog has nowhere to put "
+ "it except a rendered textarea, where it will not display"
+ )
+ assert "render" not in fields["screenshot"]["attributes"], (
+ "the screenshot field is rendered, so an attachment dropped into it becomes literal text "
+ "inside a code block"
+ )
+ error_description = fields["error-text"]["attributes"]["description"]
+ assert (
+ "a screenshot is fine" not in error_description
+ ), "the rendered error field still invites a screenshot it cannot display"
+
+
+def test_the_required_error_field_warns_about_its_own_paths() -> None:
+ """The probe output is not the only required field that publishes a path.
+
+ A PowerShell error quotes the script's location, so on the documented cloned-checkout entry
+ point the required error text carries the reporter's user name, and they are asked to paste it
+ verbatim before they ever reach the probe field's privacy note.
+ """
+ description = _fields()["error-text"]["attributes"]["description"]
+ assert "public" in description.lower(), (
+ "the error field does not mention that the issue is public, though it is required and "
+ "routinely contains C:\\Users\\<name>"
+ )
+
+
+def test_every_field_that_asks_for_a_path_says_the_issue_is_public() -> None:
+ """The privacy wording covered two fields and missed the one that asks for a path outright.
+
+ `error-text` and `probe` both warn that the issue is public and invite redaction, but
+ `file-path` asked for a full path with nothing but a `C:\\Users\\...` shaped placeholder to go
+ on. A reporter who follows the placeholder publishes their user name, and the protections added
+ everywhere else make that omission read as deliberate rather than missed.
+ """
+ fields = _fields()
+ for name in ("error-text", "probe", "file-path"):
+ attributes = fields[name]["attributes"]
+ text = f"{attributes.get('label', '')}\n{attributes.get('description', '')}"
+ assert (
+ "public" in text.lower()
+ ), f"the {name} field asks for a filesystem path without saying the issue is public"
+ # The probe is exempt from this second one: `Hide-Personal` substitutes the profile and user
+ # name before anything is written, so there is nothing for the reporter to rewrite by hand.
+ # These two are pasted unaided, and a warning with no worked replacement tends to be answered by
+ # dropping the field rather than by editing it.
+ for name in ("error-text", "file-path"):
+ description = fields[name]["attributes"].get("description", "")
+ assert (
+ "<me>" in description
+ ), f"the {name} field warns that the issue is public but never shows what to write instead"
+
+
+def _hide_personal_source() -> str:
+ """Just the Hide-Personal function, lifted out of the shipped snippet."""
+ snippet = _snippet()
+ start = snippet.index("function Hide-Personal")
+ depth = 0
+ for i in range(start, len(snippet)):
+ if snippet[i] == "{":
+ depth += 1
+ elif snippet[i] == "}":
+ depth -= 1
+ if depth == 0:
+ return snippet[start : i + 1]
+ raise AssertionError("Hide-Personal is not brace-balanced in the shipped snippet")
+
+
+ ("username", "line", "expected"),
+ [
+ # The two corruptions a bare substring replace causes. Both rewrite the exact evidence the
+ # form exists to collect, and both look like a clean report to the person pasting it.
+ (
+ "win",
+ "Windows Defender Antivirus 4.18.24090.11",
+ "Windows Defender Antivirus 4.18.24090.11",
+ ),
+ ("cat", "Trojan:Script/Wacatac.B!ml", "Trojan:Script/Wacatac.B!ml"),
+ # Still redacted where it is genuinely the account.
+ ("alice", r"C:\Users\alice\Downloads\x.ps1", r"C:\Users\<user>\Downloads\x.ps1"),
+ ("alice", r"CORP\alice", r"CORP\<user>"),
+ # A longer account name that merely starts with the same letters must not be half-eaten.
+ ("al", r"C:\Users\alice\x.ps1", r"C:\Users\alice\x.ps1"),
+ ],
+)
+def test_redaction_only_fires_on_a_real_account_component(
+ tmp_path: Path, username: str, line: str, expected: str
+) -> None:
+ """Driven through the shipped function, not by reading its regex.
+
+ The first version replaced every case-insensitive occurrence of the account name anywhere in
+ the line, so an account called `win` rewrote `Windows Defender` and one called `cat` rewrote
+ `Wacatac`. Those are the product and detection names the whole form is built to capture, and the
+ reporter cannot tell it happened.
+ """
+ pwsh = shutil.which("pwsh")
+ if pwsh is None:
+ pytest.skip("pwsh is unavailable")
+
+ script = tmp_path / "redact.ps1"
+ script.write_text(
+ _hide_personal_source()
+ + "\n"
+ + "$env:USERPROFILE = 'C:\\Users\\__no_such_profile__'\n"
+ + f"$env:USERNAME = '{username}'\n"
+ + "Write-Output (Hide-Personal $env:UNSLOTH_LINE)\n",
+ encoding = "utf-8",
+ )
+ import os as _os
+
+ done = run_pwsh(
+ [pwsh, "-NoProfile", "-NonInteractive", "-File", str(script)],
+ capture_output = True,
+ text = True,
+ timeout = 120,
+ env = {**_os.environ, "UNSLOTH_LINE": line},
+ )
+ assert done.returncode == 0, f"{done.stdout}\n{done.stderr}"
+ assert (
+ done.stdout.strip() == expected
+ ), f"account {username!r} turned {line!r} into {done.stdout.strip()!r}"
+
+
+def test_the_probe_does_not_change_the_callers_error_preference() -> None:
+ """The form promises the probe changes nothing, and then set a preference at the prompt.
+
+ `$ErrorActionPreference = 'Continue'` pasted into an interactive session persists for the rest
+ of that session, so a reporter who runs with `Stop` silently loses it. Running the body inside
+ a script block scopes the assignment to the block.
+ """
+ snippet = _snippet().strip()
+ assert snippet.startswith("& {"), (
+ "the probe no longer runs inside a script block, so the preference it sets leaks into the "
+ "session the reporter pasted it into"
+ )
+ assert snippet.endswith("}"), "the script block is not closed"
+ assert snippet.index("$ErrorActionPreference") > snippet.index(
+ "& {"
+ ), "the preference is set outside the block that was supposed to contain it"