Having worked with several APIs I found out that almost all of them use curl to demonstrate a sample auth./not-auth. request.
My question is:
How dangerous would it be to use shell_exec( % some curl string % ); on a server in a production environment to make requests?
What exactly are the additional risks associated with that?
The system that PHP "natively" uses for requests is curl package which provides some wrapper for curl functionality and probably results in pure curl after compilation.
However, it's cumbersome & quite wordy when you write it.
I did some tests and shell_exec appears to work fine.
For instance, the following code returns results completely as expected. the $json is formatted perfectly well.
$res = shell_exec('curl "https://www.zohoapis.com/crm/v2/settings/profiles" -H "Authorization: Zoho-oauthtoken 1000.8cb99dxxxxxxxxxxxxx9be93.9b8xxxxxxxxxxxxxxxf"');
$json = json_decode($res, true);
var_dump( $json, $res );
Considering that the actual action that happens deep on server should be completely identical, neither there's any significant difference in process (there's no user input involved anyway, the data used is the same, etc.) I don't see any possible negative effect or any additional risks that might be incurred by use of shell_exec.
On the other hand, potential benefits would be quite significant.
escapeshellargand the right /bin/sh setup to make it reliable.-f) to recognize request failures.