okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
714ff8242
main
1import assert from 'node:assert/strict' ; 2import { statSync } from 'node:fs' ; 3import { execFileSync } from 'node:child_process' ; 4import { join } from 'node:path' ; 5import { currentUserSid } from '../../server/private-file.mjs' ; 6 7/** The effective protection of a file: mode 0600 on POSIX, the exact DACL (one protected entry for this user) on NTFS. 8* The DACL is read through .NET (File.GetAccessControl), not Get-Acl: Get-Acl lives in a module Windows PowerShell has to load, and a 9* Windows PowerShell started under PowerShell 7 (GitHub's Windows runners) failed to load it ("the module could not be loaded"). 10* The entries are compared by SID, not as SDDL text: SDDL writes some accounts as an alias (the built-in Administrator, which GitHub's 11* runners run as, is "LA", not its S-1-5-21-...-500). */ 12export function assertPrivate ( path ) { 13if ( process . platform !== 'win32' ) { assert . equal ( statSync ( path ). mode & 0o777 , 0o600 ); return ; } 14const script = `$a = [System.IO.File]::GetAccessControl(' ${ path . replace ( / ' / g , "''" )} '); 'protected=' + $a.AreAccessRulesProtected; ` 15+ `$a.GetAccessRules($true, $true, [System.Security.Principal.SecurityIdentifier]) | ForEach-Object { $_.IdentityReference.Value + '|' + $_.FileSystemRights + '|' + $_.AccessControlType + '|inherited=' + $_.IsInherited }; ` 16+ `'sddl=' + $a.GetSecurityDescriptorSddlForm('Access')` ; 17const lines = execFileSync ( join ( process . env . SystemRoot , 'System32' , 'WindowsPowerShell' , 'v1.0' , 'powershell.exe' ), [ '-NoProfile' , '-NonInteractive' , '-Command' , script ], 18{ encoding :'utf8' , timeout :30000 , windowsHide :true }). split ( / \r ? \n / ). map ( line => line . trim ()). filter ( Boolean ); 19const sddl = lines . find ( line => line . startsWith ( 'sddl=' )) ?? '' ; 20const facts = lines . filter ( line => ! line . startsWith ( 'sddl=' )); 21assert . deepEqual ( facts , [ 'protected=True' , ` ${ currentUserSid ()} |FullControl|Allow|inherited=False` ], `ACL is not owner-only: ${ sddl } ` ); 22}