Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.
C aiderastclaude-codecode-analysiscode-intelligencecodexcursorcypherdeveloper-toolsgemini-cligraph-visualizationkilocodeknowledge-graphmcpmcp-servermodel-context-protocolopencodesqlitetree-sitterwindsurf
fix: support standard Windows profile ACLs
Martin Vogel89c7c98f0072
diff --git a/src/cli/windows_launcher_state.c b/src/cli/windows_launcher_state.cindex 91af10f87..0c5746e45 100644--- a/src/cli/windows_launcher_state.c+++ b/src/cli/windows_launcher_state.c@@ -585,7 +585,13 @@ static bool windows_owner_is_current(HANDLE file) {return windows_owner_secure(file, true);}-static bool windows_acl_secure(HANDLE file) {+static DWORD windows_private_mutation_rights(void) {+ return GENERIC_ALL | GENERIC_WRITE | FILE_WRITE_DATA | FILE_APPEND_DATA | FILE_ADD_FILE |+ FILE_ADD_SUBDIRECTORY | FILE_DELETE_CHILD | FILE_WRITE_EA | FILE_WRITE_ATTRIBUTES |+ DELETE | WRITE_DAC | WRITE_OWNER | ACCESS_SYSTEM_SECURITY;+}++static bool windows_acl_secure_for_mutation(HANDLE file, DWORD mutation) {HANDLE token = NULL;DWORD token_size = 0U;PTOKEN_USER user = NULL;@@ -604,10 +610,6 @@ static bool windows_acl_secure(HANDLE file) {memset(&information, 0, sizeof(information));secure = secure && status == ERROR_SUCCESS && descriptor && dacl && IsValidAcl(dacl) != 0 &&GetAclInformation(dacl, &information, sizeof(information), AclSizeInformation) != 0;- const DWORD mutation = GENERIC_ALL | GENERIC_WRITE | FILE_WRITE_DATA | FILE_APPEND_DATA |- FILE_ADD_FILE | FILE_ADD_SUBDIRECTORY | FILE_DELETE_CHILD |- FILE_WRITE_EA | FILE_WRITE_ATTRIBUTES | DELETE | WRITE_DAC |- WRITE_OWNER | ACCESS_SYSTEM_SECURITY;enum {CBM_ACE_ALLOW = 0x00,CBM_ACE_DENY = 0x01,@@ -649,6 +651,10 @@ static bool windows_acl_secure(HANDLE file) {return secure;}+static bool windows_acl_secure(HANDLE file) {+ return windows_acl_secure_for_mutation(file, windows_private_mutation_rights());+}+static bool windows_path_tree_plain(const wchar_t *file_path) {size_t length = file_path ? wcslen(file_path) : 0U;if (length < 4U || length >= CBM_WINDOWS_LAUNCHER_PATH_CAP || file_path[1] != L':' ||@@ -682,11 +688,19 @@ static bool windows_path_tree_plain(const wchar_t *file_path) {FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING,FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, NULL);BY_HANDLE_FILE_INFORMATION information;+ DWORD mutation = windows_private_mutation_rights();+ if (index < directory_length) {+ /* Default C:\\Users ACLs allow sibling-directory creation. That+ * cannot replace the existing next component. The executable's+ * immediate parent remains fully private. */+ mutation &= ~((DWORD)FILE_ADD_SUBDIRECTORY);+ }valid = component != INVALID_HANDLE_VALUE && GetFileType(component) == FILE_TYPE_DISK &&GetFileInformationByHandle(component, &information) != 0 &&(information.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0 &&(information.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) == 0 &&- windows_owner_secure(component, false) && windows_acl_secure(component);+ windows_owner_secure(component, false) &&+ windows_acl_secure_for_mutation(component, mutation);if (component != INVALID_HANDLE_VALUE)(void)CloseHandle(component);path[index] = saved;@@ -1693,15 +1707,23 @@ static bool windows_prepare_probe_directory(const wchar_t *target,DWORD attributes = GetFileAttributesW(cursor);if (attributes != INVALID_FILE_ATTRIBUTES) {HANDLE ancestor = CreateFileW(- cursor, FILE_READ_ATTRIBUTES,+ cursor, FILE_READ_ATTRIBUTES | READ_CONTROL,FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING,FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, NULL);BY_HANDLE_FILE_INFORMATION information;+ DWORD mutation = windows_private_mutation_rights();+ if (created->count > 0U) {+ /* Only a missing descendant will be created below this+ * existing ancestor; sibling-directory creation is sufficient+ * and cannot replace an existing component. */+ mutation &= ~((DWORD)FILE_ADD_SUBDIRECTORY);+ }valid = ancestor != INVALID_HANDLE_VALUE && GetFileType(ancestor) == FILE_TYPE_DISK &&GetFileInformationByHandle(ancestor, &information) != 0 &&(information.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0 &&(information.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) == 0 &&- windows_owner_secure(ancestor, false) && windows_acl_secure(ancestor);+ windows_owner_secure(ancestor, false) &&+ windows_acl_secure_for_mutation(ancestor, mutation);if (ancestor != INVALID_HANDLE_VALUE)(void)CloseHandle(ancestor);break;diff --git a/src/daemon/ipc.c b/src/daemon/ipc.cindex f0653136d..abfb6d910 100644--- a/src/daemon/ipc.c+++ b/src/daemon/ipc.c@@ -3840,7 +3840,13 @@ static bool win_file_owner_secure(win_security_t *security, HANDLE file,return secure;}-static bool win_file_acl_secure(win_security_t *security, HANDLE file) {+static DWORD win_private_mutation_rights(void) {+ return GENERIC_ALL | GENERIC_WRITE | FILE_WRITE_DATA | FILE_APPEND_DATA | FILE_ADD_FILE |+ FILE_ADD_SUBDIRECTORY | FILE_DELETE_CHILD | FILE_WRITE_EA | FILE_WRITE_ATTRIBUTES |+ DELETE | WRITE_DAC | WRITE_OWNER | ACCESS_SYSTEM_SECURITY;+}++static bool win_file_acl_secure(win_security_t *security, HANDLE file, DWORD mutation) {PACL dacl = NULL;PSECURITY_DESCRIPTOR descriptor = NULL;DWORD status = security->get_security_info(file, SE_FILE_OBJECT, DACL_SECURITY_INFORMATION,@@ -3850,10 +3856,6 @@ static bool win_file_acl_secure(win_security_t *security, HANDLE file) {bool secure =status == ERROR_SUCCESS && descriptor && dacl && security->is_valid_acl(dacl) &&security->get_acl_information(dacl, &information, sizeof(information), AclSizeInformation);- const DWORD mutation = GENERIC_ALL | GENERIC_WRITE | FILE_WRITE_DATA | FILE_APPEND_DATA |- FILE_ADD_FILE | FILE_ADD_SUBDIRECTORY | FILE_DELETE_CHILD |- FILE_WRITE_EA | FILE_WRITE_ATTRIBUTES | DELETE | WRITE_DAC |- WRITE_OWNER | ACCESS_SYSTEM_SECURITY;enum {WIN_FILE_ACE_ALLOW = 0x00,WIN_FILE_ACE_DENY = 0x01,@@ -3896,9 +3898,9 @@ static bool win_file_acl_secure(win_security_t *security, HANDLE file) {}static bool win_file_security_secure(win_security_t *security, HANDLE file,- bool require_current_user) {+ bool require_current_user, DWORD mutation) {return win_file_owner_secure(security, file, require_current_user) &&- win_file_acl_secure(security, file);+ win_file_acl_secure(security, file, mutation);}static bool win_runtime_directory_secure(const wchar_t *runtime_dir) {@@ -3938,7 +3940,8 @@ static bool win_runtime_directory_secure(const wchar_t *runtime_dir) {NULL, NULL, security.acl, NULL);}bool final_private =- secure_result == ERROR_SUCCESS && win_file_security_secure(&security, directory, true);+ secure_result == ERROR_SUCCESS &&+ win_file_security_secure(&security, directory, true, win_private_mutation_rights());(void)CloseHandle(directory);win_security_destroy(&security);return valid_handle && owner_ok && final_private;@@ -3953,10 +3956,15 @@ static bool win_directory_component_secure(win_security_t *security, const wcharreturn false;}BY_HANDLE_FILE_INFORMATION info;+ /* Default Windows profile ancestors grant cross-account add-subdirectory.+ * That permits siblings but cannot replace the existing next path+ * component. Keep every other mutation right forbidden; the final runtime+ * directory is separately owner-validated and given a protected DACL. */+ DWORD mutation = win_private_mutation_rights() & ~((DWORD)FILE_ADD_SUBDIRECTORY);bool valid = GetFileInformationByHandle(directory, &info) != 0 &&(info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0 &&(info.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) == 0 &&- win_file_security_secure(security, directory, false);+ win_file_security_secure(security, directory, false, mutation);(void)CloseHandle(directory);return valid;}diff --git a/tests/test_cli.c b/tests/test_cli.cindex 3e60fe103..cd517b72f 100644--- a/tests/test_cli.c+++ b/tests/test_cli.c@@ -1390,34 +1390,12 @@ TEST(cli_update_agent_configs_finish_before_guard_release) {char codex_dir[512];char codex_config[640];char release_dir[512];- char archive_path[768];- char checksum_path[640];snprintf(codex_dir, sizeof(codex_dir), "%s/.codex", tmpdir);snprintf(codex_config, sizeof(codex_config), "%s/config.toml", codex_dir);snprintf(release_dir, sizeof(release_dir), "%s/release", tmpdir);test_mkdirp(codex_dir);test_mkdirp(release_dir);-#if defined(__APPLE__)-#if defined(__aarch64__) || defined(__arm64__)- const char *asset_name = "codebase-memory-mcp-darwin-arm64.tar.gz";-#else- const char *asset_name = "codebase-memory-mcp-darwin-amd64.tar.gz";-#endif-#elif defined(_WIN32)-#if defined(_M_ARM64)- const char *asset_name = "codebase-memory-mcp-windows-arm64.zip";-#else- const char *asset_name = "codebase-memory-mcp-windows-amd64.zip";-#endif-#else-#if defined(__aarch64__)- const char *asset_name = "codebase-memory-mcp-linux-arm64-portable.tar.gz";-#else- const char *asset_name = "codebase-memory-mcp-linux-amd64-portable.tar.gz";-#endif-#endif-#ifdef _WIN32/* The existing ZIP fixture helper is intentionally exercised elsewhere;* this activation-window regression uses the tar update path. */@@ -1431,6 +1409,21 @@ TEST(cli_update_agent_configs_finish_before_guard_release) {test_rmdir_r(tmpdir);PASS();#else+ char archive_path[768];+ char checksum_path[640];+#if defined(__APPLE__)+#if defined(__aarch64__) || defined(__arm64__)+ const char *asset_name = "codebase-memory-mcp-darwin-arm64.tar.gz";+#else+ const char *asset_name = "codebase-memory-mcp-darwin-amd64.tar.gz";+#endif+#else+#if defined(__aarch64__)+ const char *asset_name = "codebase-memory-mcp-linux-arm64-portable.tar.gz";+#else+ const char *asset_name = "codebase-memory-mcp-linux-amd64-portable.tar.gz";+#endif+#endifconst char *native_fixture =#ifdef __APPLE__"/usr/bin/true";diff --git a/tests/test_daemon_ipc.c b/tests/test_daemon_ipc.cindex 2bc2b074d..d1a0edadc 100644--- a/tests/test_daemon_ipc.c+++ b/tests/test_daemon_ipc.c@@ -58,7 +58,9 @@enum { TEST_PATH_CAP = 1024 };+#ifndef _WIN32static bool ipc_test_write_byte(const char *path, unsigned char byte);+#endifstatic bool ipc_test_parent_new(char out[TEST_PATH_CAP], const char *tag) {int n = snprintf(out, TEST_PATH_CAP, "%s/cbm-ipc-%s-XXXXXX", cbm_tmpdir(), tag);@@ -289,7 +291,7 @@ typedef struct {bool present;} ipc_test_win_env_t;-static bool ipc_test_win_grant_everyone_mutation(const char *path) {+static bool ipc_test_win_grant_everyone_rights(const char *path, DWORD rights) {wchar_t *wide_path = cbm_utf8_to_wide(path);BYTE world_buffer[SECURITY_MAX_SID_SIZE];DWORD world_size = sizeof(world_buffer);@@ -301,8 +303,7 @@ static bool ipc_test_win_grant_everyone_mutation(const char *path) {NULL, &existing, NULL, &descriptor) == ERROR_SUCCESS;EXPLICIT_ACCESSW access;memset(&access, 0, sizeof(access));- access.grfAccessPermissions = FILE_ADD_FILE | FILE_ADD_SUBDIRECTORY | FILE_DELETE_CHILD |- DELETE | WRITE_DAC | WRITE_OWNER;+ access.grfAccessPermissions = rights;access.grfAccessMode = GRANT_ACCESS;access.grfInheritance = NO_INHERITANCE;access.Trustee.TrusteeForm = TRUSTEE_IS_SID;@@ -325,6 +326,12 @@ static bool ipc_test_win_grant_everyone_mutation(const char *path) {return ok;}+static bool ipc_test_win_grant_everyone_mutation(const char *path) {+ return ipc_test_win_grant_everyone_rights(path, FILE_ADD_FILE | FILE_ADD_SUBDIRECTORY |+ FILE_DELETE_CHILD | DELETE | WRITE_DAC |+ WRITE_OWNER);+}+static bool ipc_test_win_env_capture(const wchar_t *name, ipc_test_win_env_t *saved) {if (!name || !saved) {return false;@@ -737,6 +744,48 @@ TEST(daemon_ipc_windows_private_directory_rejects_untrusted_ancestor_acl) {PASS();}+TEST(daemon_ipc_windows_private_directory_allows_add_subdirectory_only_ancestor) {+ char parent[TEST_PATH_CAP] = {0};+ char add_only[TEST_PATH_CAP] = {0};+ char cache[TEST_PATH_CAP] = {0};+ bool paths_ok = false;+ bool ancestor_created = false;+ bool acl_injected = false;+ bool secured = false;+ bool cache_created = false;++ if (ipc_test_parent_new(parent, "win-add-only-ancestor")) {+ int ancestor_written = snprintf(add_only, sizeof(add_only), "%s/add-only", parent);+ int cache_written = snprintf(cache, sizeof(cache), "%s/cache", add_only);+ paths_ok = ancestor_written > 0 && ancestor_written < (int)sizeof(add_only) &&+ cache_written > 0 && cache_written < (int)sizeof(cache);+ }+ if (paths_ok) {+ ancestor_created = CreateDirectoryA(add_only, NULL) != 0;+ }+ if (ancestor_created) {+ acl_injected = ipc_test_win_grant_everyone_rights(add_only, FILE_ADD_SUBDIRECTORY);+ }+ if (acl_injected) {+ secured = cbm_daemon_ipc_private_directory_secure(cache);+ DWORD attributes = GetFileAttributesA(cache);+ cache_created = attributes != INVALID_FILE_ATTRIBUTES &&+ (attributes & FILE_ATTRIBUTE_DIRECTORY) != 0 &&+ (attributes & FILE_ATTRIBUTE_REPARSE_POINT) == 0;+ }++ (void)RemoveDirectoryA(cache);+ (void)RemoveDirectoryA(add_only);+ ipc_test_remove_flat_dir(parent);++ ASSERT_TRUE(paths_ok);+ ASSERT_TRUE(ancestor_created);+ ASSERT_TRUE(acl_injected);+ ASSERT_TRUE(secured);+ ASSERT_TRUE(cache_created);+ PASS();+}+TEST(daemon_ipc_windows_legacy_bridge_covers_handoff_and_lifetime) {static const char key[] = "91a2b3c4d5e6f708";char parent[TEST_PATH_CAP] = {0};@@ -4504,6 +4553,7 @@ SUITE(daemon_ipc) {#ifdef _WIN32RUN_TEST(daemon_ipc_windows_default_endpoint_ignores_temp_environment);RUN_TEST(daemon_ipc_windows_private_directory_rejects_untrusted_ancestor_acl);+ RUN_TEST(daemon_ipc_windows_private_directory_allows_add_subdirectory_only_ancestor);RUN_TEST(daemon_ipc_windows_legacy_bridge_covers_handoff_and_lifetime);RUN_TEST(daemon_ipc_windows_local_transition_atomically_reserves_legacy_pipe);RUN_TEST(daemon_ipc_windows_startup_retries_transient_rendezvous_reader);diff --git a/tests/test_daemon_runtime.c b/tests/test_daemon_runtime.cindex 0ceae97ad..9985dc4c5 100644--- a/tests/test_daemon_runtime.c+++ b/tests/test_daemon_runtime.c@@ -89,8 +89,10 @@ _Static_assert(CBM_DAEMON_RUNTIME_OP_ACTIVATION_SHUTDOWN == 8 &&static const char RUNTIME_BUILD_B[] ="bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";+#ifndef _WIN32static const char RUNTIME_CACHE_A[] ="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";+#endifstatic char runtime_self_build[CBM_DAEMON_BUILD_FINGERPRINT_SIZE];static atomic_bool runtime_conflict_log_fallback_seen;static atomic_bool runtime_activation_shutdown_log_seen;diff --git a/tests/test_lock_registry.c b/tests/test_lock_registry.cindex 4c9c29752..05c16d90d 100644--- a/tests/test_lock_registry.c+++ b/tests/test_lock_registry.c@@ -415,6 +415,7 @@ static int lock_registry_abort_bookkeeping_failure_retains_cleanup(ASSERT_EQ(final_free, CBM_PRIVATE_FILE_LOCK_OK);PASS();}+#endifTEST(lock_registry_terminal_close_error_finishes_pending_accounting) {#ifdef _WIN32@@ -472,7 +473,6 @@ TEST(lock_registry_terminal_close_error_finishes_pending_accounting) {PASS();#endif}-#endifTEST(lock_registry_abort_lock_failure_returns_waiter_cleanup_lease) {#ifdef _WIN32diff --git a/tests/test_platform.c b/tests/test_platform.cindex a1001579b..3e1fe2fbf 100644--- a/tests/test_platform.c+++ b/tests/test_platform.c@@ -292,7 +292,7 @@ TEST(platform_setenv_preserves_utf8_in_wide_environment) {* partially initialized paths. */TEST(platform_windows_empty_environment_is_read_and_unset_idempotently) {ASSERT_EQ(cbm_setenv("CBM_CACHE_DIR", "", 1), 0);- char observed[8] = "sentinel";+ char observed[9] = "sentinel";ASSERT_NOT_NULL(cbm_safe_getenv("CBM_CACHE_DIR", observed, sizeof(observed), "fallback"));ASSERT_STR_EQ(observed, "");ASSERT_EQ(cbm_unsetenv("CBM_CACHE_DIR"), 0);diff --git a/tests/test_windows_bundle_contract.sh b/tests/test_windows_bundle_contract.shindex 49e5167f7..caa5cfc31 100644--- a/tests/test_windows_bundle_contract.sh+++ b/tests/test_windows_bundle_contract.sh@@ -418,20 +418,35 @@ require(# Every native path-tree trust boundary must validate opened ancestor handles,# reject reparse points, inspect mutation-capable allow ACEs, and recognize the# bounded privileged-principal set (current user, SYSTEM, Administrators, and-# the fixed TrustedInstaller service SID). The native test injects a real-# Everyone-modify ACE; these static markers keep all three independently linked-# implementations aligned even on non-Windows presubmit hosts.+# the fixed TrustedInstaller service SID). The normal C:\\Users ancestor grants+# cross-account add-subdirectory, so each implementation permits only that+# right on intermediate components while keeping its final private directory+# strict. The native tests inject real ACLs; these static markers preserve the+# narrow exception and its surrounding defenses on non-Windows presubmit hosts.ancestor_security_contracts = {"src/daemon/ipc.c": ("win_directory_component_secure",- "win_file_security_secure(security, directory, false)",+ "win_file_security_secure(security, directory, false, mutation)",+ "win_private_mutation_rights()",+ "~((DWORD)FILE_ADD_SUBDIRECTORY)",+ "FILE_ADD_FILE",+ "FILE_DELETE_CHILD",+ "final runtime","ACCESS_SYSTEM_SECURITY","956008885U","FILE_ATTRIBUTE_REPARSE_POINT",),"src/cli/windows_launcher_state.c": ("windows_owner_secure(component, false)",- "windows_acl_secure(component)",+ "windows_acl_secure_for_mutation(component, mutation)",+ "windows_private_mutation_rights()",+ "if (index < directory_length)",+ "if (created->count > 0U)",+ "mutation &= ~((DWORD)FILE_ADD_SUBDIRECTORY)",+ "FILE_ADD_FILE",+ "FILE_DELETE_CHILD",+ "immediate parent remains fully private",+ "FILE_READ_ATTRIBUTES | READ_CONTROL","ACCESS_SYSTEM_SECURITY","956008885U","FILE_FLAG_OPEN_REPARSE_POINT",diff --git a/tests/windows/test_windows_launcher.py b/tests/windows/test_windows_launcher.pyindex edf0086d8..13d4909ea 100644--- a/tests/windows/test_windows_launcher.py+++ b/tests/windows/test_windows_launcher.py@@ -399,7 +399,9 @@ def assert_untrusted_ancestor_acl_rejected(def assert_add_only_ancestor_acl_allowed(source_launcher, source_payload, env, work):ancestor = work / "cross-account add-only ancestor"- launcher, _ = copy_portable_pair(source_launcher, source_payload, ancestor / "bundle")+ launcher, portable_payload = copy_portable_pair(+ source_launcher, source_payload, ancestor / "bundle"+ )grant = run(["icacls", ancestor, "/grant", "*S-1-1-0:(AD)"], env)require(grant.returncode == 0,@@ -417,13 +419,44 @@ def assert_add_only_ancestor_acl_allowed(source_launcher, source_payload, env, w"%s launcher path treated sibling creation as replacement access: %s"% (spelling, output_text(result)[-600:]),)++ managed_dir = ancestor / "managed install under add-only ancestor"+ install = run(+ [+ portable_payload,+ "install",+ "--yes",+ "--force",+ "--skip-config",+ "--dir",+ managed_dir,+ ],+ env,+ timeout=60,+ )+ require(+ install.returncode == 0,+ "managed install rejected a standard add-subdirectory-only ancestor: %s"+ % output_text(install)[-800:],+ )+ managed_launcher = managed_dir / "codebase-memory-mcp.exe"+ require(managed_launcher.is_file(), "add-only managed install produced no launcher")+ uninstall = run([managed_launcher, "uninstall", "--yes"], env, timeout=60)+ require(+ uninstall.returncode == 0,+ "add-only managed install could not be uninstalled: %s"+ % output_text(uninstall)[-800:],+ )finally:remove = run(["icacls", ancestor, "/remove:g", "*S-1-1-0"], env)require(remove.returncode == 0,"could not remove native Everyone-add-subdirectory ancestor fixture",)- print("PASS: launcher allowed add-only sibling creation without weakening path integrity")+ print(+ "PASS: launcher and managed install allowed add-only sibling creation "+ "without weakening path integrity"+ )def assert_targeted_ancestor_acl_rejected(path, launcher, right, description, env):