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.
This commit is contained in:
Adolanium authored and GitHub committed 2026-11-26 13:14:46 -05:00
1 parent 04cb70c1a3
commit 62a4bee42c
3 files changed
+70 -9

No files matched your search

+14 -6
View File
@@ -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:
+49
View File
@@ -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()
+7 -3
View File
@@ -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<DWORD*>(&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);
}