diff --git a/CHANGELOG.md b/CHANGELOG.md
index c0dc12d64..0e5b5b51d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,11 +6,11 @@ This file documents all notable changes made to ITFlow.
### Upgrading
-Update from Maintenance > Update — Queue Update hands the job to cron, which updates the files and applies this release's three database changes (3.6.6 to 3.6.9) in the same pass. They add four tables for RMM providers and their alerts, and a setting for device actions, and change nothing that is there. Nothing else is required. This release has three security fixes - see Security.
+Update from Maintenance > Update — Queue Update hands the job to cron, which updates the files and applies this release's four database changes (3.6.6 to 3.7.0) in the same pass. They add four tables for RMM providers and their alerts, a setting for device actions and one for API keys in the address, and change nothing that is there. Nothing else is required. This release has four security fixes - see Security.
### Security
-- API: send your API key in the `X-API-Key` header. A key put in the address (`?api_key=`) was written to your web server's access log with every call, and to a proxy's in front of it - a header isn't. The address and a JSON body still work, so nothing that uses the API breaks, but move your scripts and integrations to the header, then give each one that sent its key in the address a new key and revoke the old one, as the old logs still have it. The API docs now send the key in the header throughout, and the New API Key window says where it goes.
+- API: send your API key in the `X-API-Key` header. A key put in the address (`?api_key=`) was written to your web server's access log with every call, and to a proxy's in front of it - a header isn't. The address and a JSON body still work, so nothing that uses the API breaks, but move your scripts and integrations to the header, then give each one that sent its key in the address a new key and revoke the old one, as the old logs still have it. The API docs now send the key in the header throughout, and the New API Key window says where it goes. Admin > API Keys flags each key sent in the address in the last 30 days, and Admin > Settings > Security has Take API keys in the address - on if your ITFlow had API keys that still worked, so nothing stops when you update, and off on a new ITFlow. Once the flags have gone, turn it off, and a key in the address is turned away from then on.
- Credentials: a login saved with a piece of web page code as its username or password could run that code in the browser of an agent who followed a link made for the purpose. The address ITFlow's own pages use to fetch a login's username and password answered as a web page, so a browser sent straight to it drew what the login held instead of showing it as text - and the code then acted as that agent. It took someone able to get such a login saved - an agent who can edit credentials, or a person sent an Ask for a login link, once an agent had saved what they sent back - and then an agent with access to that login opening the link while signed in. The pages that list and show logins were never affected. That answer now says it is data, which no browser draws as a page, and so do sixteen like it that carried only text ITFlow had already made safe. Releases from 26.10 to 26.11.8 are affected, and there is nothing to do after updating.
- Invites: with a login key required, the page behind an agent's invite link went on showing the sign-in address with the key in it after the invite had been cancelled or had run out. Someone whose invite was withdrawn could still read the key from their old link. The key signs no one in by itself - it only opens the agents' sign-in page, which still asks for an email and password. A cancelled or run-out link now leads to the plain sign-in page. Releases from 26.11 to 26.11.8 are affected. If you cancelled an invite because the person should never have had it, change the login key in Admin > Settings > Security.
- Client access: an agent limited to some clients could read a few names belonging to the others, by putting a record's number in a page's address - a project's name on the tickets list, a site's name, a ticket's subject and an invoice's number on Trips and its export window, a vendor's name in the domains export window, and a client's name on Update Prices and in the message when an AI request was turned away. Nothing else of those records showed, and nothing could be changed. These names now show only for clients the agent can open. Releases from 26.09 to 26.11.8 are affected.
@@ -110,6 +110,7 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u
- Picture fields: `pictureField($name, $remove_name, $current, $empty, $opts)` (`functions/picture.php`) renders the picture as a button with a camera badge, a hidden file input named `$name` and a hidden `$remove_name` input; `js/picture_field.js` opens the Picture window over the form's own (the window stacking in `js/app.js`), crops on a canvas and puts the crop in the file input through `DataTransfer` - a JPG for a JPG, else WebP, PNG where the browser can't write WebP - and sets the remove input to 1 on Remove, so the forms post the same fields as before and no handler changed. Options: `round`, `shapes`, `max`, `class` (the new picture's ``), `box` and `name` (the field the initials follow). `picturePhoto()` and `picturePhotoEmpty()` are a photo's two looks. Used on the profile, Admin > Users, contacts, assets, locations and racks, replacing their file inputs, remove boxes and preview scripts. A browser without `DataTransfer` gets the file picker and the file as picked. Free crops: `shapes => 'free'` gives a frame with corner and edge handles over the whole picture instead of the fixed-shape crop, `trim` adds Trim the edges (transparent, or within a small distance of the corner colour, found on a downscaled probe), `accept` sets the file types - with `application/pdf` a PDF is used as it is - and `submit` sends the form once a picture is used; `box` adds `tall` (a receipt) and `logo`, and `pictureFile()` is a PDF's look. A PNG source stays PNG when the field doesn't take WebP, so a logo keeps its transparency. Used on the expense form and quick look (`expense_receipt_save` is now posted as a hidden field), Admin > Settings > Company details and the setup wizard's company and account steps; `js/setup.js` loses its `data-setup-image` preview and checks, and `.itflow-setup-preview` is gone.
- `cron/ticket_email_parser.php` no longer writes its run summary to App Logs - it echoes the counts and the time for a run from the command line - and ends with `cronJobStop("No mailbox is set up to read - see Admin > Settings > Mail")` when `config_imap_provider` is empty instead of logging. `cron/mail_queue.php` does the same with no `config_smtp_provider`. `cron/mail_queue.php`, `ticket_sla.php`, `domain_refresher.php` and `certificate_refresher.php` stop with `config_enable_cron` off without a `logApp()` error, as the parser has since 26.11.4.
- `apiKeyFromRequest()` (`functions/api_keys.php`) reads the key an API call came with for `api/v1/validate_api_key.php` - the `X-API-Key` header (`HTTP_X_API_KEY`), else the JSON body's `api_key`, else the query string's; one that's empty or not a string counts as none, a 401 with an empty body. The key was also escaped twice on its way in; it's escaped once now.
+- Database 3.7.0: `api_keys.api_key_address_at`, when a key last came in a call's address (`apiKeyNoteAddress()`, at most once a minute), and `settings.config_api_key_in_address` - on where a key that hadn't expired was there at the update, off otherwise and in `db.sql`. `apiKeyInAddress()` says whether a call's query string has an `api_key`. With `apiKeyInAddressAccepted()` false (read guarded, so true before the update), `api/v1/validate_api_key.php` answers a working key in the address with a 401 and a message, and logs it as an `API` `Failed` against the key without counting it toward `apiKeyWatch()` - even when a header sends the key too, as the address is logged all the same. Admin > API Keys reads `api_key_address_at` for its flag and note, and Admin > Settings > Security saves the switch.
## [26.11.8]
diff --git a/admin/api_keys.php b/admin/api_keys.php
index 374f785c5..fdeea5d7a 100644
--- a/admin/api_keys.php
+++ b/admin/api_keys.php
@@ -6,7 +6,8 @@
* they see, whether the key works (it expires, and an agent who is
* disabled, archived or has no role turns every call away), when it was
* last used and from where, and its calls over the last 30 days - each
- * opening what it was used for (modals/api/api_key_usage.php). A revoked key
+ * opening what it was used for (modals/api/api_key_usage.php), and a key sent
+ * in a call's address, where the web server's access log keeps it. A revoked key
* has expired, so it moves to Expired, where it can be deleted. The work is in functions/api_keys.php; the handlers are
* admin/post/api_keys.php.
*/
@@ -34,7 +35,7 @@ if (!isset($sortable_columns[$sort])) {
$today = date('Y-m-d');
$search = "(api_key_name LIKE '%$q%' OR user_name LIKE '%$q%')";
-$sql = mysqli_query($mysqli, "SELECT SQL_CALC_FOUND_ROWS api_key_id, api_key_name, api_key_secret, api_key_created_at, api_key_expire, api_key_user_id, api_key_last_used_at,
+$sql = mysqli_query($mysqli, "SELECT SQL_CALC_FOUND_ROWS api_key_id, api_key_name, api_key_secret, api_key_created_at, api_key_expire, api_key_user_id, api_key_last_used_at, api_key_address_at,
user_name, user_avatar, user_type, user_status, user_archived_at, user_role_id
FROM api_keys
LEFT JOIN users ON user_id = api_key_user_id
@@ -53,6 +54,11 @@ $access = userClientAccess(array_filter(array_map('intval', array_column($keys,
// What each is used for, the last 30 days (functions/api_keys.php)
$usage = apiKeyUsageSummary(array_keys($keys));
+// Keys that still work and came in a call's address lately - what to move to the header (functions/api_keys.php)
+$address_since = date('Y-m-d H:i:s', strtotime('-30 days'));
+$address_keys = intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(*) FROM api_keys WHERE api_key_expire > '$today' AND api_key_address_at > '$address_since'"))[0]);
+$address_taken = apiKeyInAddressAccepted();
+
$counts = mysqli_fetch_row(mysqli_query($mysqli, "SELECT COALESCE(SUM(api_key_expire > '$today'), 0), COALESCE(SUM(api_key_expire <= '$today'), 0)
FROM api_keys LEFT JOIN users ON user_id = api_key_user_id WHERE $search"));
@@ -72,6 +78,22 @@ $csrf = $_SESSION['csrf_token'];
+
+
+