style(desktop): keep PM source-check bridge lint clean

This commit is contained in:
ethernet
2026-09-24 06:30:30 -04:00
parent 1695fab334
commit ebc69c5faf
2 changed files with 5 additions and 0 deletions

View File

@@ -115,6 +115,7 @@ it.skipIf(process.platform !== 'win32')(
hermesHome: home,
channel: 'stable' as const
}
await expect(readSourceUpdate(probe)).resolves.toMatchObject({ supported: true, channel: 'stable', behind: null })
await expect(readSourceUpdate({ ...probe, branch: 'main&echo INJECTED' })).rejects.toThrow(
'unsafe Windows command argument'

View File

@@ -46,6 +46,7 @@ export async function readSourceUpdate(probe: SourceUpdateProbe): Promise<Source
// The install launcher boots PM's committed Python and dependency generation.
// A PATH Python can import this checkout yet lack its selected dependencies.
const managed = existsSync(path.join(probe.updateRoot, 'pm'))
const launcher = managed
? resolveInstallationLauncher(probe.updateRoot, process.platform === 'win32', probe.hermesHome)
: null
@@ -79,13 +80,16 @@ export async function readSourceUpdate(probe: SourceUpdateProbe): Promise<Source
...(probe.cachePath ? ['--cache-path', probe.cachePath] : []),
...(probe.branchConfigPath ? ['--branch-config-path', probe.branchConfigPath] : [])
]
const command: string = (managed ? launcher : probe.python)!
const viaCmd: boolean = process.platform === 'win32' && /\.cmd$/i.test(command)
// Node refuses direct .cmd execFile; shell:true interpolates untrusted branch
// and path arguments. Keep cmd.exe's one unavoidable parse fail-closed.
if (viaCmd && [command, ...args].some((value: string): boolean => /["%&|<>^\r\n]/.test(value))) {
throw new Error('The source check contains an unsafe Windows command argument.')
}
const result: { stdout: string; stderr: string } = await execute(
viaCmd ? (process.env.ComSpec ?? 'cmd.exe') : command,
viaCmd