r/Python • • 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:

  1. 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?
  2. Has anyone seen Smart App Control actually stop blocking after signing, or does it still flag new files until reputation builds?
  3. 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

33 comments sorted by

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.

1

u/Ishannaik 1d ago

three years with only one firm causing trouble is a solid track record for a signed onefile setup. nuitka onefile still unpacks into temp under appdata right, so was that IT dept blocking the extracted files running or the whole folder

1

u/Brandhor 3d ago

how does nuitka works in terms of license?

since the standard edition is agpl wouldn't it "infect" your code as well?

or it doesn't matter in this case because it's the generated exe that uses nuitka and not your code?

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.

1

u/Ishannaik 1d ago

fair, a paid cert not being a free pass makes sense given the supply chain stuff. does nuitka actually help with SAC specifically or is it more that the output doesnt look like a packed pyinstaller bundle?

1

u/sausix 1d ago

With Nuitka there is less bundling. You get a native executable with more performance from an actual compilation.

I just can't name a single point for using PyInstaller. It could be faster on the packaging process. That's it. So why use it anyway? Because of containing a full Python environment the output should be larger... The pyc files are easier to decompile...

My first signed exe files worked on other computers so far. But I stopped deploying onefile builds because it broke a subprocess call of itself. Standalone and installer version do work just fine.

1

u/Ishannaik 1d ago

onefile breaking a subprocess call of itself is a nasty one to hit, good to know standalone n the installer avoided it. was it relaunching via sys.executable that broke, or the temp extraction getting cleaned up under the child process?

1

u/sausix 23h ago

I could have fixed it. I'm running a sub component of the code as another process. It's possible with onefile too but it would be a special handling just for a temporary use case. Standalone builds do startup faster. I'll create an auto update anyway so an installer will be enough.

Nuitka has special handling for this. Didn't dig into it yet. argv[0] and sys.executable get changed I think.

I used Popen on argv[0] and that worked on running on source code and on standalone.

I've read about onefile versions fill up RAM on many starts due to their extractions. Don't remember if it was PyInstaller or Nuitka. I recommended my testers to not use the onefile and now stopped building it.

2

u/Ishannaik 23h ago

popen on argv[0] working for both source and standalone is a neat trick, way less fragile than guessing what sys.executable ends up pointing at in each mode. the ram filling up from repeated extractions would be reason enough on its own to keep testers off onefile tbh

2

u/zaphodikus 3d ago

Nuitka rocks.

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.

1

u/Ishannaik 1d ago

that line abt SAC falling back to the cert when it cant make a prediction is the exact part i needed. have u actually signed every file in a onedir build yourself or is that from the docs too?

1

u/aayush_satna_dev 1d ago

that's was also from the doc bro! I spend lot of time with the docs so even if I feel some query is out of my experience, I stick with the doc and that works perfectly.

1

u/Ishannaik 1d ago

sticking with the docs when something is outside ur own experience is honestly the safer move for windows signing stuff, half the forum answers contradict each other. did they say anything abt whether the trusted root fallback still applies to files extracted into temp, or is that one not covered?

1

u/sausix 3d ago

You can still sign containing binaries and the outer container exe. Not a valid reason against onefile.

Cons of onefile:

  • Extraction time
  • More suspicious to heuristic analysis because it's "hiding" something

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.

1

u/Ishannaik 1d ago

didnt know the psf already signs python3xx.dll, so re-signing the whole dist folder would be pointless. when u ran that on ur own builds were the NotSigned ones mostly third party .pyd files or just the pyinstaller bootloader exe?

1

u/Kamalmosadegh 1d ago

Mostly the third-party .pyd files, in my experience. The Python DLLs were already signed, so they never showed up as NotSigned. What did show up was the extension modules that come in with wheels — those .pyd files are basically DLLs with a different extension, and most of them ship unsigned — plus the bootloader exe itself and the main exe, which are unsigned unless you sign them yourself.

One thing worth noting: that snippet I posted only looks for *.exe and *.dll, so it will not even list the .pyd files. Add *.pyd to the -Include list and you will see the full picture. In practice that is the list that matters for Smart App Control — sign the bootloader exe, your main exe and the unsigned .pyd files, and leave the already-signed Python DLLs alone.

1

u/Ishannaik 1d ago

so the snippet was quietly skipping the exact files that matter, good thing u flagged the *.pyd bit. bootloader, main exe n the unsigned pyds is a pretty manageable list. did any of the wheels u used actually ship signed .pyd files or is it basically none of them

1

u/Kamalmosadegh 20h ago

Basically none, in my experience. Every third-party .pyd I have checked in a frozen build came back NotSigned — the only signed binaries I consistently saw were the Python DLLs themselves. So treat the unsigned .pyd list as the signing list, not the exception.

A quick way to get the exact count for your own build, instead of trusting mine:

Get-ChildItem -Recurse dist\YourApp -Include *.pyd | ForEach-Object { (Get-AuthenticodeSignature $_.FullName).Status } | Group-Object

If that shows, for example, 12 NotSigned and 0 Valid for the .pyds, that is normal — sign those 12 plus the bootloader and main exe, and leave anything already Valid alone.

1

u/Ishannaik 20h ago

basically none makes the plan way simpler then, every pyd that comes back NotSigned plus the two exes is the whole signing list and the Valid ones stay untouched. piping it into group-object is a nice touch too, a count is way easier to sanity check than scrolling a wall of statuses

1

u/Kamalmosadegh 16h ago

Yep, that's exactly it. Good luck with the signing, hope it goes smooth.

1

u/Ishannaik 15h ago

appreciate u sticking with all the follow ups, this thread ended up being a proper checklist for the pyinstaller side of signing

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.

6

u/sausix 3d ago

Don't sign third party DLLs which are already signed. You are giving your trust away for no reason. The Python DLLs should be signed by the Python foundation already.

1

u/codariadev 21h ago

Good catch, I should have said unsigned binaries only. Anything that already carries a valid signature (like the PSF-signed Python DLLs or signed VC runtime DLLs) should be left alone — just check which ones in dist/ are actually unsigned and sign those.

1

u/Ishannaik 1d ago

signing the dlls before pyinstaller packs them is what makes onefile sound like such a pain, didnt realise it wont do that for u. did u get azure trusted signing approved as an individual or did it need a registered company

1

u/codariadev 21h ago

I haven't been able to get it approved myself since I'm outside the US/Canada. Microsoft renamed it to Azure Artifact Signing, and individual developer validation for Public Trust is only open to folks in the US and Canada (with an Individual Azure billing account matching your government ID).

Organizations have a wider list (US, Canada, EU, UK, Australia, Japan, etc.), so if you're an individual outside the US/Canada you still end up needing either a registered company in a supported region or a regular OV cert from a traditional CA.

1

u/Ishannaik 21h ago

artifact signing being us/canada only for individuals is a big catch, so outside those two its basically a company or a regular OV cert. did u end up going the OV route or are ur builds still unsigned for now?

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