Fix command injection via file path in convertToWavType - #259
Open
zachariah-mithani wants to merge 1 commit into
Open
Fix command injection via file path in convertToWavType#259zachariah-mithani wants to merge 1 commit into
zachariah-mithani wants to merge 1 commit into
Conversation
convertToWavType() interpolated the caller-supplied file path into a shell
command string passed to shelljs.exec():
const command = `ffmpeg ... -i "${inputFilePath}" ... "${outputFilePath}"`
shell.exec(command)
The path is placed inside double quotes but never escaped, so a path that
contains a double quote breaks out of the quoting. Because this is reached
directly from the public nodewhisper(filePath, options) API (filePath is only
existence-checked, not sanitized), an application that transcribes a
user-influenced file name is exposed to arbitrary command execution. A file
named: inp" ; touch PWNED ; ".mp3 runs:
ffmpeg ... -i "inp" ; touch PWNED ; ".mp3" ... -> touch PWNED executes.
Fix: run ffmpeg with execFileSync and a discrete argv array (no shell), so the
file path is always treated as data and can never be parsed as shell syntax.
Behaviour is unchanged for legitimate paths; the same error message is thrown
on conversion failure.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
convertToWavType()(src/utils.ts) builds anffmpegcommand as a shell string and runs it throughshelljs.exec(), interpolating the caller-supplied file path inside double quotes without escaping:A path containing a
"breaks out of the quoting. This is reached straight from the publicnodewhisper(filePath, options)API —filePathis only existence-checked (checkIfFileExists), never sanitized — so an application that transcribes a user-influenced file name is exposed to arbitrary command execution (CWE-78).Impact
A file named:
turns the command into:
and the shell runs
touch PWNED. The injected command executes whether or notffmpegitself succeeds, duringconvertToWavType(before transcription). Apps that save user-uploaded audio under its original filename and pass that path tonodewhisperare the realistic exposure.I confirmed this on the published
nodejs-whisper@0.3.0: a file with that name caused the injected command to run.Fix
Run
ffmpegwithexecFileSyncand a discrete argv array (no shell), so the file path is always treated as data and can never be parsed as shell syntax:tscbuild passes.One file changed (
src/utils.ts); the now-unusedshelljsimport in this file is removed.