Hello @Nico Messerlian ,
Based on the current documentation, I do not believe Windows provides a documented Win32/SCM contract that guarantees the initial service process fails closed if its environment cannot be correctly constructed. StartServiceW exposes no environment parameter, and the behavior when no explicit block is supplied is documented explicitly: CreateProcessAsUserW, the path used to launch a service under an account, states that "if the lpEnvironment parameter is NULL, the new process inherits the environment of the calling process... It is your responsibility to prepare the environment block," and CreateProcessW confirms the same. CreateEnvironmentBlock, the producer behind userenv/profapi, is documented only as returning a BOOL, and does not define what a caller such as SCM does on failure.
From these references I would infer, rather than assert, that a NULL environment causing the new process to inherit the caller's environment is intentional and that constructing a correct environment is treated as the caller's responsibility, which would suggest the absence of a fail-closed guarantee is consistent with the design rather than an oversight.
I should be transparent that I could not reproduce the exact internal services.exe branch you describe, since forcing the profapi producer to fail inside a live, critical system process would require kernel-level intervention I did not consider safe to attempt. I did build an approximate model using the same APIs: when an explicit block is supplied the child receives exactly that block, whereas when lpEnvironment is passed as NULL, CreateProcess returns success and the child silently inherits the full caller environment. This shows the fail-open consequence you are concerned about, but it does not establish that the producer-failure branch is actually reachable under normal conditions.
On the per-service HKLM\SYSTEM\CurrentControlSet\Services\<name>\Environment value, I observed that SCM does merge valid NAME=VALUE entries into the initial service process environment, while malformed or empty entries appeared to be ignored and the service still started; I would add, though, that I could not find this value documented in the StartService/SCM reference, so I would treat it as an implementation detail rather than a supported contract to rely on for an assurance requirement.
Given this, I would suggest enforcing the provenance requirement in the service's own entry point, validating the current environment against the approved set and terminating on mismatch before any environment-dependent work, which provides a fail-closed gate you control. Whether the internal NULL-fallback branch is genuinely reachable in a legitimate same-state condition, and whether it would be considered a defect or intended behavior, remains a white-box question about services.exe that I cannot answer authoritatively.
I hope this information helps clarify the behavior, and I would be glad to look further into any specific part if it would be useful. If you found my response helpful or informative, I would greatly appreciate it if you could follow this guide for your confirmation.
Thank you.