fix: ensure path resolve is safe · nuxt/devtools@1fabb49

Original file line numberDiff line numberDiff line change

@@ -47,6 +47,8 @@ export function setupAssetsRPC({ nuxt, ensureDevAuthToken, refresh, options }: N

4747

for (const { layerDir, files } of dirs) {

4848

for (const path of files) {

4949

const filePath = resolve(layerDir, path)

50+

if (!filePath.startsWith(layerDir))

51+

continue

5052

const stat = await fsp.lstat(filePath)

5153

const fullPath = join(baseURL, path)

5254

@@ -109,6 +111,8 @@ export function setupAssetsRPC({ nuxt, ensureDevAuthToken, refresh, options }: N

109111

return await Promise.all(

110112

files.map(async ({ path, content, encoding, override }) => {

111113

let finalPath = resolve(baseDir, path)

114+

if (!finalPath.startsWith(baseDir))

115+

throw new Error(`File ${path} is not allowed to upload, it's outside of the public directory`)

112116
113117

const { ext } = parse(finalPath)

114118

if (extensions !== '*') {