From 62a4bee42cabefe8979d82229c67e266c79e784d Mon Sep 17 00:00:00 2001 From: Adolanium <94890352+Adolanium@users.noreply.github.com> Date: Thu, 26 Nov 2026 20:14:46 +0200 Subject: [PATCH] fix(windows): accept a private DACL when the user is SYSTEM (#14769) The trustee check treated the user SID and SYSTEM as exclusive. When the process user is SYSTEM, both ACEs match the user and the SYSTEM flag stays unset. Compare the two SIDs independently. --- bridge/cutter/rea_bridge.py | 20 +++++++++---- bridge/cutter/test_private_acl.py | 49 +++++++++++++++++++++++++++++++ native/windows/src/filesystem.cc | 10 +++++-- 3 files changed, 70 insertions(+), 9 deletions(-) create mode 100644 bridge/cutter/test_private_acl.py diff --git a/bridge/cutter/rea_bridge.py b/bridge/cutter/rea_bridge.py index 3529e0ec7bf..87e259fe2a6 100644 --- a/bridge/cutter/rea_bridge.py +++ b/bridge/cutter/rea_bridge.py @@ -283,6 +283,17 @@ def _windows_user_sid_text() -> str: kernel32.CloseHandle(token) +def _record_private_acl_trustee( + expected_user: str, sid: str, user_allowed: bool, system_allowed: bool +) -> tuple[bool, bool]: + """Record one ACE. The current user can be SYSTEM, so one ACE can set both.""" + is_user = sid == expected_user + is_system = sid == "S-1-5-18" + if not is_user and not is_system: + raise RuntimeError("Cutter bridge ACL allows an unrelated principal") + return user_allowed or is_user, system_allowed or is_system + + def _verify_windows_private_path(path: Path, directory: bool) -> None: kernel32, advapi32 = _windows_api() attributes = kernel32.GetFileAttributesW(str(path)) @@ -370,12 +381,9 @@ def _verify_windows_private_path(path: Path, directory: bool) -> None: if not advapi32.ConvertSidToStringSidW(sid_pointer, ctypes.byref(sid_text)): raise ctypes.WinError(ctypes.get_last_error()) try: - if sid_text.value == expected_user: - user_allowed = True - elif sid_text.value == "S-1-5-18": - system_allowed = True - else: - raise RuntimeError("Cutter bridge ACL allows an unrelated principal") + user_allowed, system_allowed = _record_private_acl_trustee( + expected_user, sid_text.value, user_allowed, system_allowed + ) finally: kernel32.LocalFree(sid_text) if not user_allowed or not system_allowed: diff --git a/bridge/cutter/test_private_acl.py b/bridge/cutter/test_private_acl.py new file mode 100644 index 00000000000..c1046755d41 --- /dev/null +++ b/bridge/cutter/test_private_acl.py @@ -0,0 +1,49 @@ +"""The private ACL accepts SYSTEM when that SID is also the process user.""" + +import importlib.util +import os +import sys +import types +import unittest + + +def _install_host_stubs(): + cutter = types.ModuleType("cutter") + cutter.CutterPlugin = type("CutterPlugin", (), {}) + sys.modules["cutter"] = cutter + qtcore = types.ModuleType("PySide6.QtCore") + qtcore.QObject = type("QObject", (), {}) + qtcore.Signal = lambda *_args: types.SimpleNamespace(connect=lambda _handler: None) + qtcore.QCoreApplication = types.SimpleNamespace(applicationVersion=lambda: "Cutter test host") + pyside = types.ModuleType("PySide6") + pyside.QtCore = qtcore + sys.modules["PySide6"] = pyside + sys.modules["PySide6.QtCore"] = qtcore + + +_install_host_stubs() +spec = importlib.util.spec_from_file_location( + "rea_cutter_bridge_acl", os.path.join(os.path.dirname(__file__), "rea_bridge.py") +) +bridge = importlib.util.module_from_spec(spec) +spec.loader.exec_module(bridge) + + +class PrivateAclTrusteeTests(unittest.TestCase): + def test_system_user_satisfies_both_trustees(self): + user, system = bridge._record_private_acl_trustee("S-1-5-18", "S-1-5-18", False, False) + self.assertEqual((user, system), (True, True)) + + def test_distinct_user_and_system_stay_separate(self): + user, system = bridge._record_private_acl_trustee("S-1-5-21-1", "S-1-5-21-1", False, False) + self.assertEqual((user, system), (True, False)) + user, system = bridge._record_private_acl_trustee("S-1-5-21-1", "S-1-5-18", user, system) + self.assertEqual((user, system), (True, True)) + + def test_unrelated_principal_is_rejected(self): + with self.assertRaisesRegex(RuntimeError, "unrelated principal"): + bridge._record_private_acl_trustee("S-1-5-21-1", "S-1-5-21-2", False, False) + + +if __name__ == "__main__": + unittest.main() diff --git a/native/windows/src/filesystem.cc b/native/windows/src/filesystem.cc index 02e8e943d3f..59d51deb236 100644 --- a/native/windows/src/filesystem.cc +++ b/native/windows/src/filesystem.cc @@ -263,9 +263,13 @@ static void verifyPrivate(HANDLE handle, const std::wstring& path, bool root) { (OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE)), "Private DACL contains unsupported rights or ACE type", path, ERROR_ACCESS_DENIED); PSID sid = const_cast(&ace->SidStart); - if (EqualSid(sid, expected.userSid())) user = true; - else if (EqualSid(sid, expected.system.data())) system = true; - else throw Failure("Private DACL permits an unrelated principal", path, ERROR_ACCESS_DENIED); + // The process user can be SYSTEM. That one ACE meets both trustee checks. + const bool isUser = EqualSid(sid, expected.userSid()) == TRUE; + const bool isSystem = EqualSid(sid, expected.system.data()) == TRUE; + if (!isUser && !isSystem) + throw Failure("Private DACL permits an unrelated principal", path, ERROR_ACCESS_DENIED); + if (isUser) user = true; + if (isSystem) system = true; } require(user && system, "Private DACL must allow only current user and SYSTEM", path, ERROR_ACCESS_DENIED); }