style(desktop): keep PM source-check bridge lint clean
This commit is contained in:
@@ -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'
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user