Email and phone links in Knowledge Base articles, documents and ticket replies: purifierUriSchemes lets mailto and tel through HTMLPurifier wherever it is set up, which had allowed only http, https and data, and database update 4.4.5 makes the HTML of Markdown articles and documents with such links again, keeping when they were updated; 26.12.6 changelog

This commit is contained in:
johnnyq
2026-12-05 01:22:28 -05:00
parent 7ea52c95a8
commit 332b444c7b
9 changed files with 73 additions and 7 deletions

View File

@@ -6,7 +6,7 @@ This file documents all notable changes made to ITFlow.
### Upgrading to 26.12.6
Update from Maintenance > Update as usual. This release has one database change: 4.4.4 adds the settings for Warranty Lookup.
Update from Maintenance > Update as usual. This release has two database changes: 4.4.4 adds the settings for Warranty Lookup, and 4.4.5 puts the email and phone links back in Knowledge Base articles and documents written in Markdown.
- If you have switched a module off in Admin > Settings > Modules - IT documentation, ticketing, invoicing and accounting or any of the others - check that you meant it before updating. Its pages, bookmarks to them and links in old emails stop opening, and the nightly run stops doing its work: with ticketing off, no recurring tickets are raised and resolved tickets aren't closed; with invoicing and accounting off, no recurring invoices or expenses are made, no autopay is charged and no payment reminders go out; with IT documentation off, no domain, certificate, warranty or service review notifications, and shared links - logins, files, documents and IT documentation exports sent to clients - don't open. Switch it back on and the next run picks up what is due, and shared links that haven't run out open again.
- API keys get a 403 saying which module is off for anything of a module that is switched off - tickets with ticketing off, assets and credentials with IT documentation off, invoices with invoicing off.
@@ -32,6 +32,7 @@ Update from Maintenance > Update as usual. This release has one database change:
- UniFi gateways come in as **Firewall/Router**. The Cloud Gateway Fiber, the Enterprise Fortress Gateway and other newer gateways came in as a switch or as Other, because UniFi doesn't always say a device is a gateway - ITFlow now knows them by their model too: the Dream Machines, Dream Routers and Dream Wall, the Cloud Gateways, the UXG Gateways, the Enterprise Fortress Gateway and the older Security Gateways. One already brought in as a switch or Other is put right by the next sync, unless you changed its type yourself, and when one goes offline its alert is the site's gateway alert. In-wall access points, which came in as switches, come in as access points.
- Connecting Microsoft 365 for mail works with an app that has only Microsoft Graph's permissions, and where your users can't approve apps. Connect asked Microsoft for Exchange's SMTP and IMAP permissions every time and forced the consent screen, so an app with only Graph's Mail.Send and Mail.ReadWrite couldn't connect, and a mailbox account that isn't allowed to approve apps was stopped at "Need admin approval" even after an admin had granted consent. On the OAuth tab, **The app has**, above **Connect Microsoft 365**, says which permissions you gave the app, and Connect asks for just those - Microsoft asks which account to sign in as instead. Coming back, ITFlow says how email now goes, or what the app is missing. **Test OAuth Token Refresh** no longer fails an app with only Graph's permissions: it checks Graph first, and SMTP and IMAP only for what Graph can't do.
- A card is saved once per client, however often it's entered. A client who set up autopay on two recurring invoices with the same card - or added it again in the portal - ended up with the card saved twice, once for each, as Stripe gives the card a new reference each time it's entered. ITFlow now knows the same card when it comes back: the one saved card is kept, with the details just entered, and every recurring invoice it pays carries on with it. A card that is already saved twice is merged into one overnight - the copy that runs out last is kept and the autopay on the others moves to it - so you don't need to do anything, and its client isn't sent two expiry reminders for it.
- Email and phone links work in Knowledge Base articles and documents - a `mailto:` or `tel:` link showed as plain text on the published article, in the client portal and on the document, while the editor still had it. Those in an article or document written in Markdown were taken out when it was saved; the database update puts them back in the ones already saved, so they don't need saving again. Email and phone links in ticket replies, such as those in an email signature, work too.
### Developer Updates
@@ -47,6 +48,7 @@ Update from Maintenance > Update as usual. This release has one database change:
- `agent/ajax.php` answers `warranty_lookup` - an asset form's `make`, `model` and `serial` (`{answer}`), or up to 25 `asset_ids` (`{results}`, written) - and `warranty_hp_check`, an HP job ID asked after with the same `asset_ids` or `serial` (`{done: false}` until HP has finished) - with IT documentation on (`moduleOffText('itdoc')` otherwise), Support at Modify, and `hasClientAccess()` for each asset. `js/warranty_lookup.js` drives the form's `[data-warranty-lookup]` button and `agent/modals/asset/asset_bulk_warranty.php` (up to 500 assets, 5 a request, HP polled every 10 seconds for up to 15 minutes). `admin/settings_warranty.php` and `admin/post/settings_warranty.php` are the `warranty` page in `settingsPages()`, its own group in `adminNavGroups()`, mapped to `itdoc` in `modulePaths()`. Database 4.4.4 adds `config_warranty_dell_client_id`, `config_warranty_dell_client_secret`, `config_warranty_hp_client_id`, `config_warranty_hp_client_secret` and `config_warranty_lenovo` (default 1) to `settings`.
- Markdown uploads: `functions/markdown_upload.php`. `upload_files` (`agent/post/file.php`) collects an upload's .md files and pictures (`markdownUploadExtensions()`, `markdownPictureExtensions()`) and hands them to `markdownUploadConvert($client_id, $file_ids, $folders_made)` at its end; a folder sent in parts keeps them in `$_SESSION['upload_batches'][upload_batch]` until `upload_folder_done`, which now answers `go` - the document's address when one document is all it made. `markdown_keep` turns it off. `markdownFileToDocument()` makes each document with `markdownImportSplit()`, `markdownSaveImages()` and `markdownRewritePictures($markdown, $find)` - `![alt](target)`, `<img src>`, `[id]: target` for a picture and Obsidian's `![[name]]`, code blocks left alone - finding each with `markdownFindPicture()`: through the folder tree from the .md's folder (`markdownPathFolder()`, `..` included, folder names with or without Notion's ID), then by a name only one picture has. `markdownCopyPicture()` checks it with `getimagesizefromstring()` and stores it under `uploads/documents/<id>/` by its real type. The file's links move to the document through `linkAdd()`; the .md and the pictures used go (`markdownUploadRemoveFile()`), and so do folders the upload made that are left empty (`markdownUploadRemoveEmptyFolders()`). `folderForUploadPath()` takes `&$made_ids` and drops Notion's 32-character ID from a folder's name (`markdownNotionName()`).
- `js/zip_reader.js` - `window.itflowZip.list(file)` reads a zip's central directory, `.unpack(file, entry)` takes a file out, inflating with `DecompressionStream('deflate-raw')`; no zip64 or encrypted entries. The upload window sends a zip with Markdown pages as the folder it holds, through the folder upload, so PHP's zip extension isn't needed. Make it a document: `agent/modals/file/file_make_document.php`, `make_file_document`, `markdownFileMakeDocument()`. `get_file_markdown` (`agent/ajax.php`) and `fileMarkdownPreviewHtml()` render an uploaded .md - its pictures in Files as `file.php` links - for the grid previewer (`kind: 'markdown'`) and the file quick look. `agent/modals/document/document_import_markdown.php` and `import_markdown_documents` are removed. `fileUploadExtensions()` takes `.markdown`, and `fileTypeInfo()` calls `.md` Markdown.
- `purifierUriSchemes()` (`functions/sanitize.php`) is the one list of address schemes HTMLPurifier lets through - `http`, `https`, `mailto`, `tel` and `data` - for `documentHtmlPurify()` and the ticket views (`agent/ticket.php`, `agent/modals/ticket/ticket.php`, `client/ticket.php`, `guest/guest_view_ticket.php`, `guest/guest_approve_ticket_task.php`), each of which set `http`/`https`/`data` only. HTMLPurifier still checks each: a `mailto:` must be an address, a `tel:` is cut down to its digits, and `javascript:`, `vbscript:`, `file:` and the rest go. Database 4.4.5 makes `document_content` and `kb_article_content` (with their `_raw` search text) again from the Markdown of those with `mailto:` or `tel:` in it, keeping `_updated_at`; it stops, to be run again, if the process still has the functions from before it.
## [26.12.5]

View File

@@ -0,0 +1,54 @@
<?php
/*
* ITFlow - Database update to version 4.4.5 (from 4.4.4)
* Included by admin/database_updates.php - do not access directly
*
* Email (mailto:) and phone (tel:) links are let through now (purifierUriSchemes(), functions/
* sanitize.php). A document or Knowledge Base article written in Markdown keeps the HTML made from
* it when it was saved (markdownToHtml()), which had those links taken out - each one whose
* Markdown has such a link has its HTML made again, so they work without saving it again. When it
* was last updated stays as it was. Rich text is made safe as it is shown, so it needs nothing.
*
* Re-runnable: the same Markdown makes the same HTML.
*/
defined('FROM_DB_UPDATER') || die("Direct file access is not allowed");
// Made by the code from before this release, the links would come out again - so stop, and the
// next run, on the updated code, picks up here (scripts/update_cli.php runs it so when it can)
if (!function_exists('purifierUriSchemes') || !function_exists('markdownToHtml')) {
throw new Exception('this update needs the updated code loaded - run the update again');
}
$itflow_column_there = function ($table, $column) use ($mysqli) {
$result = mysqli_query($mysqli, "SELECT 1 FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = '$table' AND COLUMN_NAME = '$column' LIMIT 1");
return $result && mysqli_num_rows($result) > 0;
};
if ($itflow_column_there('documents', 'document_markdown')) {
$itflow_rows = mysqli_query($mysqli, "SELECT document_id, document_name, document_markdown FROM documents
WHERE document_markdown IS NOT NULL AND (document_markdown LIKE '%mailto:%' OR document_markdown LIKE '%tel:%')");
while ($itflow_rows && ($itflow_row = mysqli_fetch_assoc($itflow_rows))) {
$itflow_html = markdownToHtml($itflow_row['document_markdown']);
mysqli_query($mysqli, "UPDATE documents SET
document_content = '" . mysqli_real_escape_string($mysqli, $itflow_html) . "',
document_content_raw = '" . escapeSql(documentContentRaw($itflow_row['document_name'], $itflow_html)) . "',
document_updated_at = document_updated_at
WHERE document_id = " . intval($itflow_row['document_id']));
}
}
if ($itflow_column_there('kb_articles', 'kb_article_markdown')) {
$itflow_rows = mysqli_query($mysqli, "SELECT kb_article_id, kb_article_title, kb_article_summary, kb_article_markdown FROM kb_articles
WHERE kb_article_markdown IS NOT NULL AND (kb_article_markdown LIKE '%mailto:%' OR kb_article_markdown LIKE '%tel:%')");
while ($itflow_rows && ($itflow_row = mysqli_fetch_assoc($itflow_rows))) {
$itflow_html = markdownToHtml($itflow_row['kb_article_markdown']);
mysqli_query($mysqli, "UPDATE kb_articles SET
kb_article_content = '" . mysqli_real_escape_string($mysqli, $itflow_html) . "',
kb_article_content_raw = '" . escapeSql(kbArticleContentRaw($itflow_row['kb_article_title'], (string) $itflow_row['kb_article_summary'], $itflow_html)) . "',
kb_article_updated_at = kb_article_updated_at
WHERE kb_article_id = " . intval($itflow_row['kb_article_id']));
}
}

View File

@@ -46,7 +46,7 @@ ticketMarkRead($ticket_id, $session_user_id);
$purifier_config = HTMLPurifier_Config::createDefault();
$purifier_config->set('Cache.DefinitionImpl', null);
$purifier_config->set('URI.AllowedSchemes', ['data' => true, 'src' => true, 'http' => true, 'https' => true]);
$purifier_config->set('URI.AllowedSchemes', purifierUriSchemes());
// Classes our scripts act on (ajax-modal fetches a page and runs it) never come from stored HTML
$purifier_config->set('Attr.ForbiddenClasses', ['ajax-modal']);
$purifier = new HTMLPurifier($purifier_config);

View File

@@ -21,7 +21,7 @@ require_once "../libs/htmlpurifier/HTMLPurifier.standalone.php";
$purifier_config = HTMLPurifier_Config::createDefault();
$purifier_config->set('Cache.DefinitionImpl', null); // Disable cache by setting a non-existent directory or an invalid one
$purifier_config->set('URI.AllowedSchemes', ['data' => true, 'src' => true, 'http' => true, 'https' => true]);
$purifier_config->set('URI.AllowedSchemes', purifierUriSchemes());
// Classes our scripts act on (ajax-modal fetches a page and runs it) never come from stored HTML
$purifier_config->set('Attr.ForbiddenClasses', ['ajax-modal']);
$purifier = new HTMLPurifier($purifier_config);

View File

@@ -20,7 +20,7 @@ require "../libs/htmlpurifier/HTMLPurifier.standalone.php";
$purifier_config = HTMLPurifier_Config::createDefault();
$purifier_config->set('Cache.DefinitionImpl', null); // Disable cache by setting a non-existent directory or an invalid one
$purifier_config->set('URI.AllowedSchemes', ['data' => true, 'src' => true, 'http' => true, 'https' => true]);
$purifier_config->set('URI.AllowedSchemes', purifierUriSchemes());
$purifier = new HTMLPurifier($purifier_config);
$ticket_id = intval($_GET['id'] ?? 0);

View File

@@ -900,7 +900,7 @@ function documentHtmlPurify($html) {
require_once __DIR__ . '/../libs/htmlpurifier/HTMLPurifier.standalone.php';
$config = HTMLPurifier_Config::createDefault();
$config->set('Cache.DefinitionImpl', null);
$config->set('URI.AllowedSchemes', ['data' => true, 'src' => true, 'http' => true, 'https' => true]);
$config->set('URI.AllowedSchemes', purifierUriSchemes());
// Classes our scripts act on (ajax-modal fetches a page and runs it) never come from stored HTML
$config->set('Attr.ForbiddenClasses', ['ajax-modal']);
$purifier = new HTMLPurifier($config);

View File

@@ -9,6 +9,16 @@ function escapeHtml($unsanitizedInput) {
return htmlspecialchars($unsanitizedInput ?? '', ENT_QUOTES, 'UTF-8');
}
/**
* The kinds of address HTMLPurifier lets through in links and pictures, wherever it is set up -
* documents, the Knowledge Base, tickets: web links, email (mailto:) and phone (tel:) links, and
* pictures in the HTML itself (data:). HTMLPurifier checks each - a mailto: must be an address, a
* tel: a number, a data: a picture - and anything else, javascript: among them, is taken out.
*/
function purifierUriSchemes() {
return ['data' => true, 'src' => true, 'http' => true, 'https' => true, 'mailto' => true, 'tel' => true];
}
function escapeSql($input) {
global $mysqli;

View File

@@ -7,7 +7,7 @@ require_once "../libs/htmlpurifier/HTMLPurifier.standalone.php";
$purifier_config = HTMLPurifier_Config::createDefault();
$purifier_config->set('Cache.DefinitionImpl', null); // Disable cache by setting a non-existent directory or an invalid one
$purifier_config->set('URI.AllowedSchemes', ['data' => true, 'src' => true, 'http' => true, 'https' => true]);
$purifier_config->set('URI.AllowedSchemes', purifierUriSchemes());
$purifier = new HTMLPurifier($purifier_config);
if (!isset($_GET['task_approval_id'], $_GET['url_key'])) {

View File

@@ -33,7 +33,7 @@ require "../libs/htmlpurifier/HTMLPurifier.standalone.php";
$purifier_config = HTMLPurifier_Config::createDefault();
$purifier_config->set('Cache.DefinitionImpl', null); // Disable cache by setting a non-existent directory or an invalid one
$purifier_config->set('URI.AllowedSchemes', ['data' => true, 'src' => true, 'http' => true, 'https' => true]);
$purifier_config->set('URI.AllowedSchemes', purifierUriSchemes());
$purifier = new HTMLPurifier($purifier_config);
$company = billingCompany();