Serve stored images safely and drop committed uploads.

display.php takes the type from the image data, refuses anything else,
and sends nosniff. Remove the nine uploads in graphics/tmp.
This commit is contained in:
tim
2026-09-25 21:48:17 +02:00
parent c5ce7661f5
commit 1698680e24
11 changed files with 16 additions and 9 deletions
+3
View File
@@ -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/
+13 -9
View File
@@ -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");
Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB