perf(core): check the Windows vault key ACL once per process (P1.2)

Every VaultStore construction started PowerShell to re-apply the key ACL.
The ACL does not change while the process runs; a created key is still
written and hardened by the same PowerShell call.
This commit is contained in:
shumeiko.it
2026-10-24 12:07:21 +02:00
parent 61ea8bbabf
commit 815c667374
2 changed files with 35 additions and 1 deletions

View File

@@ -18,6 +18,13 @@ const ALGORITHM = 'aes-256-gcm';
const KEY_LENGTH = 32;
const IV_LENGTH = 16;
/**
* Key files whose Windows ACL this process already set or verified. The check
* starts PowerShell (hundreds of milliseconds), and the vault is opened from
* several places; the ACL does not change while the process runs.
*/
const windowsKeyAclChecked = new Set<string>();
export interface VaultEntry {
name: string;
value: string;
@@ -82,9 +89,10 @@ export class VaultStore {
created = true;
}
if (process.platform === 'win32') {
if (process.platform === 'win32' && (created || !windowsKeyAclChecked.has(this.keyPath))) {
try {
this.restrictWindowsKeyPermissions(created ? key : undefined);
windowsKeyAclChecked.add(this.keyPath);
} catch (err) {
const reason = err instanceof Error ? err.message : String(err);
throw new Error(`Could not restrict vault key permissions on Windows: ${reason}.`);