using exec () can be a security risk and should be avoided if possible.
Something like a generalization - it's entirely possible to build a secure solution using exec() . But it is really difficult: there are many errors when executing external programs, especially if you pass external parameters to them.
The first step, as you say, is to avoid everything using escapeshellarg() to prevent the injection of other, possibly malicious, commands.
The question then becomes, what can cause damage to incoming incorrect values ββin the called program. For instance,
Performing the ffmpeg operation on a large 200,000 x 200,000 pixel video may cause the server to freeze because the call is trying to allocate an impossible amount of memory. Therefore, you must sanitize the size values ββthat the user can enter and exit if they are too large, or not numbers.
an attacker can tell ffmpeg to use a configuration file and try to create a video from it, which can lead to the creation of a configuration file that will be used as output, so you need to limit the range of file paths that users can specify.
And so on and so forth.
In addition, you need to think about the possibility of killing the server through a simple number of requests. What if I send 50 requests per second to a PHP script, which in turn calls the complex ffmpeg command? The server can easily break down under load, and you can protect against this.
So: there is no built-in security issue in using exec() , but every input parameter that is passed to it should be carefully considered.
source share