Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(security): prevent Zip Slip path traversal in harUnzip (#40623)

Sebastien Tardifb4bae37d34af
diff --git a/packages/playwright-core/src/server/localUtils.ts b/packages/playwright-core/src/server/localUtils.ts
index a9a3106fce..2ba65b226e 100644
--- a/packages/playwright-core/src/server/localUtils.ts
+++ b/packages/playwright-core/src/server/localUtils.ts
@@ -25,7 +25,7 @@ import { serializeClientSideCallMetadata } from '@isomorphic/trace/traceUtils';
import { assert } from '@isomorphic/assert';
import { calculateSha1 } from '@utils/crypto';
import { ZipFile } from '@utils/zipFile';
-import { removeFolders } from '@utils/fileUtils';
+import { removeFolders, resolveWithinRoot } from '@utils/fileUtils';
import { HarBackend } from './harBackend';
import type * as channels from '@protocol/channels';
import type * as har from '@trace/har';
@@ -188,7 +188,10 @@ export async function harUnzip(progress: Progress, params: channels.LocalUtilsHa
await progress.race(fs.promises.mkdir(resourcesDir, { recursive: true }));
resourcesDirCreated = true;
}
- await progress.race(fs.promises.writeFile(path.join(resourcesDir, entry), buffer));
+ const outPath = resolveWithinRoot(resourcesDir, entry);
+ if (!outPath)
+ throw new Error(`HAR zip entry '${entry}' escapes output directory`);
+ await progress.race(fs.promises.writeFile(outPath, buffer));
}
}
await progress.race(fs.promises.unlink(params.zipFile));