diff --git a/.gitignore b/.gitignore index 757a03d..cd93f85 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ # Local configuration and secrets (see .env.example) .env + +# Old upload directory; uploads now go to UPLOAD_DIR outside the web root +graphics/tmp/ diff --git a/display.php b/display.php index 713f167..51d1dc6 100644 --- a/display.php +++ b/display.php @@ -64,17 +64,21 @@ function display_img($id) { $row = $result->fetch_assoc(); if ($row) { - $img_data = $row['img']; - $mimetype = $row['mime']; + $img_data = (string)$row['img']; - ob_start(); + // Serve only real images, with the type found in the data itself (not + // the stored one), and stop browsers from guessing another type + $info = @getimagesizefromstring($img_data); + if (!$info) { + header("HTTP/1.1 404 Not Found"); + $result->close(); + return; + } + + header("Content-type: ".$info['mime']); + header("Content-length: ".strlen($img_data)); + header("X-Content-Type-Options: nosniff"); print $img_data; - $size = ob_get_length(); - $img = ob_get_clean(); - - header("Content-type: $mimetype"); - header("Content-length: $size"); - print $img; } else { header("HTTP/1.1 404 Not Found"); diff --git a/graphics/tmp/php364Gio b/graphics/tmp/php364Gio deleted file mode 100644 index 45eaff9..0000000 Binary files a/graphics/tmp/php364Gio and /dev/null differ diff --git a/graphics/tmp/php8GGIZg b/graphics/tmp/php8GGIZg deleted file mode 100644 index 45eaff9..0000000 Binary files a/graphics/tmp/php8GGIZg and /dev/null differ diff --git a/graphics/tmp/php9QtNxB b/graphics/tmp/php9QtNxB deleted file mode 100644 index 45eaff9..0000000 Binary files a/graphics/tmp/php9QtNxB and /dev/null differ diff --git a/graphics/tmp/phpMNZnOJ b/graphics/tmp/phpMNZnOJ deleted file mode 100644 index 45eaff9..0000000 Binary files a/graphics/tmp/phpMNZnOJ and /dev/null differ diff --git a/graphics/tmp/phpfNAkyA b/graphics/tmp/phpfNAkyA deleted file mode 100644 index 45eaff9..0000000 Binary files a/graphics/tmp/phpfNAkyA and /dev/null differ diff --git a/graphics/tmp/phppdTpmq b/graphics/tmp/phppdTpmq deleted file mode 100644 index 45eaff9..0000000 Binary files a/graphics/tmp/phppdTpmq and /dev/null differ diff --git a/graphics/tmp/phpsYP5eb b/graphics/tmp/phpsYP5eb deleted file mode 100644 index 45eaff9..0000000 Binary files a/graphics/tmp/phpsYP5eb and /dev/null differ diff --git a/graphics/tmp/phpyeSYNT b/graphics/tmp/phpyeSYNT deleted file mode 100644 index 45eaff9..0000000 Binary files a/graphics/tmp/phpyeSYNT and /dev/null differ diff --git a/graphics/tmp/phpzypkkj b/graphics/tmp/phpzypkkj deleted file mode 100644 index 45eaff9..0000000 Binary files a/graphics/tmp/phpzypkkj and /dev/null differ