diff --git a/CHANGELOG.md b/CHANGELOG.md
index 33a3328ac..e3b198854 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,7 +6,13 @@ This file documents all notable changes made to ITFlow.
### Upgrading to 26.12.3
-Update from Maintenance > Update as usual - this release has nine database changes: 4.2.2 adds a table for passkeys and a setting to turn them on or off, 4.2.3 lets a document keep the Markdown it was written in, 4.2.4 lets a ticket keep its pictures as files, 4.2.5 adds identity providers, 4.2.6 keeps each ticket's email conversation together, 4.2.7 lets a reply from a CC say who sent it, 4.2.8 renames the watchers table for CCs, 4.2.9 lets the mail queue go at a pace your mail host takes, and 4.3.0 lets contacts unsubscribe from bulk email. The client portal's Microsoft 365 single sign-on becomes the first identity provider, for client contacts, and keeps its redirect address, so nothing changes in Microsoft Entra. Nothing else is required: passkeys are on, and no one has one until they add it. Pictures already inside tickets move to files in the background afterwards - the new Ticket Pictures job in Maintenance > Cron does a batch a minute, so an install with years of emailed screenshots may take a while, and tickets work as usual meanwhile. A passkey is made for your ITFlow's address (the one in config.php) and only works there, over HTTPS - if you move ITFlow to a new address, everyone adds theirs again. Watchers are called CCs now. Emails about a ticket go to its contact with the CCs copied in, rather than one each - Admin > Settings > Tickets has the switch, under Emails about a ticket.
+Update from Maintenance > Update as usual - this release has ten database changes: 4.2.2 adds a table for passkeys and a setting to turn them on or off, 4.2.3 lets a document keep the Markdown it was written in, 4.2.4 lets a ticket keep its pictures as files, 4.2.5 adds identity providers, 4.2.6 keeps each ticket's email conversation together, 4.2.7 lets a reply from a CC say who sent it, 4.2.8 renames the watchers table for CCs, 4.2.9 lets the mail queue go at a pace your mail host takes, 4.3.0 lets contacts unsubscribe from bulk email, and 4.3.1 encrypts the mail passwords and tokens. The client portal's Microsoft 365 single sign-on becomes the first identity provider, for client contacts, and keeps its redirect address, so nothing changes in Microsoft Entra. Nothing else is required: passkeys are on, and no one has one until they add it. Pictures already inside tickets move to files in the background afterwards - the new Ticket Pictures job in Maintenance > Cron does a batch a minute, so an install with years of emailed screenshots may take a while, and tickets work as usual meanwhile. A passkey is made for your ITFlow's address (the one in config.php) and only works there, over HTTPS - if you move ITFlow to a new address, everyone adds theirs again. Watchers are called CCs now. Emails about a ticket go to its contact with the CCs copied in, rather than one each - Admin > Settings > Tickets has the switch, under Emails about a ticket.
+
+### Security
+
+- The mail passwords, the OAuth client secret and the tokens ITFlow signs in to Microsoft 365 and Google with are encrypted in the database, where they were kept as typed - anyone with a copy of the database, or a backup, could sign in to your mailboxes. They're encrypted with a key made from config.php's backup key, so keep that key as Maintenance > Backup says: an install restored without it needs the passwords entered again, and Admin > Settings > Mail says so. Without a backup key - config.php not writable - they stay as typed, and Admin > Settings > Mail says that too.
+- Pictures from other sites in a client's email - a logo, or a tracking pixel that tells the sender when it was read and from where - are hidden on a ticket until you click Show pictures, on the ticket, its quick look and its work order. Pictures kept with the ticket show as always.
+- The sign-in page no longer loads the mail server's password.
### New Features & Updates
@@ -153,6 +159,7 @@ Update from Maintenance > Update as usual - this release has nine database chang
- Mail review stage 4: a failed email is still being tried while it is under MAIL_QUEUE_TRIES and its last try is within MAIL_QUEUE_GIVE_UP_HOURS (24) - mailQueueRetryingSql(), mailQueueFailedSql() and mailQueueRetrying(), for the job, the tabs, an email's state, Cancel and the summary - so one given up on before the tries went from 4 to 8 stays Failed rather than being sent again, and Failed gives its own count of tries. mailQueueRefusedForGood() decides which refused recipients are for good: the enhanced codes 5.1.1, 5.1.2, 5.1.3, 5.1.6 and 5.1.10, or 550, 551 or 553 naming an unknown recipient from a server that gives none (MailQueueSmtp keeps code_ex). Any other refusal is tried again and counts toward the two-in-a-row stop. mailQueueNotifyAdmins() counts dismissed notices toward its hour. The job orders by email_bulk, then email_sensitive DESC.
- Mail review stage 5: cron/ticket_email_parser.php - an email with no From address is from '' rather than itflow-guest@example.com: addReply() takes it as a stranger's ($no_sender) and addTicket() makes no CC and sends no answer. contactBounceClearEmail() runs after ticketMailSenderCheck(), and only when it didn't fail. ticketMailReplyTo() (functions/ticket_mail_auto.php) reads Reply-To: one at From's domain is taken as the sender ($via, shown as "sent by"); else, when ticketMailSystemSender() says From is a no-reply or website address (TICKET_MAIL_SYSTEM_SENDERS) or there is none, it is $answer - steps 4 to 6 raise the ticket with contact_id 0 for it at the From contact's or domain's client, or none. addTicket() makes the sender a CC whenever there is no contact (was: no client), answers anyone not a contact through ticketMailCreated()'s new $stranger (no Subject row and no button - its last parameter was the subject), and skips ticketMailColleaguesNew() for a forged ticket or one with no contact. ticketMailSenderContact() (functions/ticket_mail_thread.php) picks the contact for steps 3 and 4 by the From domain's client, then the latest ticket, then contact_id, and ticketMailSenderContactNote() notes the others; Try an Email uses it. An agent's email whose To or Cc has the ticket's contact, a CC or another of the client's contacts (ticketMailClientAddresses()) is a Public reply - addReplyAgentToClient() fills ticket_reply_emailed_to, calls setTicketFirstResponse(), assigns it through ticketChangeAssignee() under ticketReplyAssigns() or moves New to Open, and fires reply_reply_agent_public. ticketNotifyOwner() (functions/ticket.php) puts a bell notice with the assigned agent or the admins (appNotifyUsers(), functions/logging.php) - for bounces and closed-ticket replies, where appNotify() told every agent - and ticketMailAssigneeReplied() goes to ticketMailUnassignedReplied() on a ticket nobody has: the new-ticket address, else that notice. That covers portal and text replies too.
- Mail review stage 6: database 4.3.0 adds contacts.contact_unsubscribed_at and settings.config_mail_unsubscribe_secret. functions/contact_unsubscribe.php signs each contact's link with an HMAC of the contact id and address (contactUnsubscribeToken(), the key made on first use), and contactUnsubscribeSet() takes every contact with the address out or back in; contactUnsubscribedAddresses() is checked at send time, so a contact added since at another client is out too. guest/unsubscribe.php asks on GET, acts on its form's POST, and takes RFC 8058's List-Unsubscribe=One-Click POST with no page. emailBulkRecipients() (functions/email.php) builds the recipients from contact rows - the bounced, the unsubscribed, no address and the same address left out and counted - each with an unsubscribe link (emailHtml()'s new unsubscribe field) and its own List-Unsubscribe and List-Unsubscribe-Post headers (emailQueue() recipients' headers, let through by MAIL_QUEUE_HEADERS); emailBulkPost() now takes contact rows and converts Send at with timezoneFromView(). sendQueueEmail() sets the envelope sender per email - setFrom(..., false) with Sender reset, as PHPMailer's setFrom() kept the first email's From as Sender for the whole kept-alive connection - and for email_bulk passes mailQueueReturnPath(), the read mailbox when ticket parsing is on, the provider isn't Graph sending, the SMTP username is empty or that mailbox, and the domains align; a MAIL FROM refusal sends it again from the From address and sets mailQueueReturnPathRefused() for the run. mailQueueBouncesTo() tells the Email window.
+- Mail review stage 7a: database 4.3.1 widens config_smtp_password, config_imap_password and config_mail_oauth_client_secret to varchar(500) and encrypts what is saved. functions/mail_secret.php seals MAIL_SECRET_COLUMNS (the two passwords, the OAuth secret, refresh and access tokens, and config_mail_graph_token) with secretSeal($plain, 'mail') as RMM and identity provider secrets are - but keeps a value as typed when there is no key, as mail would otherwise stop. mailSecretOpen() reads an unsealed value as it is, so nothing breaks before it is sealed: load_global_settings.php, cron/mail_queue.php, cron/nightly_tasks.php and mailGraphToken() open them; settingsWrite() seals secret-kind mail columns; every token write (the parser's two refreshes, persistMailOauthTokens(), the Microsoft callback, the Test OAuth refresh, mailGraphToken()) goes through mailSecretSql(). mailSecretsSealAll() runs in the update and nightly; mailSecretProblem() is the Admin > Settings > Mail warning. Remote pictures: ticketHtmlForAgents($purifier, $html) purifies and then ticketRemoteImagesHold() moves an http(s) or // img src to data-remote-src (a blank GIF and .itflow-remote-image in its place) and a style with a remote url() to data-remote-style - in agent/ticket.php, the quick look and ticketWorkOrderHtml(); ticketRemoteImagesNote() and js/app.js show the note and put them back. login.php drops the SMTP host, port, encryption, username and password it loaded but never used.
## [26.12.2]
diff --git a/admin/database_updates/4.3.1.php b/admin/database_updates/4.3.1.php
new file mode 100644
index 000000000..4ec2c24f2
--- /dev/null
+++ b/admin/database_updates/4.3.1.php
@@ -0,0 +1,26 @@
+
+
+
+
';
}
// Signing off the work, on site
@@ -206,7 +206,7 @@ function ticketWorkOrderHtml(array $ticket, $purifier, array $replies) {
. printSheetBoxHtml('Job', $job_html)
. '
')
. printSheetSectionHtml('Details', printSheetFieldsHtml($fill_ins))
. printSheetSectionHtml('Tasks', $tasks_html, 'data-print-tasks')
. printSheetSectionHtml('Conversation', $replies_html, 'data-print-replies')
diff --git a/functions/settings.php b/functions/settings.php
index 80fb92a1f..e127bea81 100644
--- a/functions/settings.php
+++ b/functions/settings.php
@@ -895,8 +895,10 @@ function settingsWrite($table, array $before, array $after) {
} elseif (is_int($value) || is_float($value)) {
$sets[] = "$column_sql = " . (is_float($value) ? rtrim(rtrim(sprintf('%.6F', $value), '0'), '.') : $value);
} elseif (($fields[$column]['kind'] ?? '') === 'secret') {
- // escapeSql() would trim it and take out anything that looks like a tag - a password can have both
- $sets[] = "$column_sql = '" . mysqli_real_escape_string($mysqli, (string) $value) . "'";
+ // escapeSql() would trim it and take out anything that looks like a tag - a password can have both. The mail
+ // passwords and OAuth secrets encrypted (functions/mail_secret.php)
+ $value = in_array($column, MAIL_SECRET_COLUMNS, true) && mailSecretReady() ? mailSecretSeal((string) $value) : (string) $value;
+ $sets[] = "$column_sql = '" . mysqli_real_escape_string($mysqli, $value) . "'";
} else {
$sets[] = "$column_sql = '" . escapeSql((string) $value) . "'";
}
diff --git a/functions/ticket_pictures.php b/functions/ticket_pictures.php
index 15b794bf0..aab66a017 100644
--- a/functions/ticket_pictures.php
+++ b/functions/ticket_pictures.php
@@ -401,3 +401,62 @@ function ticketPicturesSweep($seconds = 25) {
}
return ['moved' => $moved, 'texts' => $texts, 'behind' => $behind, 'failed' => ticketPicturesFailed()];
}
+
+/*
+ * ---------- pictures from other sites, held back ----------
+ *
+ * A client's email can carry pictures it loads from another site - a sender's logo, or a tracking pixel that tells
+ * them when the email was read, and from where. On a ticket that was each agent who opened it. On the agent's pages
+ * (the ticket, its quick look, its work order) such a picture is held back until someone clicks Show pictures - its
+ * address kept as data-remote-src, and a background picture's style as data-remote-style (js/app.js puts them back).
+ * Pictures kept as the ticket's files, and data ones, show as always.
+ */
+
+/* A blank 1x1 GIF where a held-back picture goes. */
+const TICKET_REMOTE_IMAGE_BLANK = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';
+
+/* HTML someone wrote, made safe ($purifier) and with pictures from other sites held back - for the agent's pages. */
+function ticketHtmlForAgents($purifier, $html) {
+ return ticketRemoteImagesHold($purifier->purify((string) $html));
+}
+
+/* Whether a picture's address is another site's - http(s) or // to a host that isn't this install's. */
+function ticketRemoteImageUrl($url) {
+ global $config_base_url;
+ $url = html_entity_decode(trim((string) $url), ENT_QUOTES | ENT_HTML5, 'UTF-8');
+ if (!preg_match('#^(https?:)?//([^/?\#:]+)#i', $url, $m)) {
+ return false;
+ }
+ $own = strtolower((string) parse_url('https://' . preg_replace('#^https?://#i', '', (string) ($config_base_url ?? '')), PHP_URL_HOST));
+ return strtolower($m[2]) !== $own;
+}
+
+/* Purified HTML with the pictures from other sites held back (above). */
+function ticketRemoteImagesHold($html) {
+ $html = (string) $html;
+ if (stripos($html, ']*>#i', function ($m) {
+ $tag = $m[0];
+ // A picture
+ if (preg_match('#^'
+ . 'Pictures from other sites are hidden, so their senders can\'t see when this is read, or from where.'
+ . '';
+}
diff --git a/includes/load_global_settings.php b/includes/load_global_settings.php
index 93653e530..19856cbea 100644
--- a/includes/load_global_settings.php
+++ b/includes/load_global_settings.php
@@ -45,7 +45,8 @@ $config_smtp_host = $row['config_smtp_host'];
$config_smtp_port = intval($row['config_smtp_port']);
$config_smtp_encryption = $row['config_smtp_encryption'];
$config_smtp_username = $row['config_smtp_username'];
-$config_smtp_password = $row['config_smtp_password'];
+// Encrypted in the database (functions/mail_secret.php)
+$config_smtp_password = function_exists('mailSecretOpen') ? mailSecretOpen($row['config_smtp_password']) : $row['config_smtp_password'];
$config_mail_from_email = $row['config_mail_from_email'];
$config_mail_from_name = $row['config_mail_from_name'];
@@ -55,14 +56,14 @@ $config_imap_host = $row['config_imap_host'];
$config_imap_port = intval($row['config_imap_port']);
$config_imap_encryption = $row['config_imap_encryption'];
$config_imap_username = $row['config_imap_username'];
-$config_imap_password = $row['config_imap_password'];
+$config_imap_password = function_exists('mailSecretOpen') ? mailSecretOpen($row['config_imap_password']) : $row['config_imap_password'];
// Mail OAUTH2
$config_mail_oauth_client_id = $row['config_mail_oauth_client_id'];
-$config_mail_oauth_client_secret = $row['config_mail_oauth_client_secret'];
+$config_mail_oauth_client_secret = function_exists('mailSecretOpen') ? mailSecretOpen($row['config_mail_oauth_client_secret']) : $row['config_mail_oauth_client_secret'];
$config_mail_oauth_tenant_id = $row['config_mail_oauth_tenant_id'];
-$config_mail_oauth_refresh_token = $row['config_mail_oauth_refresh_token'];
-$config_mail_oauth_access_token = $row['config_mail_oauth_access_token'];
+$config_mail_oauth_refresh_token = function_exists('mailSecretOpen') ? mailSecretOpen($row['config_mail_oauth_refresh_token']) : $row['config_mail_oauth_refresh_token'];
+$config_mail_oauth_access_token = function_exists('mailSecretOpen') ? mailSecretOpen($row['config_mail_oauth_access_token']) : $row['config_mail_oauth_access_token'];
$config_mail_oauth_access_token_expires_at = $row['config_mail_oauth_access_token_expires_at'];
// Defaults
diff --git a/js/app.js b/js/app.js
index e5257c8ad..822bb3164 100644
--- a/js/app.js
+++ b/js/app.js
@@ -957,6 +957,38 @@ function itflowInit() {
// the document is already parsed, otherwise wait for it.
itflowReady(itflowInit);
+/*
+ * Pictures from other sites in a ticket's text are held back (functions/ticket_pictures.php) - the note above it says so
+ * when there are any, and Show pictures puts them back, in the page or the window it is in.
+ */
+function itflowRemoteImagesNotes(root) {
+ (root || document).querySelectorAll('[data-remote-images-note]').forEach(function (note) {
+ const scope = note.closest('.modal') || document;
+ note.classList.toggle('d-none', !scope.querySelector('[data-remote-src], [data-remote-style]'));
+ });
+}
+itflowReady(function () {
+ itflowRemoteImagesNotes(document);
+});
+itflowBindOnce('itflowRemoteImagesModal', 'shown.bs.modal', '.modal', function () {
+ itflowRemoteImagesNotes(this);
+});
+itflowBindOnce('itflowRemoteImagesShow', 'click', '[data-show-remote-images]', function () {
+ const scope = this.closest('.modal') || document;
+ scope.querySelectorAll('[data-remote-src]').forEach(function (img) {
+ img.src = img.getAttribute('data-remote-src');
+ img.removeAttribute('data-remote-src');
+ img.classList.remove('itflow-remote-image');
+ });
+ scope.querySelectorAll('[data-remote-style]').forEach(function (el) {
+ el.setAttribute('style', el.getAttribute('data-remote-style'));
+ el.removeAttribute('data-remote-style');
+ });
+ scope.querySelectorAll('[data-remote-images-note]').forEach(function (note) {
+ note.classList.add('d-none');
+ });
+});
+
/*
* Calendar event modals - the All day switch shows or hides the time row.
*
diff --git a/login.php b/login.php
index 3ec60a69f..76c854c7d 100644
--- a/login.php
+++ b/login.php
@@ -89,12 +89,8 @@ $company_logo = $row['company_logo'];
$config_start_page = escapeHtml($row['config_start_page']);
$config_login_message = escapeHtml($row['config_login_message']);
+// Whether mail is set up, for Forgot password - the sign-in page doesn't need the mail server's details or password
$config_smtp_provider = $row['config_smtp_provider'];
-$config_smtp_host = $row['config_smtp_host'];
-$config_smtp_port = intval($row['config_smtp_port']);
-$config_smtp_encryption = $row['config_smtp_encryption'];
-$config_smtp_username = $row['config_smtp_username'];
-$config_smtp_password = $row['config_smtp_password'];
$config_mail_from_email = escapeSql($row['config_mail_from_email']);
$config_mail_from_name = escapeSql($row['config_mail_from_name']);