Skip to content

Commit 36e4544

Browse files
authored
fix(zip): never write through a symlink when extracting (#43910)
1 parent 1482237 commit 36e4544

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

‎packages/playwright/src/reporters/blob.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,13 @@ export class BlobReporter extends TeleReporterEmitter {
8484
zipFinishPromise.resolve(undefined);
8585
}).on('error', error => zipFinishPromise.reject(error));
8686

87+
const addedEntries = new Set<string>();
8788
for (const { originalPath, zipEntryPath } of this._attachments) {
89+
if (addedEntries.has(zipEntryPath))
90+
continue;
8891
if (!fs.statSync(originalPath, { throwIfNoEntry: false })?.isFile())
8992
continue;
93+
addedEntries.add(zipEntryPath);
9094
zipFile.addFile(originalPath, zipEntryPath);
9195
}
9296

‎packages/utils/third_party/extractZip.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,10 @@ class Extractor {
177177
debug('creating symlink', link, dest);
178178
await fs.symlink(link, dest);
179179
} else {
180-
await pipeline(readStream, createWriteStream(dest, { mode: procMode }));
180+
// 'wx' fails when dest exists, including a symlink left by a previous entry.
181+
// Otherwise an archive could place a symlink and then a regular file with the
182+
// same name to write outside of the extraction directory.
183+
await pipeline(readStream, createWriteStream(dest, { mode: procMode, flags: 'wx' }));
181184
}
182185
}
183186

0 commit comments

Comments
 (0)