The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(windows): create protected token descriptors on ARM64
ethernet5093154cef82
diff --git a/hermes_cli/windows_ssh_runtime.py b/hermes_cli/windows_ssh_runtime.pyindex 2114cd59d46..3580c3c0c28 100644--- a/hermes_cli/windows_ssh_runtime.py+++ b/hermes_cli/windows_ssh_runtime.py@@ -87,17 +87,12 @@ def _sid_str(sid) -> str:def _security_attributes():- w = _win32()- ntsecuritycon, win32security = w.ntsecuritycon, w.win32security- owner = _current_sid()- acl = win32security.ACL()- for sid in (owner, _system_sid()):- acl.AddAccessAllowedAceEx(win32security.ACL_REVISION, 0, ntsecuritycon.FILE_ALL_ACCESS, sid)- descriptor = win32security.SECURITY_DESCRIPTOR()- descriptor.SetSecurityDescriptorOwner(owner, False)- descriptor.SetSecurityDescriptorDacl(True, acl, False)- # Protect the DACL so inheritable parent ACEs (%LOCALAPPDATA% grants) are not merged in.- descriptor.SetSecurityDescriptorControl(win32security.SE_DACL_PROTECTED, win32security.SE_DACL_PROTECTED)+ win32security = _win32().win32security+ owner = _sid_str(_current_sid())+ # D:P blocks inherited grants at creation. SDDL also avoids pywin32 311's+ # SetSecurityDescriptorControl argument-width bug on ARM64.+ descriptor = win32security.ConvertStringSecurityDescriptorToSecurityDescriptor(+ f"O:{owner}D:P(A;;FA;;;{owner})(A;;FA;;;SY)", win32security.SDDL_REVISION_1)attributes = win32security.SECURITY_ATTRIBUTES()attributes.SECURITY_DESCRIPTOR = descriptorreturn attributesdiff --git a/tests/gateway/test_host_rendezvous_windows.py b/tests/gateway/test_host_rendezvous_windows.pyindex 9f2dba149c4..f3ee20df41e 100644--- a/tests/gateway/test_host_rendezvous_windows.py+++ b/tests/gateway/test_host_rendezvous_windows.py@@ -21,42 +21,56 @@ def host_dir(tmp_path, monkeypatch):hr.release_host_lock(hr.ROLE_SERVE)-def _allowed_sids():- from hermes_cli import windows_ssh_runtime as wsr-- return wsr._allowed_sids()---def test_host_token_is_written_with_a_protected_owner_only_dacl(host_dir):- """Owner+SYSTEM only, and the DACL is protected so inheritable parent grants are not merged."""+def _assert_private_dacl(path):+ import ntsecurityconimport win32securityfrom hermes_cli import windows_ssh_runtime as wsr- assert hr.claim_host_lock(hr.ROLE_SERVE)[0] is hr.HostLockOutcome.ACQUIRED- hr.publish_record(hr.ROLE_SERVE, host="127.0.0.1", port=9119, token="live-session-token")-- path = hr.token_path(hr.ROLE_SERVE)- assert path.read_text(encoding="utf-8").strip() == "live-session-token"descriptor = win32security.GetFileSecurity(str(path), win32security.OWNER_SECURITY_INFORMATION | win32security.DACL_SECURITY_INFORMATION)- allowed = _allowed_sids()- assert wsr._sid_str(descriptor.GetSecurityDescriptorOwner()) in allowed+ assert wsr._sid_str(descriptor.GetSecurityDescriptorOwner()) == wsr._sid_str(wsr._current_sid())dacl = descriptor.GetSecurityDescriptorDacl()assert dacl is not None, "a null DACL grants everyone"+ granted = set()for index in range(dacl.GetAceCount()):ace = dacl.GetAce(index)- assert wsr._sid_str(ace[-1]) in allowed+ assert ace[0] == (win32security.ACCESS_ALLOWED_ACE_TYPE, 0)+ assert ace[1] == ntsecuritycon.FILE_ALL_ACCESS+ granted.add(wsr._sid_str(ace[-1]))+ assert granted == wsr._allowed_sids()assert descriptor.GetSecurityDescriptorControl()[0] & win32security.SE_DACL_PROTECTED+def test_host_token_is_written_with_a_protected_owner_only_dacl(host_dir):+ """Owner+SYSTEM only, and the DACL is protected so inheritable parent grants are not merged."""+ assert hr.claim_host_lock(hr.ROLE_SERVE)[0] is hr.HostLockOutcome.ACQUIRED+ hr.publish_record(hr.ROLE_SERVE, host="127.0.0.1", port=9119, token="live-session-token")++ path = hr.token_path(hr.ROLE_SERVE)+ assert path.read_text(encoding="utf-8-sig").strip() == "live-session-token"+ _assert_private_dacl(path)++def test_rewriting_an_existing_token_keeps_it_private(host_dir):- """CreateFile ignores the security descriptor on an existing file, and ``os.replace`` fails- against an open reader — the writer replaces in place instead of inheriting either bug."""+ """CreateFile ignores creation security on existing files; replacement must repair old grants."""+ import ntsecuritycon+ import win32security+assert hr.claim_host_lock(hr.ROLE_SERVE)[0] is hr.HostLockOutcome.ACQUIREDhr.publish_record(hr.ROLE_SERVE, host="127.0.0.1", port=9119, token="first")+ path = hr.token_path(hr.ROLE_SERVE)+ permissive = win32security.ACL()+ permissive.AddAccessAllowedAceEx(+ win32security.ACL_REVISION, 0, ntsecuritycon.FILE_ALL_ACCESS,+ win32security.ConvertStringSidToSid("S-1-1-0"))+ win32security.SetNamedSecurityInfo(+ str(path), win32security.SE_FILE_OBJECT, win32security.DACL_SECURITY_INFORMATION,+ None, None, permissive, None)+hr.publish_record(hr.ROLE_SERVE, host="127.0.0.1", port=9119, token="second")assert hr.read_token(hr.ROLE_SERVE) == "second"+ _assert_private_dacl(path)record = hr.read_record(hr.ROLE_SERVE, include_stale=True)assert record is not None and hr.record_token_is_consistent(record)diff --git a/tests/hermes_cli/test_legacy_launchers_windows_live.py b/tests/hermes_cli/test_legacy_launchers_windows_live.pyindex 268bc875d81..b1123898ec9 100644--- a/tests/hermes_cli/test_legacy_launchers_windows_live.py+++ b/tests/hermes_cli/test_legacy_launchers_windows_live.py@@ -16,7 +16,8 @@ import hermes_cli.gateway_windows as gateway_windows@pytest.mark.platforms("windows")def test_status_warns_and_uninstall_removes_pre_suffix_launchers(tmp_path, monkeypatch, capsys):- home = tmp_path / "hermes"+ # The shared isolation fixture uses tmp_path / "hermes" as the Windows native default.+ home = tmp_path / "custom-hermes"(home / "gateway-service").mkdir(parents=True)monkeypatch.setenv("HERMES_HOME", str(home))appdata = tmp_path / "AppData" / "Roaming"