Protecting this process is a two-way procedure:
- providing input meets some criteria (especially for maximum types)
- providing input cannot flow and change the process itself
Let's say I pass the number to the program ...
$num = $_GET['num']; // get the input $num = (int)$_GET['num']; // ensure it is an integer $num = max($num, 0); // ensure it is at least 0 $num = min($num, 800); // ensure it is at most 800 $num = escapeshellarg($num); // this is overkill at this point, but you never know exec('command '.$num);
As stated above, you can also have your own language, but ...
- he may be vulnerable
- this may be redundant for a simple task
- it's just an extended version of the filter system
Finally, there is another alternative. There are functions that take command and parameters as separate arguments, such as popen() (you can enter command arguments through pipes). But it depends on the implementation.
source share