Fix Windows local file download paths (#810)
This commit is contained in:
@@ -65,9 +65,17 @@ export interface TerminalConfig {
|
||||
/**
|
||||
* Validate a file path: must be absolute and not contain '..' traversal.
|
||||
*/
|
||||
export function normalizePlatformPath(filePath: string, platform = process.platform): string {
|
||||
if (platform !== 'win32') return filePath
|
||||
const msysDrivePath = filePath.match(/^\/([a-zA-Z])(?:\/(.*))?$/)
|
||||
if (!msysDrivePath) return filePath
|
||||
const [, drive, rest = ''] = msysDrivePath
|
||||
return `${drive.toUpperCase()}:\\${rest.replace(/\//g, '\\')}`
|
||||
}
|
||||
|
||||
export function validatePath(filePath: string): string {
|
||||
if (!filePath) throw Object.assign(new Error('Missing file path'), { code: 'missing_path' })
|
||||
const resolved = resolve(filePath)
|
||||
const resolved = resolve(normalizePlatformPath(filePath))
|
||||
const normalized = normalize(resolved)
|
||||
if (normalized.includes('..')) {
|
||||
throw Object.assign(new Error('Invalid file path'), { code: 'invalid_path' })
|
||||
|
||||
Reference in New Issue
Block a user