Skip to content

Commit d619ab8

Browse files
committed
Stop following symlinks when archiving directories
1 parent 33c310e commit d619ab8

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/archiveDirectory.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ async function tarDirectory(
100100
gzip: true,
101101
file: tempFile.name,
102102
cwd: sourceDirectory,
103-
follow: true,
103+
follow: false,
104104
noDirRecurse: true,
105105
portable: true,
106106
},
@@ -141,7 +141,14 @@ async function zipDirectory(
141141
}
142142
throw err;
143143
}
144-
for (const file of files) {
144+
// For security, filter out all symlinks
145+
const realFiles = await Promise.all(
146+
files.filter(async (f) => {
147+
const stats = await fs.promises.lstat(f.name);
148+
return !stats.isSymbolicLink();
149+
}),
150+
);
151+
for (const file of realFiles) {
145152
const name = path.relative(sourceDirectory, file.name);
146153
allFiles.push(name);
147154
archive.file(file.name, {

0 commit comments

Comments
 (0)