php - Security of unzipping user submitted files -
php - Security of unzipping user submitted files -
not much of coding problem here, general question relating security. i'm working on project allows user submitted content. key part of content user uploads zip file. zip file should contain mp3 files.
i unzip files directory on server, can stream sound on website users hear to.
my concern opens potentially damaging zip files. i've read 'zipbombs' in past, , don't want malicious zip file causing damage.
so, there safe way of doing this? can scan zip file without unzipping first, , if contains other mp3's delete or flag warning admin?
if makes difference i'm developing site on wordpress. utilize built in upload features of wordpress allow user upload zip file our server (i'm not sure if there's form of security within wordpress scan zip file?)
code, extract mp3s zip, ignore everthing else $zip = new ziparchive(); $filename = 'newzip.zip'; if ($zip->open($filename)!==true) { exit("cannot open <$filename>\n"); } ($i=0; $i<$zip->numfiles;$i++) { $info = $zip->statindex($i); $file = pathinfo($info['name']); if(strtolower($file['extension']) == "mp3") { file_put_contents(basename($info['name']), $zip->getfromindex($i)); } } $zip->close();
i utilize use id3_get_version
(http://www.php.net/manual/en/function.id3-get-version.php) ensure contents of file mp3 too
php wordpress zip unzip
Comments
Post a Comment