I am running into an issue with running a PacketTunnelProvider as a system extension, and fast user switching.
Since the VPN is running as root, it runs outside any user context, and is accessible to all users on the machine. I can see the following behavior:
- Login to User A
- Connect VPN
- Fast switch to user B
- Open Safari, observe that traffic is directed and sent out the VPN. (As noted by the ability to browse otherwise un-reachable websites).
Is there a way to detect that a fast user switch is happening? And disconnect the VPN when user B takes control of the screen.
I know NSWorkspace
is not a daemon-safe API. So NSWorkspaceSessionDidResignActiveNotification
and like will not be useful here.
One alternative would be to use NSWorkspace notifications in the GUI and alert the system extension via XPC. But that wouldn't work in the case where there isn't a GUI, such as with ConnectOnDemand.
Is there a daemon-safe API to use or some other alternative?
Thanks