Filter out bad MIME types from fileopen.php and share allowable array with filesave.php
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@2617 eee81c28-f429-11dd-99c0-75d572ba1ddd
This commit is contained in:
11
editor/extensions/allowedMimeTypes.php
Normal file
11
editor/extensions/allowedMimeTypes.php
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
$allowedMimeTypesBySuffix = array(
|
||||||
|
'svg' => 'image/svg+xml',
|
||||||
|
'png' => 'image/png',
|
||||||
|
'jpeg' => 'image/jpeg',
|
||||||
|
'bmp' => 'image/bmp',
|
||||||
|
'webp' => 'image/webp'
|
||||||
|
);
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -12,20 +12,24 @@
|
|||||||
// Very minimal PHP file, all we do is Base64 encode the uploaded file and
|
// Very minimal PHP file, all we do is Base64 encode the uploaded file and
|
||||||
// return it to the editor
|
// return it to the editor
|
||||||
|
|
||||||
$file = $_FILES['svg_file']['tmp_name'];
|
|
||||||
|
|
||||||
$output = file_get_contents($file);
|
|
||||||
|
|
||||||
$type = $_REQUEST['type'];
|
$type = $_REQUEST['type'];
|
||||||
if (!in_array($type, array('load_svg', 'import_svg', 'import_img'))) {
|
if (!in_array($type, array('load_svg', 'import_svg', 'import_img'))) {
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
require('allowedMimeTypes.php');
|
||||||
|
|
||||||
|
$file = $_FILES['svg_file']['tmp_name'];
|
||||||
|
|
||||||
|
$output = file_get_contents($file);
|
||||||
|
|
||||||
$prefix = '';
|
$prefix = '';
|
||||||
|
|
||||||
// Make Data URL prefix for import image
|
// Make Data URL prefix for import image
|
||||||
if($type == 'import_img') {
|
if($type == 'import_img') {
|
||||||
$info = getimagesize($file);
|
$info = getimagesize($file);
|
||||||
|
if (!in_array($info['mime'], $allowedMimeTypesBySuffix)) {
|
||||||
|
exit;
|
||||||
|
}
|
||||||
$prefix = 'data:' . $info['mime'] . ';base64,';
|
$prefix = 'data:' . $info['mime'] . ';base64,';
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
@@ -33,7 +37,12 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<script>
|
<script>
|
||||||
window.top.window.svgEditor.processFile("<?php echo $prefix . base64_encode($output); ?>", "<?php echo $type; ?>");
|
window.top.window.svgEditor.processFile("<?php
|
||||||
|
|
||||||
|
// This should be safe since SVG edit does its own filtering (e.g., if an SVG file contains scripts)
|
||||||
|
echo $prefix . base64_encode($output);
|
||||||
|
|
||||||
|
?>", "<?php echo $type; ?>");
|
||||||
</script>
|
</script>
|
||||||
</head><body></body>
|
</head><body></body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -9,13 +9,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$allowedMimeTypesBySuffix = array(
|
require('allowedMimeTypes.php');
|
||||||
'svg' => 'image/svg+xml',
|
|
||||||
'png' => 'image/png',
|
|
||||||
'jpeg' => 'image/jpeg',
|
|
||||||
'bmp' => 'image/bmp',
|
|
||||||
'webp' => 'image/webp'
|
|
||||||
);
|
|
||||||
|
|
||||||
$mime = !isset($_POST['mime']) || !in_array($_POST['mime'], $allowedMimeTypesBySuffix) ? 'image/svg+xml' : $_POST['mime'];
|
$mime = !isset($_POST['mime']) || !in_array($_POST['mime'], $allowedMimeTypesBySuffix) ? 'image/svg+xml' : $_POST['mime'];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user