r/Python • u/Ishannaik • 4d ago
Discussion PyInstaller on Windows: does code signing stop Smart App Control blocking the DLLs?
I ship a desktop app with a python backend frozen with pyinstaller, currently unsigned. Two problems on Windows:
- SmartScreen "Windows protected your PC" on every fresh download
- worse: on some users' machines Smart App Control blocks the bundled .pyd/.dll files ("An Application Control policy has blocked this file") and the app just dies on startup
I'm about to pay for signing, and the part I can't find a straight answer on is the pyinstaller side:
- Is signing the main exe enough, or do you have to sign every .pyd and .dll inside the bundle (incl. python3xx.dll and third party wheels) before freezing?
- Has anyone seen Smart App Control actually stop blocking after signing, or does it still flag new files until reputation builds?
- onefile vs onedir, does it matter here? onefile extracts to temp, which feels like exactly what SAC hates.
If you've been through this, what did your build pipeline end up looking like?
36
Upvotes
16
u/Responsible_Pool9923 4d ago
I switched to Nuitka and sign both the onefile binary and the installer binary. Been shipping the app for three years now to Windows and Mac users, and it has been moslty smooth sailing except for one firm with overcautious IT department blocking access to AppData.
5
u/sausix 3d ago
There's no guarantee just because you or your company have been verified and paid for a certificate. Applies to cheap Azure fragment signing and also to expensive certificates like DigiCert. Microsoft still applies heuristics to software components. Because keys and suply chains can be compromized anyway.
Signing improves trust a lot at least. I'm in the club since yesterday and I will face the same results soon.
And do not use PyInstaller. No it does not compile your code. #1 misconception of PyInstaller. Go for Nuitka.
3
u/aayush_satna_dev 3d ago
2. I don't think so it would block. You can check the documentation as well. It says, "if the app intelligence service can't make a prediction, SAC still allows an app signed with a certificate from a CA in the Trusted Root Program."
https://learn.microsoft.com/en-us/windows/apps/develop/smart-app-control/overview
3. try using onedir because it would allow you to sign every file.
2
u/Kamalmosadegh 2d ago
One thing worth doing before paying for a cert: check what's actually unsigned in your build first. A quick pass over the dist folder with PowerShell will list it:
Get-ChildItem -Recurse dist\YourApp -Include *.exe, *.dll | ForEach-Object { (Get-AuthenticodeSignature $_.FullName).Status }
Anything that comes back NotSigned is what Smart App Control will actually look at. On a typical PyInstaller onedir build you'll find most of the Python DLLs are already signed by the PSF — don't re-sign those; a second signature adds nothing and you end up vouching for binaries you didn't build.
And keep the two mechanisms apart, because they answer your question 2 differently: Smart App Control blocks binaries it can't classify, and a valid signature gets you past that part. SmartScreen is separate and reputation-based, so a brand-new cert will still trigger the "Windows protected your PC" warning until enough people have installed it without incident. An EV cert skips that reputation-building period, which is the main thing the extra cost buys you. So signing solves the SAC block, but expect SmartScreen warnings on a fresh cert for a while either way.
4
u/codariadev 3d ago
On 1: sign everything that gets loaded, not just the exe. SAC evaluates each binary as it loads, so an unsigned python3xx.dll or a .pyd from some wheel can still get blocked even if the launcher is signed. With onedir that's easy: build, run signtool over every .exe/.dll/.pyd in dist/yourapp, then sign the main exe last (and the installer, if you have one).
On 3: onedir is the easier path here. With onefile the bootloader unpacks to %TEMP% on every launch, and you'd have to sign the DLLs before they get packed into the archive, which PyInstaller doesn't do for you. Shipping onedir inside a signed installer (Inno Setup, MSIX) also gives you a stable install path instead of random temp folders.
On 2: SmartScreen and SAC are different things. SAC should stop hard-blocking once the files carry a valid signature from a trusted CA (that's the doc someone linked). SmartScreen is reputation-based and EV certs no longer skip the warm-up, so expect the "protected your PC" prompt for a while either way. If price is the issue, look at Azure Trusted Signing, it's much cheaper than a traditional cert and works with signtool.
Also timestamp the signatures (
/tr+/td sha256), otherwise they stop validating when the cert expires.2
u/YotzYotz 2d ago
One thing that significantly cut down the number of false positives from the antivirus racket industry for me, was building my own bootloaders for PyInstaller.
https://pyinstaller.org/en/stable/bootloader-building.html
2
u/cointoss3 4d ago
No, signing didn’t help
1
u/OkSignificance5380 3d ago
No.
Code signing DLLs/exes does nothing to prevent smart screen