mirror of
https://github.com/stablyai/orca.git
synced 2026-11-17 19:34:29 +00:00
* Support Windows native Antigravity account credentials * Preserve Antigravity prompt arguments and sanitize Windows file failures * Preserve Windows credential bytes and distinguish native read failures * Import Buffer type in Windows security declarations * Expose native credential bytes without a Node type dependency * Let Windows agy launches keep shell ownership * fix: declare Windows account messages and cover owner scope * fix: resolve Windows account authority before snapshot projection * fix: share Windows credential parsing with saved account reader * test: type saved account identity lookup mock * test: isolate native account fixture host detection * test: reuse filesystem mock for container marker control * test: preserve native credential contract failure diagnostics * test: normalize private read expectation and cover Windows boundary
68 lines
2.8 KiB
TypeScript
68 lines
2.8 KiB
TypeScript
import { WINDOWS_FILE_ALL_ACCESS, type WindowsDacl } from './windows-security-addon'
|
|
|
|
/** SYSTEM and the local Administrators group: they can take ownership regardless, so denying them buys nothing. */
|
|
export const LOCAL_SYSTEM_SID = 'S-1-5-18'
|
|
export const BUILTIN_ADMINISTRATORS_SID = 'S-1-5-32-544'
|
|
|
|
export const ACCESS_ALLOWED_ACE_TYPE = 0
|
|
export const ACCESS_DENIED_ACE_TYPE = 1
|
|
export const OBJECT_INHERIT_ACE = 0x1
|
|
export const CONTAINER_INHERIT_ACE = 0x2
|
|
export const INHERIT_ONLY_ACE = 0x8
|
|
const GENERIC_ALL = 0x10000000
|
|
|
|
/** Install protected user/SYSTEM/Administrators full control; directory rules inherit so newly created children start restricted. */
|
|
export function hardenedDaclSddl(userSid: string, isDirectory: boolean): string {
|
|
const flags = isDirectory ? 'OICI' : ''
|
|
return `D:P(A;${flags};FA;;;${LOCAL_SYSTEM_SID})(A;${flags};FA;;;${BUILTIN_ADMINISTRATORS_SID})(A;${flags};FA;;;${userSid})`
|
|
}
|
|
|
|
/** Allow only user/SYSTEM/Administrators, require parent-inheritance protection and usable user access.
|
|
* Accept equivalent private legacy DACLs instead of rewriting them to exactly match the current recipe. */
|
|
export function findSecureDaclViolation(
|
|
dacl: WindowsDacl | null,
|
|
userSid: string,
|
|
isDirectory: boolean
|
|
): string | null {
|
|
const privateViolation = findPrivateDaclViolation(dacl, userSid)
|
|
if (privateViolation || !dacl) {
|
|
return privateViolation
|
|
}
|
|
if (!dacl.protected) {
|
|
return 'DACL is not protected; the parent still propagates into it'
|
|
}
|
|
const inheritsToChildren = OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE
|
|
const usable = dacl.aces.some(
|
|
(ace) =>
|
|
ace.type === ACCESS_ALLOWED_ACE_TYPE &&
|
|
ace.sid === userSid &&
|
|
(ace.flags & INHERIT_ONLY_ACE) === 0 &&
|
|
((ace.mask & GENERIC_ALL) !== 0 ||
|
|
(ace.mask & WINDOWS_FILE_ALL_ACCESS) === WINDOWS_FILE_ALL_ACCESS) &&
|
|
(!isDirectory || (ace.flags & inheritsToChildren) === inheritsToChildren)
|
|
)
|
|
return usable ? null : `missing full control for ${userSid}`
|
|
}
|
|
|
|
/** Private CLI files may inherit a private parent; reading must not rewrite their permissions. */
|
|
export function findPrivateDaclViolation(dacl: WindowsDacl | null, userSid: string): string | null {
|
|
if (!dacl) {
|
|
return 'the path has a NULL DACL, which grants everyone everything'
|
|
}
|
|
// Object, callback and conditional ACEs can grant by rules this check cannot evaluate.
|
|
const unsupported = dacl.aces.find(
|
|
(ace) => ace.type !== ACCESS_ALLOWED_ACE_TYPE && ace.type !== ACCESS_DENIED_ACE_TYPE
|
|
)
|
|
if (unsupported) {
|
|
return `unsupported ACE type ${unsupported.type}`
|
|
}
|
|
const allowed = new Set([userSid, LOCAL_SYSTEM_SID, BUILTIN_ADMINISTRATORS_SID])
|
|
const stranger = dacl.aces.find(
|
|
(ace) => ace.type === ACCESS_ALLOWED_ACE_TYPE && !allowed.has(ace.sid ?? '')
|
|
)
|
|
if (stranger) {
|
|
return `unexpected rule for ${stranger.sid}`
|
|
}
|
|
return null
|
|
}
|