Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1fabb49

Browse files
committed
fix: ensure path resolve is safe
1 parent 39a0677 commit 1fabb49

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

packages/devtools/src/server-rpc/assets.ts

Lines changed: 4 additions & 0 deletions
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 !== '*') {

0 commit comments

Comments
 (0)