fix : securite middle et execfile
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import { exec } from "child_process"
|
||||
import { execFile } from "child_process"
|
||||
import diskSources from "../config/disk-commands.json"
|
||||
|
||||
type DiskSource = {
|
||||
key: string
|
||||
label: string
|
||||
command: string
|
||||
args?: string[]
|
||||
}
|
||||
|
||||
function getCommand(source: DiskSource) {
|
||||
@@ -15,9 +16,9 @@ function getCommand(source: DiskSource) {
|
||||
return process.env[envKey] || (legacyEnvKey ? process.env[legacyEnvKey] : undefined) || source.command
|
||||
}
|
||||
|
||||
function runCommand(command: string): Promise<string> {
|
||||
function runCommand(command: string, args: string[] = []): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
exec(command, (error, stdout, stderr) => {
|
||||
execFile(command, args, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
reject(stderr || error.message)
|
||||
return
|
||||
@@ -31,7 +32,7 @@ export default defineEventHandler(async () => {
|
||||
const results = await Promise.all(
|
||||
(diskSources as DiskSource[]).map(async (source) => {
|
||||
try {
|
||||
const output = await runCommand(getCommand(source))
|
||||
const output = await runCommand(source.command, source.args || [])
|
||||
return {
|
||||
key: source.key,
|
||||
label: source.label,
|
||||
|
||||
Reference in New Issue
Block a user