I recently ran into an interesting behavior on Windows that I found unintuitive so I figured other people may want to know about it too.
An application can call AddClipboardFormatListener to register a callback that gets called whenever the clipboard contents change, like when you copy a file or some text. The process can then call GetClipboardData to read the data. No special privileges are needed and any process can register this callback unless it is running in a sandbox.
The interesting thing is that when a virtual machine is running is “Enhanced session” mode, processes inside the VM that registered a callback with AddClipboardFormatListener will be notified for clipboard changes on the host, or in other VMs that are also running with “Enhanced session”. Of course, the host machine can also read the clipboard contents of the VMs.
I tested this with a small program that I ran in a VM, and saw text (and all other types of clipboard data, but that’s not shown in the screenshot) from within the VM (I called it VM 1), the host machine, and a second VM (VM 2):

Enhanced session (this is the Hyper-V name, but other VM frameworks have similar features) allows copying in and out of the VM, as well as between VMs, so it’s not all that surprising that the VM gets access to the clipboard of the host and of other VMs. But intuitively I expected processes to only get access to clipboard data belonging to the virtual machine’s clipboard, or data that is being copied into the VM. When I copy a password from a password manager into a password field inside a browser on the host machine, I don’t expect a process running inside a VM to be able to access that data, even if the VM is running in “enhanced session” mode. I also don’t expect one virtual machine to have access to the clipboard of another virtual machine (technically that’s not entirely the case because in this setup they all just share the host machine’s clipboard but I’d still expect some isolation between VMs).
Is this a bug? Is this intended behavior that hasn’t been well documented? Is this behavior obvious and I am the only one who is surprised by this? I can’t say.
I only tested this on Hyper-V so I can’t say if the same behavior exists in other VM frameworks. My guess is that it does, but if anyone tests it and wants to share their results I’d be curious to know what you find and will update the blog with your findings.
