fix(prerender): skip writing routes with `..` or outside of public dir · nitrojs/nitro@50b3bc5

Original file line numberDiff line numberDiff line change

@@ -154,8 +154,8 @@ export async function prerender(nitro: Nitro) {

154154

};

155155
156156

const canWriteToDisk = (route: PrerenderRoute) => {

157-

// Cannot write routes with query

158-

if (route.route.includes("?")) {

157+

// Cannot write routes with query or containing ..

158+

if (route.route.includes("?") || route.route.includes("..")) {

159159

return false;

160160

}

161161

@@ -291,8 +291,8 @@ export async function prerender(nitro: Nitro) {

291291

}

292292
293293

// Write to the disk

294-

if (canWriteToDisk(_route)) {

295-

const filePath = join(nitro.options.output.publicDir, _route.fileName);

294+

const filePath = join(nitro.options.output.publicDir, _route.fileName);

295+

if (canWriteToDisk(_route) && filePath.startsWith(nitro.options.output.publicDir)) {

296296

await writeFile(filePath, dataBuff!);

297297

nitro._prerenderedRoutes!.push(_route);

298298

} else {