@evomap/evolver-proxy 2.0.32 → 2.0.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -155,6 +155,14 @@ export async function prepareWindowsExecutableSwap(options) {
155
155
  resultPath: paths.resultPath,
156
156
  };
157
157
  }
158
+ function reportUpdaterFailure(options, error) {
159
+ try {
160
+ options.onFailure?.(error);
161
+ }
162
+ catch {
163
+ // 辅助诊断失败不能覆盖原始失败,也不能阻断 durable result 与恢复状态。
164
+ }
165
+ }
158
166
  /**
159
167
  * Apply the pending operation before the stable controller starts target.
160
168
  * A successful swap is idempotent across crashes after rename: if target
@@ -180,6 +188,7 @@ export async function applyPendingWindowsExecutableSwap(options = {}) {
180
188
  await validateWorkItem(workItem, paths, stateDir, options.assertHelperTrust);
181
189
  }
182
190
  catch (error) {
191
+ reportUpdaterFailure(options, error);
183
192
  const result = {
184
193
  schema_version: RESULT_SCHEMA_VERSION,
185
194
  operation: workItem?.operation ?? 'install',
@@ -227,6 +236,7 @@ export async function applyPendingWindowsExecutableSwap(options = {}) {
227
236
  await rm(paths.pendingPath);
228
237
  }
229
238
  catch (error) {
239
+ reportUpdaterFailure(options, error);
230
240
  result = {
231
241
  schema_version: RESULT_SCHEMA_VERSION,
232
242
  operation: workItem.operation,
@@ -624,44 +634,77 @@ function assertNativeWindowsUpdaterHelperTrust(paths) {
624
634
  break;
625
635
  current = dirname(current);
626
636
  }
637
+ const encodedChecks = checks.map((check) => (`${Buffer.from(check.path, 'utf8').toString('base64')}|${check.parentOnly ? '1' : '0'}`)).join('\n');
638
+ if (encodedChecks.length > 24 * 1024) {
639
+ throw selfUpdateFailure(SELF_UPDATE_FAILURE_CODES.REPLACE_FAILED, 'windows_updater_helper_acl_payload_oversized');
640
+ }
627
641
  try {
628
- execFileSync(trustedWindowsSystemExecutable('WindowsPowerShell\\v1.0\\powershell.exe'), ['-NoProfile', '-NonInteractive', '-Command', windowsUpdaterAclScript(checks)], { stdio: 'ignore', timeout: 10_000, windowsHide: true });
642
+ execFileSync(trustedWindowsSystemExecutable('WindowsPowerShell\\v1.0\\powershell.exe'), ['-NoProfile', '-NonInteractive', '-Command', windowsUpdaterAclScript()], {
643
+ env: {
644
+ SystemRoot: HOST_WINDOWS_SYSTEM_ROOT,
645
+ WINDIR: HOST_WINDOWS_SYSTEM_ROOT,
646
+ EVOLVER_UPDATER_ACL_CHECKS: encodedChecks,
647
+ },
648
+ shell: false,
649
+ stdio: 'ignore',
650
+ timeout: 10_000,
651
+ windowsHide: true,
652
+ });
629
653
  }
630
654
  catch (error) {
631
- throw selfUpdateFailure(SELF_UPDATE_FAILURE_CODES.REPLACE_FAILED, 'windows_updater_helper_acl_untrusted', {
655
+ const status = typeof error === 'object' && error !== null
656
+ ? error.status
657
+ : undefined;
658
+ const reason = status === 21
659
+ ? 'owner_untrusted'
660
+ : status === 22
661
+ ? 'identity_unresolved'
662
+ : status === 23
663
+ ? 'writer_untrusted'
664
+ : status === 24
665
+ ? 'input_or_acl_read_failed'
666
+ : 'process_failed';
667
+ throw selfUpdateFailure(SELF_UPDATE_FAILURE_CODES.REPLACE_FAILED, `windows_updater_helper_acl_${reason}`, {
632
668
  cause: error,
633
669
  });
634
670
  }
635
671
  }
636
- function windowsUpdaterAclScript(checks) {
637
- const encodedChecks = Buffer.from(JSON.stringify(checks), 'utf8').toString('base64');
672
+ export function windowsUpdaterAclScript() {
638
673
  const d = String.fromCharCode(36);
639
674
  return [
640
675
  `${d}ErrorActionPreference = 'Stop'`,
641
- 'try {',
642
- ` ${d}json = [Text.Encoding]::UTF8.GetString([Convert]::FromBase64String('${encodedChecks}'))`,
643
- ` ${d}checks = ${d}json | ConvertFrom-Json`,
676
+ 'trap { exit 24 }',
677
+ `${d}checks = @()`,
678
+ `foreach (${d}row in ${d}env:EVOLVER_UPDATER_ACL_CHECKS.Split([char]10, [System.StringSplitOptions]::RemoveEmptyEntries)) {`,
679
+ ` ${d}parts = ${d}row.Split('|')`,
680
+ ` if (${d}parts.Count -ne 2 -or (${d}parts[1] -ne '0' -and ${d}parts[1] -ne '1')) { exit 24 }`,
681
+ ` try { ${d}path = [Text.Encoding]::UTF8.GetString([Convert]::FromBase64String(${d}parts[0])) } catch { exit 24 }`,
682
+ ` ${d}checks += [pscustomobject]@{ path = ${d}path; parentOnly = (${d}parts[1] -eq '1') }`,
683
+ '}',
684
+ `if (${d}checks.Count -eq 0) { exit 24 }`,
644
685
  ` ${d}userSid = [System.Security.Principal.WindowsIdentity]::GetCurrent().User.Value`,
645
686
  ` ${d}trustedInstaller = 'S-1-5-80-956008885-3418522649-1831038044-1853292631-2271478464'`,
646
687
  ` ${d}trustedOwners = @(${d}userSid, 'S-1-5-18', 'S-1-5-32-544', ${d}trustedInstaller)`,
647
688
  ` ${d}trustedWriters = @(${d}userSid, 'S-1-5-18', 'S-1-5-32-544', ${d}trustedInstaller, 'S-1-3-0', 'S-1-3-4')`,
648
689
  ` ${d}parentDanger = [System.Security.AccessControl.FileSystemRights]::Delete -bor [System.Security.AccessControl.FileSystemRights]::DeleteSubdirectoriesAndFiles -bor [System.Security.AccessControl.FileSystemRights]::ChangePermissions -bor [System.Security.AccessControl.FileSystemRights]::TakeOwnership`,
649
690
  ` ${d}contentDanger = [System.Security.AccessControl.FileSystemRights]::WriteData -bor [System.Security.AccessControl.FileSystemRights]::AppendData -bor [System.Security.AccessControl.FileSystemRights]::CreateFiles -bor [System.Security.AccessControl.FileSystemRights]::CreateDirectories`,
650
- ` foreach (${d}check in @(${d}checks)) {`,
651
- ` ${d}acl = Get-Acl -LiteralPath ${d}check.path`,
691
+ `foreach (${d}check in ${d}checks) {`,
692
+ ` try { ${d}attributes = [System.IO.File]::GetAttributes(${d}check.path) } catch { exit 24 }`,
693
+ ` try { ${d}acl = if ((${d}attributes -band [System.IO.FileAttributes]::Directory) -ne 0) { [System.IO.Directory]::GetAccessControl(${d}check.path) } else { [System.IO.File]::GetAccessControl(${d}check.path) } } catch { exit 24 }`,
652
694
  ` ${d}owner = ${d}acl.GetOwner([System.Security.Principal.SecurityIdentifier]).Value`,
653
695
  ` if (${d}trustedOwners -notcontains ${d}owner) { exit 21 }`,
654
696
  ` ${d}danger = if (${d}check.parentOnly) { ${d}parentDanger } else { ${d}parentDanger -bor ${d}contentDanger }`,
655
- ` foreach (${d}rule in @(${d}acl.Access)) {`,
697
+ ` ${d}rules = @(${d}acl.GetAccessRules(${d}true, ${d}true, [System.Security.Principal.SecurityIdentifier]))`,
698
+ ` foreach (${d}rule in ${d}rules) {`,
656
699
  ` if (${d}rule.AccessControlType -ne [System.Security.AccessControl.AccessControlType]::Allow) { continue }`,
657
700
  ` if ((${d}rule.PropagationFlags -band [System.Security.AccessControl.PropagationFlags]::InheritOnly) -ne 0) { continue }`,
658
701
  ` if ((${d}rule.FileSystemRights -band ${d}danger) -eq 0) { continue }`,
659
- ` try { ${d}sid = ${d}rule.IdentityReference.Translate([System.Security.Principal.SecurityIdentifier]).Value } catch { exit 22 }`,
702
+ ` if (-not (${d}rule.IdentityReference -is [System.Security.Principal.SecurityIdentifier])) { exit 22 }`,
703
+ ` ${d}sid = ${d}rule.IdentityReference.Value`,
660
704
  ` if (${d}trustedWriters -notcontains ${d}sid) { exit 23 }`,
661
705
  ' }',
662
- ' }',
663
- '} catch { exit 24 }',
664
- ].join('; ');
706
+ '}',
707
+ ].join('\n');
665
708
  }
666
709
  function trustedWindowsSystemExecutable(name) {
667
710
  if (!win32.isAbsolute(HOST_WINDOWS_SYSTEM_ROOT) || /[\r\n\0]/.test(HOST_WINDOWS_SYSTEM_ROOT)) {