From dcd367114677331876834de95baf84a1b1ef8f2f Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Fri, 5 May 2023 18:15:18 -0700 Subject: [PATCH] ensure binaryChecksum for download is correct --- .../screenshotting/server/browsers/install.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/screenshotting/server/browsers/install.ts b/x-pack/plugins/screenshotting/server/browsers/install.ts index dd925878dd0f7..351aa875dc48a 100644 --- a/x-pack/plugins/screenshotting/server/browsers/install.ts +++ b/x-pack/plugins/screenshotting/server/browsers/install.ts @@ -30,8 +30,8 @@ export async function install( const binaryChecksum = await md5(binaryPath).catch(() => 'MISSING'); if (binaryChecksum === pkg.binaryChecksum) { + // validated a previously extracted browser binary logger.info(`Browser executable: ${binaryPath}`); - // validated a previously downloaded browser return binaryPath; } @@ -54,6 +54,17 @@ export async function install( logger.error(error); } + // check the newly extracted browser binary + const downloadedBinaryChecksum = await md5(binaryPath).catch(() => 'MISSING'); + if (downloadedBinaryChecksum !== pkg.binaryChecksum) { + const error = new Error( + `Error installing browsers, binary checksums incorrect for [${architecture}/${platform}]` + ); + logger?.error(error); + + throw error; + } + logger.info(`Browser executable has been installed: ${binaryPath}`); return binaryPath;