Skip to content

Commit eeda6e8

Browse files
committed
Security measure: Restrict the execution scope of fs.rmSync.
1 parent 4d4ac1e commit eeda6e8

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,14 @@ async function generateBundle(this: PluginContext, bundle: OutputBundle, config:
401401
}
402402
if (options.removeInlinedPublicIconFiles) {
403403
// delete inlined public files
404+
const { outDir } = config.build
405+
const mustStartsWith = path.resolve(outDir) + path.sep
404406
for (const name of globalRemoveDistFileNames) {
405407
try {
406-
fs.rmSync(path.join(config.build.outDir, name), { force: true })
408+
const _path = path.resolve(outDir, name)
409+
if (_path.startsWith(mustStartsWith)) {
410+
fs.rmSync(_path, { force: true })
411+
}
407412
} catch (e) {
408413
console.error(e)
409414
}

0 commit comments

Comments
 (0)