[PR #19109] Include the hash of the SID in the Window Class and Mutant #31708

Open
opened 2026-01-31 09:49:02 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/microsoft/terminal/pull/19109

State: closed
Merged: Yes


Right now, we do not use a sufficiently unique name to disambiguate Terminal instances running on the same desktop.

Mutexes (mutants) are named objects that live in the user's session, under Sessions\1\BaseNamedObjects (for the local desktop session). When multiple users are logged into the same session--such as with "Run as different user"--they share a local BaseNamedObjects namespace. Ugh.

We cannot use CreatePrivateNamespace as it requires a boundary descriptor, and the only boundary descriptors supported by the current API are based on package identity. I also fear that CreatePrivateNamespace is subject to a race condition with OpenPrivateNamespace; Create will not Open an existing one, so we would need to back off and retry either opening or creating. Yuck.

After this commit, we will hash the user's SID into the name of both the window class and the mutant, right after the path hash (if running unpackaged).

Closes #18704

**Original Pull Request:** https://github.com/microsoft/terminal/pull/19109 **State:** closed **Merged:** Yes --- Right now, we do not use a sufficiently unique name to disambiguate Terminal instances running on the same desktop. Mutexes (mutants) are named objects that live in the user's session, under `Sessions\1\BaseNamedObjects` (for the local desktop session). When multiple users are logged into the same session--such as with "Run as different user"--they share a local BaseNamedObjects namespace. Ugh. We cannot use [`CreatePrivateNamespace`] as it requires a boundary descriptor, and the only boundary descriptors supported by the current API are based on package identity. I also fear that `CreatePrivateNamespace` is subject to a race condition with `OpenPrivateNamespace`; Create will not Open an existing one, so we would need to back off and retry either opening or creating. Yuck. After this commit, we will hash the user's SID into the name of both the window class and the mutant, right after the path hash (if running unpackaged). Closes #18704 [`CreatePrivateNamespace`]: https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-createprivatenamespacea
claunia added the pull-request label 2026-01-31 09:49:02 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#31708