I'm very weak in curl functions. I have a script which does hourly routines to update files among networked sites.
I have three concerns:
- Efficiency
- Accuracy
- Security
Having tested it in some length, it will grab the 404's and save them as csv files, and then the validation afterward deletes them. But it would be better to reject a non-csv file flat out...even if its disguised as a .csv for malicious purposes.
On that note, I will be saving them to a special folder. Is there any way to hide executable (malicious) code in them? I figured I would keep this directory non-executable to ensure safety.
Here is the code:
//check file exists first:
if ( !$fp = curl_init( $url ) )
return 'Symbiocard not found at this address ('.$url.'). Please upload manually.';
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_NOBODY, 0 );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_BINARYTRANSFER, 1 );
$raw = curl_exec( $ch );
curl_close( $ch );
if ( file_exists( $newfile ) ) {
unlink( $newfile );
} //file_exists( $newfile )
$fp = fopen( $newfile, 'x' );
fwrite( $fp, $raw );
fclose( $fp );
$required_fields = array(
'symbiostock_site',
'admin_email',
'symbiostock_version'
);
I didn't past my validation / file writing code simply because I'd like to filter it on the CURL level.
THE QUESTION: How do I limit curl to only communicate with a genuine csv file (not a 404 or any other document at the supposed .csv location).