From af31b70b41a9582334862ebdd1abe54d3fc0d685 Mon Sep 17 00:00:00 2001 From: Michael Rasmussen Date: Thu, 11 Jun 2015 18:16:09 +0200 Subject: [PATCH] Enhance security --- message_view.php | 9 ++++-- quarantine.php | 80 ++++++++++++++++++++++++++---------------------- show_headers.php | 11 +++++-- 3 files changed, 58 insertions(+), 42 deletions(-) diff --git a/message_view.php b/message_view.php index fabf698..e81d984 100644 --- a/message_view.php +++ b/message_view.php @@ -11,12 +11,17 @@ $id = $_GET['id']; $id = urldecode($id); + $mail = unserialize($_SESSION['mailInfo'][$id]); + + if (false == $util->authorized($mail->recipient)) { + header('Location: index.php'); + exit; + } + $util->setHeading("Message ID : $id"); echo $util->getHeader(); echo $util->getHeading(); - $mail = unserialize($_SESSION['mailInfo'][$id]); - $row = $DB->getMail($id); $string = $row->mail_text; $sa_tests = null; diff --git a/quarantine.php b/quarantine.php index 031a416..14e07e7 100644 --- a/quarantine.php +++ b/quarantine.php @@ -21,41 +21,44 @@ foreach ($ids as $id) { $mail_id = urldecode($id); $mail = unserialize($_SESSION['mailInfo']["$mail_id"]); - $secret_id = $mail->secret_id; - $recipient = $mail->recipient; - if ($request == 'release') { - $amavisserver = $CFG->amavisd_db_host; - $policy_port = $CFG->amavis_policy_port; + if (true == $util->authorized($mail->recipient)) { + $secret_id = $mail->secret_id; + $recipient = $mail->recipient; - $fp = fsockopen($amavisserver, $policy_port, $errno, $errstr, 30); - if (!$fp) { - error("$errstr ($errno)"); - exit; - } - $out = "request=" . $request . "\r\n"; - $out .= "mail_id=" . $mail_id . "\r\n"; - $out .= "recipient=" . $recipient . "\r\n"; - $out .= "secret_id=" . $secret_id . "\r\n\r\n"; - fwrite($fp, $out); - $response = fread($fp, 8192); - fclose($fp); - $response = urldecode($response); - if (! preg_match("/^setreply=250\s+([\d\.]+)\s+(.*)/", $response, $matches)) { - error("Request to release failed [$out][$response]"); - exit; - } - if ($matches[1] != '2.0.0') { - error($matches[2]); + if ($request == 'release') { + $amavisserver = $CFG->amavisd_db_host; + $policy_port = $CFG->amavis_policy_port; + + $fp = fsockopen($amavisserver, $policy_port, $errno, $errstr, 30); + if (!$fp) { + error("$errstr ($errno)"); + exit; + } + $out = "request=" . $request . "\r\n"; + $out .= "mail_id=" . $mail_id . "\r\n"; + $out .= "recipient=" . $recipient . "\r\n"; + $out .= "secret_id=" . $secret_id . "\r\n\r\n"; + fwrite($fp, $out); + $response = fread($fp, 8192); + fclose($fp); + $response = urldecode($response); + if (! preg_match("/^setreply=250\s+([\d\.]+)\s+(.*)/", $response, $matches)) { + error("Request to release failed [$out][$response]"); + exit; + } + if ($matches[1] != '2.0.0') { + error($matches[2]); + exit; + } + + $query[] = "UPDATE msgrcpt SET rs = 'R' WHERE mail_id = '$mail_id'"; + } else if ($request == 'delete') { + $query[] = "UPDATE msgrcpt SET rs = 'D' WHERE mail_id = '$mail_id'"; + } else { + error("Unknown operation [$request]"); exit; } - - $query[] = "UPDATE msgrcpt SET rs = 'R' WHERE mail_id = '$mail_id'"; - } else if ($request == 'delete') { - $query[] = "UPDATE msgrcpt SET rs = 'D' WHERE mail_id = '$mail_id'"; - } else { - error("Unknown operation [$request]"); - exit; } } @@ -80,12 +83,15 @@ $query = array(); $error = array(); foreach ($marked as $mail_id) { - $query[] = "delete from msgs where mail_id = '$mail_id'"; - $query[] = "delete from msgrcpt where mail_id = '$mail_id'"; - $query[] = "delete from quarantine where mail_id = '$mail_id'"; - $success = $DB->update($query); - if (! $success) { - $error[] = $mail_id; + $mail = $DB->getMail($mail_id); + if (true == $util->authorized($mail->recipient)) { + $query[] = "delete from msgs where mail_id = '$mail_id'"; + $query[] = "delete from msgrcpt where mail_id = '$mail_id'"; + $query[] = "delete from quarantine where mail_id = '$mail_id'"; + $success = $DB->update($query); + if (! $success) { + $error[] = $mail_id; + } } } if (count($error) > 0) { diff --git a/show_headers.php b/show_headers.php index 7cee6dc..0ff9a6e 100644 --- a/show_headers.php +++ b/show_headers.php @@ -8,13 +8,18 @@ $util = new Utils; $loggedIn = $util->isLoggedIn(); if ($loggedIn && isset($_GET['id'])) { + $id = $_GET['id']; + $mail = unserialize($_SESSION['mailInfo'][$id]); + + if (false == $util->authorized($mail->recipient)) { + header('Location: index.php'); + exit; + } + $util->setHeading('Full Headers Report'); echo $util->getHeader(); echo $util->getHeading(); - $id = $_GET['id']; - $mail = unserialize($_SESSION['mailInfo'][$id]); - $row = $DB->getMail($id); $string = $row->mail_text; $sa_tests = null; -- 2.39.5