Use execFileSync instead of execSync to prevent command injection
All checks were successful
CI / CI (push) Successful in 1m24s
All checks were successful
CI / CI (push) Successful in 1m24s
and add verbose flag
This commit is contained in:
parent
6293010b6c
commit
a6060cdbfb
1 changed files with 8 additions and 9 deletions
|
@ -1,4 +1,4 @@
|
|||
const { execSync } = require('child_process');
|
||||
const { execFileSync } = require('child_process');
|
||||
const path = require('path');
|
||||
const fs = require('fs')
|
||||
|
||||
|
@ -38,7 +38,7 @@ module.exports = {
|
|||
|
||||
const originalMessage = await message.channel.send("Downloading video...")
|
||||
|
||||
if(this.executeCommand(["yt-dlp", url, "-P", downloadsDir, "--cookies", cookieFilepath]).error){
|
||||
if(this.executeCommand("yt-dlp", [url, "-P", downloadsDir, "--cookies", cookieFilepath]).error){
|
||||
originalMessage.edit("An error occured when downloading the video.");
|
||||
this.cleanUp(downloadsDir);
|
||||
return;
|
||||
|
@ -68,16 +68,15 @@ module.exports = {
|
|||
fs.rmSync(downloadsDir, {force: true, recursive: true});
|
||||
},
|
||||
|
||||
executeCommand(command) {
|
||||
if(!Array.isArray(command)) return {error: true};
|
||||
const cmdString = command.join(" ")
|
||||
console.log("Executing:", cmdString);
|
||||
executeCommand(command, commandArgs, {verbose = false}) {
|
||||
if (typeof command !== 'string' || !Array.isArray(commandArgs)) return { error: true };
|
||||
console.log("Executing:", command, commandArgs.join(" "));
|
||||
try {
|
||||
const output = execSync(cmdString, { encoding: 'utf-8' })
|
||||
if (output.length != 0)
|
||||
const output = execFileSync(command, commandArgs, {encoding: 'utf8'})
|
||||
if (output.length != 0 && verbose)
|
||||
console.log(output)
|
||||
} catch (error) {
|
||||
console.error(`Error executing ${command[0]} command:`, error);
|
||||
console.error(`Error executing ${command} command:`, error);
|
||||
return { error: true };
|
||||
}
|
||||
return { error: false };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue