Skip to content

Commit 50a11a5

Browse files
authored
Merge pull request #243 from Lissy93/sec/fix-com-inj-vul
security: Replace exec with execFile
2 parents 9965386 + 145711b commit 50a11a5

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

api/screenshot.js

+20-15
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import puppeteer from 'puppeteer-core';
22
import chromium from 'chrome-aws-lambda';
33
import middleware from './_common/middleware.js';
4-
import { exec } from 'child_process';
4+
import { execFile } from 'child_process';
55
import { promises as fs } from 'fs';
66
import path from 'path';
77
import pkg from 'uuid';
@@ -20,32 +20,37 @@ const directChromiumScreenshot = async (url) => {
2020

2121
return new Promise((resolve, reject) => {
2222
const chromePath = process.env.CHROME_PATH || '/usr/bin/chromium';
23-
const command = `${chromePath} --headless --disable-gpu --no-sandbox --screenshot=${screenshotPath} "${url}"`;
24-
25-
console.log(`[DIRECT-SCREENSHOT] Executing command: ${command}`);
23+
const args = [
24+
'--headless',
25+
'--disable-gpu',
26+
'--no-sandbox',
27+
`--screenshot=${screenshotPath}`,
28+
url
29+
];
30+
31+
console.log(`[DIRECT-SCREENSHOT] Executing: ${chromePath} ${args.join(' ')}`);
2632

27-
exec(command, async (error, stdout, stderr) => {
33+
execFile(chromePath, args, async (error, stdout, stderr) => {
2834
if (error) {
29-
console.error(`[DIRECT-SCREENSHOT] Error executing Chromium: ${error.message}`);
35+
console.error(`[DIRECT-SCREENSHOT] Chromium error: ${error.message}`);
3036
return reject(error);
3137
}
32-
38+
3339
try {
34-
// Read screenshot
40+
// Read the screenshot file
3541
const screenshotData = await fs.readFile(screenshotPath);
36-
console.log(`[DIRECT-SCREENSHOT] Read ${screenshotData.length} bytes from screenshot file`);
42+
console.log(`[DIRECT-SCREENSHOT] Screenshot read successfully`);
3743

38-
// Convert base64
44+
// Convert to base64
3945
const base64Data = screenshotData.toString('base64');
40-
41-
// Clean
42-
await fs.unlink(screenshotPath).catch(err =>
46+
47+
await fs.unlink(screenshotPath).catch(err =>
4348
console.warn(`[DIRECT-SCREENSHOT] Failed to delete temp file: ${err.message}`)
4449
);
45-
50+
4651
resolve(base64Data);
4752
} catch (readError) {
48-
console.error(`[DIRECT-SCREENSHOT] Error reading screenshot: ${readError.message}`);
53+
console.error(`[DIRECT-SCREENSHOT] Failed reading screenshot: ${readError.message}`);
4954
reject(readError);
5055
}
5156
});

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "web-check",
33
"type": "module",
4-
"version": "2.0.0",
4+
"version": "2.0.1",
55
"homepage": "https://web-check.xyz",
66
"scripts": {
77
"start": "node server",

0 commit comments

Comments
 (0)