From 33a2929ab6a0aa9c52265dbf778fcf4dbd3d5098 Mon Sep 17 00:00:00 2001 From: johnnyq Date: Wed, 15 Jul 2026 13:42:19 -0400 Subject: [PATCH] Feature: Secure File Download Handler for ticket attachments Implemented --- agent/ticket.php | 10 +-- agent/ticket_attachment.php | 126 ++++++++++++++++++++++++++++++++++++ 2 files changed, 132 insertions(+), 4 deletions(-) create mode 100644 agent/ticket_attachment.php diff --git a/agent/ticket.php b/agent/ticket.php index 82572cfd..5837454e 100644 --- a/agent/ticket.php +++ b/agent/ticket.php @@ -561,9 +561,10 @@ if (isset($_GET['ticket_id'])) { $name [View][Download]"; + + echo "
$name [View][Download]"; } ?> @@ -784,8 +785,9 @@ if (isset($_GET['ticket_id'])) { $name | Download | View"; + $ticket_attachment_id = intval($ticket_attachment['ticket_attachment_id']); + + echo "
$name | Download | View"; } ?> diff --git a/agent/ticket_attachment.php b/agent/ticket_attachment.php new file mode 100644 index 00000000..9ece8050 --- /dev/null +++ b/agent/ticket_attachment.php @@ -0,0 +1,126 @@ += $file_mtime) +) { + http_response_code(304); + exit; +} + +// Audit log - skip thumbnail loads +if (!$thumb) { + logAudit("Ticket", "Download", "$session_name viewed ticket attachment $attachment_name_escaped", $client_id); +} + +// Send the file +header("Content-Type: $attachment_mime_type"); +header("Content-Disposition: $disposition; filename=\"$safe_attachment_name\""); +header("Content-Length: " . filesize($file_path)); +header("X-Content-Type-Options: nosniff"); + +// Clear output buffers so large files stream instead of loading into memory +while (ob_get_level()) { + ob_end_clean(); +} + +readfile($file_path); +exit;