Hi @Phat Dat ,
Thank you for the questions. To answer them:
Does Windows expose a supported primitive that satisfies this?
There is no documented Windows primitive that provides this guarantee. The public API documentation does not describe a lifecycle generation that is checked atomically with a defined execution boundary. It also does not describe a brokered operation that commits an effect in an OS-defined order relative to workstation lock or user/session switch. This reflects the published API contracts, not undocumented internal behavior.
Your reading of the three references matches their documentation:
- WTSRegisterSessionNotification delivers WM_WTSSESSION_CHANGE notifications to registered windows, and services use HandlerEx instead. Neither documents an ordering between the session transition and an application's commit.
- Personal Data Encryption protects file data. At Level 2, data remains accessible for one minute after lock before the keys are discarded.
- WebAuthNPluginPerformUserVerification2 performs Windows Hello verification for a plugin-authenticator operation and can sign a custom buffer. Its documentation does not cover expiry after lock/unlock, ordering against session transitions, cancellation semantics or a minimum build.
API, editions/builds, caller identity/topology, operation limits, ordering, failure/cancellation and documentation
Since there is no documented primitive that meets this requirement, there are no corresponding API details to provide. None of the referenced mechanisms documents the ordering guarantee your requirement depends on.
The limit for arbitrary application operations
The documentation provides no supported way to bind "no lock or session switch since approval" atomically to "the effect has been committed." Combining these mechanisms does not close that gap. A generation query, a notification-driven flag, a PDE-protected secret and a signed approval each leave a check-to-commit window. Windows does not document that window as ordered against session transitions. As a result, none of them guarantees denial in history 1 or defines the outcome of the race in history 2.
Narrower construction
There is no confirmed Windows-supported narrower construction that satisfies all three histories. An application-owned design can reduce the exposure, but it is not an OS guarantee:
- Keep no approval over time. Request fresh user verification immediately before committing, bound to the exact operation. For example, sign a hash of the operation plus a single-use nonce issued by the authority.
- Accept each nonce once and keep it only in memory. An authority restart then discards pending approvals and does not replay unfinished work.
- Discard outstanding nonces when lock or switch notifications arrive, as defense in depth only.
This design denies history 1, because an approval granted before a lock is never reused. It also handles restart without replay and supports history 3. It does not satisfy history 2. A lock between successful verification and commitment has no documented Windows ordering, so the design only narrows that window to the authority's own verify-to-commit path.
The design also depends on a verification API that your authority is supported to call. WebAuthNPluginPerformUserVerification2 is documented for plugin-authenticator operations, so it should not be assumed to apply to a general protected authority.
I hope this helps and provide you the answers you need.
If this instruction is applicable to your situation, I would greatly appreciate it if you could follow the instruction here so others experiencing similar behavior can benefit from it as well.