Supported Windows primitive for atomically invalidating a pending action on session lock/switch

Phat Dat 0 Reputation points
2026-10-13T01:58:06.39+00:00

We are evaluating a local Windows application with a protected authority and untrusted ordinary user applications. We need a supported API contract, not a timing workaround.

A user approves one immutable, exact operation. Until execution is genuinely committed, that approval must expire on workstation lock, user/session switch or authority restart. Unlocking must not revive it. Completed effects need not be undone. Restart must not replay unfinished work.

Critical histories:

  1. Approve, lock, unlock, then attempt commitment before lifecycle notifications have reached the authority: deny.
  2. Lock and commitment race: an OS-defined ordering must determine whether commitment preceded invalidation; an application mutex alone does not order Windows session transitions.
  3. A stable unlocked session with fresh consent must have a useful successful path.

Does Windows expose a supported primitive that satisfies this, either a lifecycle generation checked atomically with a defined execution boundary, or a brokered operation with equivalent ordering? A generation query alone would leave a check-to-commit race.

If so, please identify API, supported Windows editions/builds, caller identity/topology, operation limits, lock/switch ordering, failure/cancellation behavior and official documentation. If no supported primitive exists for arbitrary application operations, please clarify that limit and any supported narrower construction.

WTS/HandlerEx notifications do not document this barrier. Personal Data Encryption Level 2 documents a one-minute post-lock access interval. WebAuthn plugin verification can sign a custom buffer, but its public API descriptions do not establish expiry after a lock-unlock cycle or atomicity with the application's later effect. We are not requesting ways to suppress locking, weaken revocation, or install unsupported hooks.

References:

https://learn.microsoft.com/en-us/windows/win32/api/wtsapi32/nf-wtsapi32-wtsregistersessionnotification

https://learn.microsoft.com/en-us/windows/security/operating-system-security/data-protection/personal-data-encryption/

https://learn.microsoft.com/en-us/windows/win32/api/webauthnplugin/nf-webauthnplugin-webauthnpluginperformuserverification2

Windows development | Windows API - Win32
0 comments No comments

1 answer

Sort by: Most helpful
  1. Zack Nguyen (WICLOUD CORPORATION) 165 Reputation points Microsoft External Staff Moderator
    2026-10-13T02:48:24.97+00:00

    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:

    1. 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.
    2. Accept each nonce once and keep it only in memory. An authority restart then discards pending approvals and does not replay unfinished work.
    3. 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.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.