perf: load page modules on demand and avoid repeated startup ACL writes
This commit is contained in:
1 parent
73773f9526
commit
7ead1e7cb7
19 files changed
+330
-24
No files matched your search
@@ -0,0 +1,43 @@
|
||||
'use strict';
|
||||
const test=require('node:test'),assert=require('node:assert/strict'),cp=require('node:child_process');
|
||||
const fs=require('node:fs'),os=require('node:os'),path=require('node:path');
|
||||
|
||||
test('native ACL policy accepts only the current owner and one protected inheritable full-control allow rule',{skip:process.platform!=='win32'},()=>{
|
||||
const {privateDirectoryAcl}=require('../../src/platform/security/windows-directory.cjs');
|
||||
const cases=`
|
||||
$sid=[System.Security.Principal.WindowsIdentity]::GetCurrent().User
|
||||
function Make-Acl($protected,$owner,$rights,$inherit,$propagation,$type,$identity) {
|
||||
$acl=New-Object System.Security.AccessControl.DirectorySecurity
|
||||
$acl.SetOwner($owner);$acl.SetAccessRuleProtection($protected,$false)
|
||||
$rule=New-Object System.Security.AccessControl.FileSystemAccessRule($identity,$rights,$inherit,$propagation,$type)
|
||||
$acl.AddAccessRule($rule);return $acl
|
||||
}
|
||||
$other=New-Object System.Security.Principal.SecurityIdentifier('S-1-1-0')
|
||||
$rows=@(
|
||||
(Test-PrivateDirectoryAcl (Make-Acl $true $sid 'FullControl' 'ContainerInherit,ObjectInherit' 'None' 'Allow' $sid) $sid),
|
||||
(Test-PrivateDirectoryAcl (Make-Acl $false $sid 'FullControl' 'ContainerInherit,ObjectInherit' 'None' 'Allow' $sid) $sid),
|
||||
(Test-PrivateDirectoryAcl (Make-Acl $true $other 'FullControl' 'ContainerInherit,ObjectInherit' 'None' 'Allow' $sid) $sid),
|
||||
(Test-PrivateDirectoryAcl (Make-Acl $true $sid 'Read' 'ContainerInherit,ObjectInherit' 'None' 'Allow' $sid) $sid),
|
||||
(Test-PrivateDirectoryAcl (Make-Acl $true $sid 'FullControl' 'None' 'None' 'Allow' $sid) $sid),
|
||||
(Test-PrivateDirectoryAcl (Make-Acl $true $sid 'FullControl' 'ContainerInherit,ObjectInherit' 'InheritOnly' 'Allow' $sid) $sid),
|
||||
(Test-PrivateDirectoryAcl (Make-Acl $true $sid 'FullControl' 'ContainerInherit,ObjectInherit' 'None' 'Deny' $sid) $sid),
|
||||
(Test-PrivateDirectoryAcl (Make-Acl $true $sid 'FullControl' 'ContainerInherit,ObjectInherit' 'None' 'Allow' $other) $sid)
|
||||
)
|
||||
$extra=Make-Acl $true $sid 'FullControl' 'ContainerInherit,ObjectInherit' 'None' 'Allow' $sid
|
||||
$extra.AddAccessRule((New-Object System.Security.AccessControl.FileSystemAccessRule($other,'Read','ContainerInherit,ObjectInherit','None','Allow')))
|
||||
$rows+=(Test-PrivateDirectoryAcl $extra $sid)
|
||||
ConvertTo-Json -Compress -InputObject $rows
|
||||
`;
|
||||
const output=cp.execFileSync('powershell.exe',['-NoLogo','-NoProfile','-NonInteractive','-Command','$ErrorActionPreference="Stop";'+privateDirectoryAcl+cases],{encoding:'utf8',windowsHide:true,timeout:15000});
|
||||
assert.deepEqual(JSON.parse(output),[true,false,false,false,false,false,false,false,false]);
|
||||
});
|
||||
|
||||
test('a compliant real directory is not rewritten and an unprotected directory is repaired',{skip:process.platform!=='win32'},t=>{
|
||||
const {privateDirectoryAcl,secureDirectoryScript}=require('../../src/platform/security/windows-directory.cjs'),parent=path.resolve(os.tmpdir()),dir=fs.mkdtempSync(path.join(parent,'acl-policy-'));
|
||||
assert.equal(path.dirname(dir),parent);t.after(()=>fs.rmSync(dir,{recursive:true,force:true}));
|
||||
const run=script=>cp.execFileSync('powershell.exe',['-NoLogo','-NoProfile','-NonInteractive','-Command','$ErrorActionPreference="Stop";'+script],{input:dir,encoding:'utf8',windowsHide:true,timeout:15000}).trim();
|
||||
run(secureDirectoryScript);const protectedAt=fs.statSync(dir,{bigint:true}).ctimeNs;run(secureDirectoryScript);assert.equal(fs.statSync(dir,{bigint:true}).ctimeNs,protectedAt,'read verification must not rewrite the DACL');
|
||||
run('$p=[Console]::In.ReadToEnd();$acl=[IO.Directory]::GetAccessControl($p);$acl.SetAccessRuleProtection($false,$true);[IO.Directory]::SetAccessControl($p,$acl)');
|
||||
run(secureDirectoryScript);
|
||||
const verified=run(privateDirectoryAcl+';$p=[Console]::In.ReadToEnd();Test-PrivateDirectoryAcl ([IO.Directory]::GetAccessControl($p)) ([System.Security.Principal.WindowsIdentity]::GetCurrent().User)');assert.equal(verified,'True');
|
||||
});
|
||||
Reference in new issue
Block a user