@@ -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+
39904026static 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
40104048static 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
41154155static 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
41214161static 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}
0 commit comments