The Startup Crash and the Smart App Control Trap
When a frozen Python backend dies immediately after launch on a Windows machine running Smart App Control (SAC), the failure rarely happens inside your Python code. It happens at the Windows loader boundary when a native module fails policy verification. A PyInstaller build is not a single monolithic binary; it is a bootloader executable plus dozens or hundreds of Portable Executable (PE) images—python3xx.dll, the VC++ runtime, C-extension .pyd files (which are structurally standard Windows DLLs), and third-party native libraries from wheels like NumPy, SQLite, OpenSSL, or PySide. When the bootloader calls LoadLibraryExW to map a bundled .pyd or .dll into the process address space, Windows evaluates that child image against its security policy. If Smart App Control blocks that specific module with "An Application Control policy has blocked this file", the loader aborts mapping the image and returns a module-load failure up through Python's import machinery, raising an unhandled ImportError or access/loader fault that kills the process before your main application window or recovery handler ever runs.
Signing only the top-level .exe fails to prevent this crash because Windows does not inherit code-signing trust transitively from a signed parent process to every unsigned module it loads. In a standard Windows PE load path, the kernel and user-mode loader inspect the PE header and Authenticode signature of each mapped image independently. Even when app.exe carries a valid cryptographic signature, an unsigned _ssl.pyd or libcrypto-3.dll remains an unverified PE image on disk. Under Smart App Control—which enforces strict policy rules on non-reputable or unsigned code rather than merely warning the user like classic SmartScreen—an unsigned third-party DLL or PYD has no trusted signer chain to vouch for it. The causal chain is direct: unsigned wheel binary stays unsigned during freeze -> Windows loader maps the .pyd/.dll as a separate PE image -> SAC policy rejects the unverified image -> import/loader error terminates the Python runtime at startup.
A common choice error before buying a certificate is assuming either that signing app.exe post-build covers the bundle or that a brand-new code-signing certificate immediately flips Smart App Control from block to allow. Post-build signing of only the main executable leaves every bundled .pyd and .dll untouched, so the exact same loader rejection occurs on any dependency not already allowed by local reputation. Conversely, signing every binary with a fresh certificate solves the missing-signature defect at the PE level, but does not instantly erase reputation cold-start friction on first release: Windows reputation systems weigh signer history and prevalence over time rather than treating a brand-new certificate as fully seasoned on day one. Furthermore, signing alone breaks down if timestamps are omitted during signing—once a timestamping authority (TSA) signature is missing or the certificate expires, signature validation shifts from time-stamped historical validity to current certificate state, causing verification failures on future installs.
-
Signing only the main
.exevs. signing every.pydand.dllbefore/during freeze: Signing only the.exeis ineffective against SAC blocking bundled dependencies because Windows verifies each loaded PE module on its own signature; signing every native.pydand.dll(includingpython3xx.dlland wheel shared libraries) is required so no loaded image lacks a valid signature. -
onefileextraction to temp vs.onedir/ installer layout: Inonefilemode, the bootloader extracts bundled binaries into a temporary directory (such as%TEMP%\_MEI...) on every launch. Repeatedly writing and loading extracted PE files inside a transient temp path amplifies scan/evaluation overhead on every startup and leaves temporary artifacts exposed to path/file-based heuristics and cleanup races, whereas a structured directory layout or proper installer places binaries in a stable application folder with clean versioned updates. -
Decision rule for packaging and signing: If your Python backend includes native
.pydor.dlldependencies and targets Windows users with Smart App Control active -> sign every.pyd,.dll, and.exewith an RFC 3161 timestamped certificate and ship via a signed installer or structured release directory rather than relying on an unsigned build oronefiletemp extraction alone.
How Windows Evaluates Frozen Python Binaries and Signing Boundaries
When a PyInstaller-frozen Python backend launches on Windows, users do not run a monolithic single-file program in memory. They run a C bootloader stub that unpacks or locates dozens or hundreds of separate Portable Executable (PE) images—python3xx.dll, Visual C++ runtime libraries, C-extension .pyd files (which are structurally standard Windows DLLs), and native wheel libraries such as NumPy, SQLite, OpenSSL, or PySide. Treating the top-level .exe as the sole security boundary is the single most expensive mistake teams make when budgeting for code signing.
Non-Transitive Authenticode Verification at the Loader Boundary
Authenticode trust is not inherited down a call tree. When the PyInstaller bootloader initializes the embedded Python runtime and imports native extensions, Windows invokes LoadLibraryExW to map each .dll or .pyd into the process virtual address space. During that mapping sequence, the Windows loader and kernel/user-mode policy checks inspect the target module's own PE header and embedded PKCS#7 Authenticode signature independently of the parent .exe.
The failure chain operates mechanically across four steps:
-
Unsigned dependency enters the freeze: A third-party wheel ships precompiled
.dllor.pydbinaries without an Authenticode signature, and PyInstaller packs them untouched into the archive or bundle folder. -
Independent module mapping: At runtime, Python's import machinery calls the Win32 loader to map that specific
.pydor.dllas its own PE image rather than reusing the signed signature attached toapp.exe. - Policy rejection on unverified image: On a machine with Smart App Control (SAC) in enforcement mode, a module lacking verifiable signing/reputation status fails policy evaluation, triggering "An Application Control policy has blocked this file" and aborting image mapping.
-
Unrecoverable process termination: Because mapping fails before Python finishes binding the extension module, the runtime raises an unhandled
ImportErroror loader exception during startup—often before application logging or crash handlers initialize—killing the process immediately.
Signing only app.exe removes the SmartScreen warning on the wrapper executable itself, yet leaves every child PE image exposed. The moment execution reaches an unsigned wheel binary on a SAC-enforced host, the loader blocks that file and the app dies on startup, turning certificate spend into a partial fix that still fails onboarding.
Signing Scope: Main Executable vs. Every Bundled .pyd and .dll
To eliminate missing-signature blocks under SAC, you must sign every native PE binary (.exe, .dll, and .pyd) in the bundle—including python3xx.dll, runtime DLLs, and third-party wheel shared libraries—not just the top-level executable. Signing in onedir mode before final packaging (or signing all collected PE files cleanly and verifying no unsigned PE binaries remain) ensures that when LoadLibraryExW maps any dependency, an Authenticode signature is present on that exact file.
A common pipeline error is signing only after PyInstaller finishes building, or signing only files matching *.exe. Because .pyd files use the .pyd extension rather than .dll, naive file globs miss them completely, leaving critical C extensions unsigned while the main binary shows a valid signature.
Equally critical is RFC 3161 timestamping during signing. If a signature lacks a timestamp from a trusted Time Stamping Authority (TSA), Windows evaluates certificate validity against the current system clock rather than the historical signing time. Once the code-signing certificate expires—or if clock/chain checks fail later—the signature loses validity, causing verification failures on subsequent installs or updates.
Reputation Cold Start: Does Signing Stop Smart App Control Immediately?
Signing every .exe, .dll, and .pyd fixes the missing signature defect at the PE level, but it does not grant instant, zero-friction reputation on day one. Windows reputation systems (SmartScreen and SAC) evaluate cryptographic identity alongside prevalence and history over time. With a brand-new certificate or newly compiled binaries, initial reputation starts cold: a valid signature proves who signed the binary and that it was not tampered with since signing, whereas prevalence and historical trust accumulate as genuine installations and telemetry occur.
In practice, moving from unsigned to fully signed with an RFC 3161 timestamp still improves outcomes immediately by establishing stable signer identity rather than anonymous or unsigned files, but edge-case blocks or heightened scrutiny can still occur on fresh certificates or brand-new file hashes until reputation builds. Reusing a consistent signing identity across releases—and avoiding unnecessary churn of unrelated native binaries on every minor patch—helps reputation accumulate rather than resetting per build.
onefile vs. onedir and Installers: Extraction Mechanics and Risk
Packaging layout directly changes how Windows scans, caches, and evaluates files at launch. In PyInstaller onefile mode, the bootloader extracts bundled binaries into a transient subdirectory under %TEMP% (such as _MEI...) on startup and cleans up afterward. That repeated extraction creates three concrete operational problems:
- Repeated scan and evaluation overhead: Every cold start writes fresh files to a temporary path and forces security scanners and loader checks to evaluate extracted binaries again instead of reading from a stable installed location.
- Temporary-path and heuristic friction: Unpacking executables and DLLs into volatile temp folders increases exposure to heuristic scrutiny, path-based exclusions mismatches, and file-lock or cleanup races if a prior process exits abruptly.
-
Weak update and provenance boundaries: A raw
onefiledrop lacks a formal installation footprint, making versioned upgrades, uninstall hygiene, and installer-level trust harder to manage cleanly.
| Approach | Runtime & Security Mechanics | Practical Verdict |
| Unsigned onefile EXE | No Authenticode signatures on EXE, DLLs, or PYDs; extracts binaries to %TEMP%\_MEI* on every launch. |
Worst: Triggers SmartScreen warnings and high risk of SAC blocks on bundled DLLs/PYDs plus temp-extraction overhead. |
| EXE-only signed bundle | Only top-level .exe is signed; child .dll and .pyd images remain unsigned when mapped via LoadLibraryExW. |
Insufficient: Leaves child PE modules unverified, allowing SAC to block individual extensions and crash startup. |
| All PEs signed + onedir / signed installer | Every .exe, .dll, and .pyd is timestamp-signed; binaries sit in a stable installed directory rather than temp extraction. |
Optimal: Eliminates unsigned-PE loader blocks, avoids repeated temp extraction, and supports steady reputation growth. |
When the optimal approach still hits limits: Even with every PE signed and distributed via a structured directory or signed installer, blocks or friction can still happen if (1) a third-party native DLL is packed or modified in a way that breaks PE signature structure, (2) a build script misses a nested .pyd or runtime DLL, (3) RFC 3161 timestamping was omitted and the certificate expires, or (4) certificate and file prevalence is still in its early cold-start window on strict SAC hosts.
Decision Rule and Repeatable Release Pipeline
Decision rule: If your PyInstaller distribution includes native .pyd or .dll dependencies and targets Windows users where Smart App Control or SmartScreen enforcement matters -> sign every .exe, .dll, and .pyd with an RFC 3161 timestamped certificate and ship via a signed installer or stable onedir layout rather than an unsigned build or raw onefile temp extraction.
A reliable, repeatable pipeline keeps signing deterministic and auditable before you spend money on a certificate:
-
1. Freeze in
onedirfirst: Build the frozen directory in a clean CI environment so all collected.exe,.dll, and.pydfiles are visible on disk in deterministic paths. -
2. Enumerate and sign every PE binary: Walk the output directory to collect every
.exe,.dll, and.pydfile, sign each one with your code-signing certificate and an RFC 3161 timestamp server, and fail the build if any signing call exits non-zero. -
3. Run a signature verification gate: Programmatically verify signatures across every
.exe,.dll, and.pydin the staged directory before packaging—confirming zero unsigned PE binaries slip through. -
4. Package into a signed installer or structured release artifact: Wrap the verified directory into an installer (and sign the installer executable itself with RFC 3161 timestamping) so files land in a stable installation path rather than extracting to
%TEMP%on every launch. - 5. Test on a clean SAC-enabled VM before public rollout: Validate installation and cold startup on a fresh Windows environment with Smart App Control active—and with an unsigned test binary intentionally left in place during dry runs—to confirm you catch real loader blocks rather than false-positive local machine allowances.
Preventing Windows SmartScreen and Smart App Control Blocks in PyInstaller Apps via Cost-Effective Code Signing
Shipping an unsigned PyInstaller desktop bundle on Windows fails in two distinct ways that cost real users before your main Python loop ever runs. First, Windows SmartScreen inspects file reputation and throws a Windows protected your PC gate on fresh downloads when a binary lacks established telemetry. Second, on machines where Windows Smart App Control (SAC) is active—enabled by default on clean installations—Smart App Control enforces strict application control rather than a dismissible warning. When a native module fails policy, the Windows loader aborts image mapping with An Application Control policy has blocked this file, Python raises an unhandled ImportError or loader fault during extension import, and the process dies before your logging or crash handlers initialize.
Signing only the outer app.exe wrapper does not stop this crash. A PyInstaller freeze produces a C bootloader alongside dozens or hundreds of Portable Executable (PE) images—python3xx.dll, Visual C++ runtime libraries, C-extension .pyd files (which are structurally Windows DLLs), and native wheel libraries such as NumPy, SQLite, OpenSSL, or PySide. Authenticode trust is not transitive across the process boundary. When the bootloader or Python import machinery calls LoadLibraryExW to map a .dll or .pyd into virtual address space, the loader inspects that specific child image's PE header and PKCS#7 signature independently of the parent executable. An unsigned wheel binary stays unsigned through PyInstaller's bundling pass; when LoadLibraryExW maps it under SAC and finds no trusted signature or reputation allowlist, mapping fails and tears down the runtime.
Buying a code-signing certificate before fixing PE coverage and packaging layout wastes money on two fronts. If bundled .pyd or .dll files remain unsigned, SAC blocks them regardless of whether app.exe carries a valid signature. Even when every PE is signed with an RFC 3161 timestamp—which binds signature validity to signing time via a Time Stamping Authority so future certificate expiration does not break verification—reputation still starts cold on a new certificate or newly hashed binaries. Changing native binaries unnecessarily across builds resets file-level reputation accumulation, keeping friction high until prevalence and signer history build over time.
Five Packaging and Signing Scenarios Under Scrutiny
To see where SmartScreen warnings and Smart App Control loader blocks persist or disappear, compare five concrete release configurations across runtime mechanics, reputation behavior, and failure modes.
| Scenario | PE & Packaging Mechanics | SmartScreen & SAC Behavior | Primary Failure Mechanism |
| 1. Unsigned onefile EXE | No Authenticode signatures on app.exe or extracted .dll/.pyd files; unpacks to a transient %TEMP%\_MEI... folder on every launch. | Triggers SmartScreen reputation prompts on download and exposes extracted child PEs to SAC blocks and scan overhead on launch. | Unverified PE headers and temp-folder extraction trigger repeated scans, heuristic scrutiny, and loader rejection of unsigned modules. |
| 2. EXE-only signed onefile/onedir | Only the top-level app.exe is signed; python3xx.dll, runtime DLLs, and third-party .pyd/.dll wheels remain unsigned. | Reduces top-level launcher friction over time, but SAC still blocks unsigned child .pyd/.dll images during LoadLibraryExW. | Non-transitive signature evaluation leaves child PE images unverified; failed extension import kills startup before app code runs. |
| 3. All PEs signed + onefile | Every .exe, .dll, and .pyd is signed with an RFC 3161 timestamp, but still extracted to %TEMP%\_MEI... on each run. | Eliminates unsigned-module blocks once signatures verify, but still pays per-launch extraction/scan costs and temp-path edge cases. | Repeated disk writes into volatile temp paths cause cold-start scan latency, path-rule mismatches, and cleanup/lock races on abrupt exits. |
| 4. All PEs signed + onedir (new cert) | Every .exe, .dll, and .pyd is RFC 3161 timestamp-signed in a stable directory, using a brand-new signing certificate. | Zero missing-signature loader defects, but SAC/SmartScreen reputation starts cold until signer and file telemetry accumulate. | Lack of historical signer prevalence and file reputation leaves new certificates/hashes exposed to strict policy or warning friction initially. |
| 5. All PEs signed + signed installer/onedir (aged cert) | Every .exe, .dll, and .pyd is RFC 3161 timestamp-signed, shipped via a signed installer to a stable path with a mature cert. | Optimal baseline: eliminates missing-signature blocks, avoids temp extraction churn, and leverages accumulated signer/file reputation. | Can still fail if a post-sign step modifies a PE header/binary, a nested DLL is missed, or timestamps are omitted before cert expiry. |
Scenario 1 (Unsigned onefile EXE) fails both gates. At launch, the bootloader unpacks bundled PEs into a temporary _MEI folder and loads them; each write and LoadLibraryExW call hits an unverified file with zero reputation, creating startup blocks plus repeated extraction and scanning overhead on every run.
Scenario 2 (EXE-only signed bundle) is the most common budget trap. Signing only app.exe puts a signature on the outer wrapper, but the operating system evaluates every mapped .dll and .pyd separately when Python imports C extensions. One unsigned native library in a wheel is enough to trigger SAC's block dialog and abort startup.
Scenario 3 (All PEs signed + onefile) fixes missing signatures on child modules, yet keeping onefile temp extraction creates operational friction. Extracting dozens or hundreds of binaries into %TEMP% on every launch forces repeated file creation, security evaluation, and cleanup work, and abrupt process termination can leave locked or partial temp artifacts behind.
Scenario 4 (All PEs signed + onedir with a new certificate) solves the technical loader defect—every PE carries a valid signature and sits at a deterministic path—but does not buy instant reputation. SmartScreen and SAC weigh historical telemetry and prevalence over time, so a brand-new certificate or brand-new binary hash still faces cold-start caution until real-world usage builds trust.
Scenario 5 (All PEs signed + signed installer/onedir with an established certificate) is the optimal architecture. Placing signed binaries in a stable installation directory via a signed installer avoids per-launch temp extraction, gives users clean upgrades and uninstalls, and lets reputation accumulate across releases without resetting every binary on every build.
Edge Cases That Break Even a Signed Build
Even after you sign every .exe, .dll, and .pyd and move off raw onefile extraction, four failure mechanisms can still cause blocks or verification errors:
- Post-sign binary mutation: Any step that packs, compresses, strips, or rewrites a PE after signing—such as UPX packing or modifying resources/headers after signtool runs—alters bytes covered by the Authenticode digest or invalidates the PE signature layout, causing signature verification failure at load time.
- Incomplete file enumeration: Signing scripts that filter only for *.exe and *.dll often miss *.pyd extension modules or nested runtime libraries inside wheel subdirectories, leaving an unverified PE image right in the import path.
- Missing RFC 3161 timestamp: Signing without a trusted timestamp ties certificate validity to the current system clock rather than the time of signing. Once the certificate expires, subsequent installs or verifications fail even if the binary was signed while the certificate was active.
- Unnecessary binary churn: Rebuilding or re-touching unchanged native binaries on trivial app updates creates new file hashes and slows reputation accumulation compared to keeping stable native modules intact when their dependencies do not change.
Decision Rule and Repeatable Release Pipeline
Use this decision rule when choosing your distribution and signing setup: if your Windows distribution includes native .pyd or .dll dependencies and targets users where SmartScreen or Smart App Control is active, then sign every .exe, .dll, and .pyd with an RFC 3161 timestamp and ship via a signed installer or onedir layout rather than an unsigned build or onefile temp extraction alone. Only if you ship a pure, self-contained executable with no external or bundled child PEs and zero SAC enforcement target could lighter packaging be considered, and even there RFC 3161 timestamping remains mandatory.
Before purchasing a certificate, wire your CI pipeline so signing is deterministic, auditable, and hard to bypass:
- Freeze in onedir mode on clean CI: Build in a clean automated environment using onedir so every .exe, .dll, and .pyd lands in predictable directories on disk.
- Sign all PE files with RFC 3161 timestamps: Enumerate every .exe, .dll, and .pyd in the staged output, apply Authenticode signing with an RFC 3161 timestamping authority, and fail the pipeline immediately on any non-zero signing exit code.
- Run a programmatic signature gate: Before packaging, scan every staged .exe, .dll, and .pyd with a verification check (such as signtool verify or equivalent PE signature inspection) and abort the release if any binary is unsigned or invalid.
- Package into a signed installer targeting a stable path: Wrap the verified build into an installer, sign the installer binary itself with an RFC 3161 timestamp, and install to a persistent application directory rather than relying on %TEMP% extraction at runtime.
- Verify on a clean SAC-enabled VM: Test installation and cold launch on a fresh Windows VM with Smart App Control active—and run a deliberate negative test with one unsigned DLL to confirm real loader enforcement rather than trusting a developer workstation where local allowances mask errors.
Evaluating the Certificate ROI Prerequisite
Investing in a code-signing certificate before auditing your PyInstaller build layout is a fast path to wasted capital. Publishers frequently purchase an Extended Validation or Standard certificate, sign only the primary app.exe wrapper, and discover that their application still crashes instantly on Smart App Control-active machines. The root cause lies in how the Windows loader evaluates executable images.
Windows does not inherit trust transitively from a parent process to child modules. When Python executes an import statement or the C runtime initializes, the operating system invokes LoadLibraryExW to map external binary images into virtual memory. Every bundled .dll and .pyd—including python3xx.dll, Visual C++ runtimes, and native wheel extensions like NumPy or PySide—undergoes an independent cryptographic signature and policy inspection. If a single child Portable Executable lacks a valid Authenticode signature, Smart App Control terminates the image-mapping sequence, throwing an unhandled policy block that aborts execution before Python loggers or crash handlers can initialize.
Reputation Ramp-Up and Cold-Start Friction
Signing every binary does not grant instant immunity against SmartScreen and Smart App Control policies on day one. Reputation-based trust mechanisms evaluate both the signer's digital identity and the historical prevalence of specific binary hashes across global telemetry telemetry networks. When a certificate or a newly compiled binary hash is brand new, it possesses zero accumulated telemetry weight.
The mechanical effect of this cold state is heuristic scrutiny. Even with a valid signature, Windows treats unknown binaries with suspicion, resulting in delayed execution checks, transient warning prompts on initial download, and strict policy enforcement if user-base telemetry fails to cross validation thresholds. Publishers must budget for an operational ramp-up phase where early users experience minor trust friction while global download volume builds signer prevalence.
Packaging Mechanics: Onefile vs. Onedir Cost Profiles
The choice between PyInstaller's onefile and onedir modes imposes stark trade-offs regarding security validation and runtime performance overhead:
- Unsigned or partially signed onefile builds force the bootloader to unpack every embedded .dll and .pyd into a transient temporary folder (such as %TEMP%\_MEI...) on every single application launch. This dynamic extraction creates a heavy CPU and disk-IO bottleneck, floods security scanners with recurring file-creation events, and frequently triggers path-rule mismatches or file-lock collisions on abrupt exits.
- Signed onedir layouts paired with an installer deposit verified binaries into a stable, persistent directory path (like Program Files) once during installation. This eliminates per-launch extraction latency, keeps file paths deterministic for policy engines, and allows the operating system to cache trust evaluations rather than rescanning unpacked binaries on every execution cycle.
Common Choice Errors and Decision Framework
Publishers routinely commit critical release errors by relying on manual signing scripts, skipping RFC 3161 Time Stamping Authority timestamps—which causes signatures to fail validation the moment the signing certificate expires—or mutating binaries via post-sign compression like UPX, which shatters the PE header digest.
Decision Rule: If your Windows application distributes native .pyd or .dll dependencies and targets SmartScreen or Smart App Control environments, you must sign every single .exe, .dll, and .pyd binary using an RFC 3161 timestamp, and distribute the bundle via a signed installer targeting a persistent installation path rather than relying on raw onefile temporary extraction.
Why Signing Only app.exe Fails Under Smart App Control
Signing only the top-level PyInstaller executable does not protect a frozen Python desktop application from Windows Smart App Control (SAC). When a user launches app.exe, the Windows loader first maps the executable image into virtual memory, then Python extension imports and C runtime initialization invoke LoadLibraryExW on every bundled .pyd file (which is a Windows PE DLL) and every .dll file such as python3xx.dll, VC++ runtimes, SQLite, NumPy, or Qt/PySide libraries.
Authenticode trust is not transitive from parent process to child module. Each .dll and .pyd carries its own Portable Executable (PE) header and PKCS#7 signature block, and the kernel/loader evaluates each mapped binary independently. If app.exe is signed with a valid certificate but an underlying .pyd or .dll lacks a valid signature or violates SAC policy, the loader aborts mapping that image and returns an application control policy block. Inside the frozen Python process, that blocked image surfaces as an unhandled ImportError or loader failure before logging or crash reporting initializes, killing startup silently on the user machine.
Buying a code-signing certificate before fixing binary signing coverage and packaging layout wastes money. Unprotected child binaries still trigger SAC startup crashes even when app.exe carries a signature, and a brand-new certificate starts with zero historical prevalence in Microsoft reputation telemetry.
Reputation Cold-Start and onefile vs. onedir Mechanics
Code signing proves identity and file integrity; it does not grant instant SmartScreen or SAC reputation. SmartScreen and SAC weigh both signer identity and global file/signer prevalence across Windows telemetry. A newly issued certificate or a newly compiled binary hash starts at cold prevalence, so Windows can still apply stricter scrutiny, delayed evaluation, or reputation warnings until enough clean executions and downloads accumulate.
Adding an RFC 3161 timestamp from a Time Stamping Authority (TSA) embeds a cryptographically signed time token inside the Authenticode signature. That timestamp prevents a signature from becoming invalid after the signing certificate expires, because the verifier checks the signature against the timestamp rather than the current system clock. It does not bypass cold-start reputation.
- Unsigned onefile EXE: Neither app.exe nor the unpacked .pyd/.dll files are signed. Every launch extracts the entire payload into a transient %TEMP%\_MEI... folder, multiplying file-creation events, scan work, and path churn while leaving every child PE exposed to SAC blocks.
- EXE-only signed (onefile or onedir): Only app.exe is signed. Launcher warnings may ease over time, but unsigned .pyd and .dll files still fail independent loader checks under active SAC, crashing startup.
- All PEs signed with onefile: Every .exe, .dll, and .pyd is signed with an RFC 3161 timestamp, but extraction still writes dozens of PE files into a randomized %TEMP%\_MEI... directory on every launch. That repeated disk write/scan cycle slows cold starts, creates temporary directory cleanup collisions on abrupt exits, and fights path-based policy caching.
- All PEs signed with onedir (new certificate): Every .exe, .dll, and .pyd is signed and placed in a fixed directory. Unsigned-module loader blocks stop, but initial reputation is cold until telemetry builds.
- All PEs signed with a signed installer and onedir (mature certificate): Optimal baseline. Native binaries are written once to a persistent path such as Program Files, verified once or cached cleanly by the OS, and backed by accumulated signer and binary history.
Decision rule: If your Windows app ships any native .pyd or .dll dependencies and targets SmartScreen or SAC environments, sign every .exe, .dll, and .pyd with an RFC 3161 timestamp and ship via a signed installer using a onedir layout rather than an unsigned build or onefile temp extraction. Use a lighter single-binary setup only when there are zero child PEs and no SAC target, and still keep RFC 3161 timestamps on every signed artifact.
Where Signed Builds Break in Practice
- Post-sign binary mutation: Running UPX packing, resource editing, or binary stripping after signing alters bytes inside the PE sections or header layout. Because the Authenticode digest hashes the PE structure (excluding the signature table itself), post-sign mutation breaks cryptographic integrity and causes loader verification failure. Always freeze and mutate before signing, never after.
- Incomplete file enumeration: Scripts that sign only *.exe and *.dll often miss *.pyd files or nested native libraries inside third-party wheels. Any skipped PE remains an unverified module on sys.path or the DLL search path.
- Missing RFC 3161 timestamp: Signing without a TSA URL leaves the signature tied to current wall-clock validity. Once the certificate expires, installations and verifications fail even if the binary was signed while the certificate was active.
- Unnecessary binary churn: Rebuilding or re-touching unchanged wheel DLLs on minor Python/UI releases changes file hashes and resets per-hash prevalence. Preserve untouched native binaries when dependencies have not changed.
Actionable Verification and Packaging Playbook
Before paying for a production certificate, reproduce the failure and lock down the release pipeline in this exact sequence:
1. Reproduce on a Clean SAC-Enabled VM
- Provision a clean Windows virtual machine with Smart App Control in On mode (SAC cannot be toggled back to On once turned Off without a reset, so snapshot the clean VM before testing).
- Do not test only on a developer workstation where local execution history or developer allowances mask enforcement.
- Run a negative test by leaving one non-critical .dll or .pyd unsigned in a staged build and launching the app to confirm you see the exact ImportError or policy block before shipping.
2. Build onedir and Sign Every PE with a Timestamp
- Freeze the application in onedir mode on a clean CI runner so all binaries land in deterministic paths, and disable post-sign UPX compression.
- Recursively enumerate every .exe, .dll, and .pyd in the staged onedir tree and sign each file using signtool sign with an RFC 3161 timestamp server (/tr and /td sha256).
- Fail the pipeline immediately on any non-zero signing exit code.
3. Audit Signatures Before Packaging
- Run an automated verification pass over every staged .exe, .dll, and .pyd using signtool verify /pa /v (or a PE signature parser) to confirm each file has a valid signature chain and an embedded RFC 3161 timestamp.
- Abort the build if any file is unsigned, missing a timestamp, or fails chain verification.
4. Ship a Signed Installer to a Persistent Path
- Wrap the verified onedir payload into an installer (such as Inno Setup or MSIX/NSIS) that writes files once to a stable directory rather than %TEMP%.
- Sign the installer binary itself with the same certificate and RFC 3161 timestamp, then verify the installer signature before release.
- Install and cold-start the final signed installer on the clean SAC snapshot VM, then repeat on a second clean snapshot after rolling out an update to verify that unchanged native binaries keep their hashes and behavior remains clean.
Top comments (0)