Skip to content

Commit e908ade

Browse files
author
Carlos Garcia
committed
Forzamos la descarga de archivos xml, svg y html de MyFiles.
1 parent e03866e commit e908ade

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

‎Core/Controller/Myfiles.php‎

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ public function run(): void
9898
ob_end_flush();
9999
}
100100

101-
// force to download svg files to prevent XSS attacks
102-
if ($this->isSvg($this->filePath)) {
101+
// force to download svg, xml and html files to prevent XSS attacks
102+
if ($this->shouldForceDownload($this->filePath)) {
103103
header('Content-Disposition: attachment; filename="' . basename($this->filePath) . '"');
104104
}
105105

@@ -125,16 +125,25 @@ private function getMime(string $filePath): string
125125
return mime_content_type($filePath);
126126
}
127127

128-
private function isSvg(string $filePath): bool
128+
private function shouldForceDownload(string $filePath): bool
129129
{
130-
// comprobamos la extensión
131-
if (strpos($filePath, '.svg') !== false) {
132-
return true;
130+
// verificar extensión
131+
$info = pathinfo($filePath);
132+
if (isset($info['extension'])) {
133+
$extension = strtolower($info['extension']);
134+
$dangerousExtensions = ['svg', 'xml', 'xsig', 'html', 'htm', 'xhtml'];
135+
if (in_array($extension, $dangerousExtensions, true)) {
136+
return true;
137+
}
133138
}
134139

135-
// comprobamos mime
136-
if (strpos($this->getMime($filePath), 'image/svg') !== false) {
137-
return true;
140+
// verificar MIME type detectado (por si el archivo está renombrado)
141+
$mime = $this->getMime($filePath);
142+
$dangerousMimes = ['text/html', 'text/xml', 'application/xml', 'image/svg+xml', 'application/xhtml+xml'];
143+
foreach ($dangerousMimes as $dangerousMime) {
144+
if (strpos($mime, $dangerousMime) !== false) {
145+
return true;
146+
}
138147
}
139148

140149
return false;

0 commit comments

Comments
 (0)