Fix problema di sicurezza upload file svg e xml

This commit is contained in:
loviuz 2021-07-04 20:02:16 +02:00
parent 9011409cc1
commit 7ec0bbe4bb
2 changed files with 65 additions and 56 deletions

View File

@ -206,7 +206,7 @@ class Upload extends Model
*/ */
public function isImage() public function isImage()
{ {
$list = ['jpg', 'png', 'gif', 'jpeg', 'bmp']; $list = ['jpg', 'png', 'gif', 'jpeg', 'bmp', 'svg'];
return in_array($this->extension, $list); return in_array($this->extension, $list);
} }

View File

@ -29,7 +29,15 @@ if (empty($file)) {
$link = base_path().'/'.$file->filepath; $link = base_path().'/'.$file->filepath;
if ($file->isFatturaElettronica()) { // Force download of the file
if (get('force') == '1') {
header('Content-Type: application/octet-stream');
header("Content-Transfer-Encoding: Binary");
header("Content-disposition: attachment; filename=\"" . basename($file->original_name) . "\"");
readfile($docroot.'/'.$file->filepath);
exit();
} else {
if ($file->isFatturaElettronica()) {
$content = file_get_contents(base_dir().'/'.$file->filepath); $content = file_get_contents(base_dir().'/'.$file->filepath);
// Individuazione stylesheet // Individuazione stylesheet
@ -56,16 +64,16 @@ if ($file->isFatturaElettronica()) {
$xslt->importStylesheet($xsl); $xslt->importStylesheet($xsl);
echo ' echo '
<style> <style>
#notifica { #notifica {
min-width: 860px !important; min-width: 860px !important;
} }
</style>'; </style>';
echo $xslt->transformToXML($xml); echo $xslt->transformToXML($xml);
} else { } else {
echo ' echo '
<style> <style>
body, iframe, img{ body, iframe, img{
border: 0; border: 0;
margin: 0; margin: 0;
@ -76,7 +84,7 @@ if ($file->isFatturaElettronica()) {
height:100%; height:100%;
min-height: 500px; min-height: 500px;
} }
</style>'; </style>';
if ($file->isImage()) { if ($file->isImage()) {
echo ' echo '
@ -87,8 +95,9 @@ if ($file->isFatturaElettronica()) {
} }
echo ' echo '
<iframe src="'.($link ?: $src).'"> <iframe src="'.base_path().'/view.php?file_id='.$file_id.'&force=1">
<a src="'.$link.'">'.tr('Il browser non supporta i contenuti iframe: clicca qui per raggiungere il file originale').'</a> <a src="'.base_path().'/view.php?file_id='.$file_id.'&force=1">'.tr('Il browser non supporta i contenuti iframe: clicca qui per raggiungere il file originale').'</a>
</iframe>'; </iframe>';
} }
}
} }