Unverified Commit d9bd3291 authored by Ionuț Botizan's avatar Ionuț Botizan Committed by GitHub

Sanitize the path to the user config before importing (#30003)

parent ac287e67
import chalk from 'chalk' import chalk from 'chalk'
import findUp from 'next/dist/compiled/find-up' import findUp from 'next/dist/compiled/find-up'
import { basename, extname, relative } from 'path' import { basename, extname, relative } from 'path'
import { pathToFileURL } from 'url'
import { Agent as HttpAgent } from 'http' import { Agent as HttpAgent } from 'http'
import { Agent as HttpsAgent } from 'https' import { Agent as HttpsAgent } from 'https'
import * as Log from '../build/output/log' import * as Log from '../build/output/log'
...@@ -530,8 +531,10 @@ export default async function loadConfig( ...@@ -530,8 +531,10 @@ export default async function loadConfig(
let userConfigModule: any let userConfigModule: any
try { try {
// we must use file for absolute dynamic imports on Windows // `import()` expects url-encoded strings, so the path must be properly
userConfigModule = await import(`file://${path}`) // escaped and (especially on Windows) absolute paths must pe prefixed
// with the `file://` protocol
userConfigModule = await import(pathToFileURL(path).href)
} catch (err) { } catch (err) {
console.error( console.error(
chalk.red('Error:') + chalk.red('Error:') +
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment