Skip to content

Commit 076c8ae

Browse files
authored
Merge pull request DeusData#1623 from DeusData/fix/ancestor-appcontainer-sids
fix(windows): tolerate AppContainer SIDs on ancestors, keep the runtime dir strict
2 parents 995760b + 9b5555a commit 076c8ae

2 files changed

Lines changed: 73 additions & 9 deletions

File tree

‎src/daemon/ipc.c‎

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3987,8 +3987,45 @@ static bool win_sid_trusted(win_security_t *security, PSID sid) {
39873987
win_sid_is_trusted_installer((const uint8_t *)sid, (size_t)sid_length);
39883988
}
39893989

3990+
/* AppContainer identities: package SIDs (S-1-15-2-*) and capability SIDs
3991+
* (S-1-15-3-*), under the APP_PACKAGE identifier authority (15).
3992+
*
3993+
* These are tolerated on ANCESTOR components only — never on the private
3994+
* runtime directory itself, which keeps demanding the exact current user.
3995+
*
3996+
* Why they are admissible there: a sandboxed package's ACE on %LOCALAPPDATA%
3997+
* grants that package, and a process cannot select which AppContainer it runs
3998+
* in — the identity is stamped by the OS at process creation from the package
3999+
* it was launched from. So such an ACE cannot be exercised by arbitrary local
4000+
* code the way a live local group can. What it does permit is the packaged
4001+
* application itself; that is the residual risk this exemption accepts, and it
4002+
* is the same trust already extended to whatever installed that package.
4003+
*
4004+
* Why BOTH forms: capability SIDs alone are not enough. The most common real
4005+
* ACE of this shape is `S-1-15-2-*` — a package SID. On reported machines it
4006+
* resolves through HKCR\...\AppContainer\Mappings to Anthropic Claude
4007+
* Desktop, an application many of our users run and cannot be asked to
4008+
* uninstall. Covering only S-1-15-3-* leaves exactly that case failing.
4009+
*
4010+
* Grounded in #1533 (four independent reproductions across four SID classes)
4011+
* and #1574. Approach and the ancestor-only boundary follow @mlandolfi90's
4012+
* PR #1447, extended to package SIDs. */
4013+
static bool win_sid_is_app_container(const uint8_t *sid, size_t sid_length) {
4014+
if (!windows_sid_valid(sid, sid_length) || sid[1] < 1U) {
4015+
return false;
4016+
}
4017+
/* identifier authority must be exactly 15 (APP_PACKAGE_AUTHORITY) */
4018+
if (sid[2] != 0U || sid[3] != 0U || sid[4] != 0U || sid[5] != 0U || sid[6] != 0U ||
4019+
sid[7] != 15U) {
4020+
return false;
4021+
}
4022+
uint32_t first = win_sid_read_u32_le(sid + 8U);
4023+
return first == 2U || first == 3U;
4024+
}
4025+
39904026
static bool win_bounded_sid_trusted(win_security_t *security, const uint8_t *sid,
3991-
size_t sid_capacity, bool creator_owner_inherit_only) {
4027+
size_t sid_capacity, bool creator_owner_inherit_only,
4028+
bool ancestor) {
39924029
if (!security || !sid || sid_capacity < 8U || sid[1] > 15U) {
39934030
return false;
39944031
}
@@ -4004,7 +4041,8 @@ static bool win_bounded_sid_trusted(win_security_t *security, const uint8_t *sid
40044041
* user, so such an ACE only ever grants to us. Default Windows
40054042
* profile/temp ACLs (and GitHub runner profiles) carry it, and
40064043
* rejecting it locked real current-user directories out. */
4007-
security->is_well_known_sid((PSID)sid, WinCreatorOwnerRightsSid));
4044+
security->is_well_known_sid((PSID)sid, WinCreatorOwnerRightsSid) ||
4045+
(ancestor && win_sid_is_app_container(sid, sid_length)));
40084046
}
40094047

40104048
static bool win_file_owner_secure(win_security_t *security, HANDLE file,
@@ -4039,7 +4077,8 @@ static DWORD win_private_mutation_rights(void) {
40394077
DELETE | WRITE_DAC | WRITE_OWNER | ACCESS_SYSTEM_SECURITY;
40404078
}
40414079

4042-
static bool win_file_acl_secure(win_security_t *security, HANDLE file, DWORD mutation) {
4080+
static bool win_file_acl_secure(win_security_t *security, HANDLE file, DWORD mutation,
4081+
bool ancestor) {
40434082
PACL dacl = NULL;
40444083
PSECURITY_DESCRIPTOR descriptor = NULL;
40454084
DWORD status = security->get_security_info(file, SE_FILE_OBJECT, DACL_SECURITY_INFORMATION,
@@ -4080,7 +4119,8 @@ static bool win_file_acl_secure(win_security_t *security, HANDLE file, DWORD mut
40804119
const uint8_t *sid = (const uint8_t *)&ace->SidStart;
40814120
size_t sid_capacity = (size_t)header->AceSize - sid_offset;
40824121
bool creator_owner_inherit_only = (header->AceFlags & INHERIT_ONLY_ACE) != 0U;
4083-
if (!win_bounded_sid_trusted(security, sid, sid_capacity, creator_owner_inherit_only)) {
4122+
if (!win_bounded_sid_trusted(security, sid, sid_capacity, creator_owner_inherit_only,
4123+
ancestor)) {
40844124
/* Name the untrusted identity class so a harness/profile ACL leak
40854125
* (an inherited Users / Authenticated Users / Everyone ACE) is
40864126
* distinguishable from a genuinely hostile grant. */
@@ -4113,9 +4153,9 @@ static bool win_file_acl_secure(win_security_t *security, HANDLE file, DWORD mut
41134153
}
41144154

41154155
static bool win_file_security_secure(win_security_t *security, HANDLE file,
4116-
bool require_current_user, DWORD mutation) {
4156+
bool require_current_user, DWORD mutation, bool ancestor) {
41174157
return win_file_owner_secure(security, file, require_current_user) &&
4118-
win_file_acl_secure(security, file, mutation);
4158+
win_file_acl_secure(security, file, mutation, ancestor);
41194159
}
41204160

41214161
static bool win_runtime_directory_secure(const wchar_t *runtime_dir) {
@@ -4179,7 +4219,7 @@ static bool win_runtime_directory_secure(const wchar_t *runtime_dir) {
41794219
}
41804220
bool final_private =
41814221
secure_result == ERROR_SUCCESS &&
4182-
win_file_security_secure(&security, directory, true, win_private_mutation_rights());
4222+
win_file_security_secure(&security, directory, true, win_private_mutation_rights(), false);
41834223
(void)CloseHandle(directory);
41844224
win_security_destroy(&security);
41854225
return valid_handle && owner_ok && final_private;
@@ -4202,7 +4242,7 @@ static bool win_directory_component_secure(win_security_t *security, const wchar
42024242
bool valid = GetFileInformationByHandle(directory, &info) != 0 &&
42034243
(info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0 &&
42044244
(info.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) == 0 &&
4205-
win_file_security_secure(security, directory, false, mutation);
4245+
win_file_security_secure(security, directory, false, mutation, true);
42064246
(void)CloseHandle(directory);
42074247
return valid;
42084248
}

‎tests/test_windows_bundle_contract.sh‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ require(
415415
needle in read("src/daemon/ipc.c")
416416
for needle in (
417417
"win_directory_component_secure",
418-
"win_file_security_secure(security, directory, false, mutation)",
418+
"win_file_security_secure(security, directory, false, mutation, true)",
419419
"win_private_mutation_rights()",
420420
"~((DWORD)FILE_ADD_SUBDIRECTORY)",
421421
"FILE_ADD_FILE",
@@ -429,6 +429,30 @@ require(
429429
"src/daemon/ipc.c must enforce the shared cross-account ancestor trust policy",
430430
)
431431
432+
# ── 6b. AppContainer tolerance is ANCESTOR-ONLY ─────────────────────────────
433+
# Package (S-1-15-2-*) and capability (S-1-15-3-*) SIDs are admitted on ancestor
434+
# components so a machine running a sandboxed desktop app (Claude Desktop stamps
435+
# its package SID on %LOCALAPPDATA%) is not locked out. The private runtime
436+
# directory must keep demanding the exact current user: it is passed
437+
# ancestor=false and that is the whole boundary.
438+
require(
439+
all(
440+
needle in read("src/daemon/ipc.c")
441+
for needle in (
442+
"win_sid_is_app_container",
443+
"ancestor && win_sid_is_app_container",
444+
# both AppContainer forms, not capability alone
445+
"first == 2U || first == 3U",
446+
# APP_PACKAGE identifier authority
447+
"sid[7] != 15U",
448+
# the private runtime directory is validated with ancestor=false
449+
"win_private_mutation_rights(), false)",
450+
)
451+
),
452+
"AppContainer SIDs must be tolerated on ancestors ONLY, covering both package "
453+
"and capability forms, with the private runtime directory still strict",
454+
)
455+
432456
# On Windows subprocess supervision receives a non-NULL lpApplicationName, so a
433457
# literal `git` would not use PATH. Resolve only git.exe beneath inherited
434458
# absolute PATH entries and never permit the current-directory search implied by

0 commit comments

Comments
 (0)