Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config/global.ini.php
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,9 @@
; notifications to hide, by ID. Only some notifications can be hidden, e.g. the warning about the PHP security
; advisory of 2026-10-21, when your Linux distribution has backported the fix without changing the PHP version number:
;disabled_notifications[] = PhpSecurityAdvisory_2026_10_21
;
; or the Microsoft 365 SMTP password login warning, when you don't send emails through Microsoft 365 with a password:
;disabled_notifications[] = SmtpBasicAuthRetirementMicrosoft

; Set to 1 if you're using https on your Matomo server and Matomo can't detect it,
; e.g., a reverse proxy using https-to-http, or a web server that doesn't
Expand Down
8 changes: 8 additions & 0 deletions plugins/CoreAdminHome/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,18 @@ public function setMailSettings()
// an access token requested before a change at the provider would otherwise be reused until it expires
StaticContainer::get(SmtpTokenProvider::class)->forgetAccessToken();

$smtpPasswordLoginWarningApplies = SmtpBasicAuthRetirementNotification::appliesTo($mail);
if (!$smtpPasswordLoginWarningApplies) {
// so it doesn't keep showing on report pages until the next admin page
SmtpBasicAuthRetirementNotification::cancel();
}

// the form shows what was stored instead of repeating the rules above
$toReturn = $response->getResponse([
'result' => 'success',
'message' => 'ok',
'hasClientSecret' => $mail['oauth_client_secret'] !== '',
'smtpPasswordLoginWarningApplies' => $smtpPasswordLoginWarningApplies,
]);
} catch (Exception $e) {
$toReturn = $response->getResponseException($e);
Expand Down Expand Up @@ -456,6 +463,7 @@ private function handleGeneralSettingsAdmin($view)
// Whether to display or not the general settings (cron, beta, smtp)
$view->isGeneralSettingsAdminEnabled = self::isGeneralSettingsAdminEnabled();
$view->isMultiServerEnvironment = SettingsPiwik::isMultiServerEnvironment();
$view->areMailSettingsShown = CoreAdminHome::areMailSettingsShownInUi();
$view->isPluginsAdminEnabled = CorePluginsAdmin::isPluginsAdminEnabled();
if ($view->isGeneralSettingsAdminEnabled) {
$this->displayWarningIfConfigFileNotWritable();
Expand Down
15 changes: 15 additions & 0 deletions plugins/CoreAdminHome/CoreAdminHome.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Piwik\Piwik;
use Piwik\Site;
use Piwik\ProxyHttp;
use Piwik\SettingsPiwik;
use Piwik\Plugins\CoreHome\SystemSummary;
use Piwik\Settings\Storage\Backend\PluginSettingsTable;

Expand All @@ -34,9 +35,23 @@ public function registerEvents()
'Translate.getClientSideTranslationKeys' => 'getClientSideTranslationKeys',
'System.addSystemSummaryItems' => 'addSystemSummaryItems',
'FrontController.modifyErrorPage' => 'onModifyErrorPage',
'Controller.triggerAdminNotifications' => 'onTriggerAdminNotifications',
);
}

public function onTriggerAdminNotifications(): void
{
SmtpBasicAuthRetirementNotification::notifyIfNeeded();
}

/**
* Whether the general settings page shows the email server settings.
*/
public static function areMailSettingsShownInUi(): bool
{
return Controller::isGeneralSettingsAdminEnabled() && !SettingsPiwik::isMultiServerEnvironment();
}

public function onModifyErrorPage(&$output, $exception)
{
if (
Expand Down
140 changes: 140 additions & 0 deletions plugins/CoreAdminHome/SmtpBasicAuthRetirementNotification.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<?php

/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/

namespace Piwik\Plugins\CoreAdminHome;

use Piwik\Config;
use Piwik\Container\StaticContainer;
use Piwik\Mail\OAuth\SmtpTokenProvider;
use Piwik\Notification;
use Piwik\Notification\Manager as NotificationManager;
use Piwik\Piwik;
use Piwik\Plugin\Manager as PluginManager;
use Piwik\Request\AuthenticationToken;
use Piwik\Session;
use Piwik\Session\SessionNamespace;
use Piwik\Url;

/**
* Microsoft 365 turns off password logins for SMTP by default from the end of December 2026. The warning goes
* to every super user who sends with a password login, as the host alone can't tell reliably whether the server
* is a Microsoft one. Where the email settings can't be changed in the UI, it points to the config file instead.
*/
class SmtpBasicAuthRetirementNotification
{
public const NOTIFICATION_ID = 'SmtpBasicAuthRetirementMicrosoft';

public static function notifyIfNeeded(): void
{
// a token_auth request is likely an embedded page shown to the public, not a signed-in user
if (Piwik::isUserIsAnonymous() || StaticContainer::get(AuthenticationToken::class)->getAuthToken() !== '') {
return;
}

if (
!Piwik::hasUserSuperUserAccess()
|| NotificationManager::isDisabled(self::NOTIFICATION_ID)
// Matomo Cloud doesn't send through the [mail] settings
|| PluginManager::getInstance()->isPluginActivated('Cloud')
|| !self::appliesTo(Config::getInstance()->mail)
) {
// persistent notifications stay in the session, so drop it once the settings no longer match
self::cancel();
return;
}

// posted once per session, so a warning the user closed stays closed until they sign out
$session = self::getSession();
if ($session !== null && !empty($session->shown)) {
return;
}

$announcementLink = Url::getExternalLinkTag(
'https://techcommunity.microsoft.com/blog/exchange/updated-exchange-online-smtp-auth-basic-authentication-deprecation-timeline/4489835'
);

if (CoreAdminHome::areMailSettingsShownInUi()) {
$settingsUrl = 'index.php' . Url::getCurrentQueryStringWithParametersModified([
'module' => 'CoreAdminHome',
'action' => 'generalSettings',
]) . '#/mailSettings';

$message = Piwik::translate('CoreAdminHome_SmtpBasicAuthRetirementMicrosoft', [
// the rest of the query string comes from the request and the message is not escaped
'<a href="' . htmlspecialchars($settingsUrl, ENT_QUOTES) . '">',
'</a>',
$announcementLink,
'</a>',
]);
} else {
$message = Piwik::translate('CoreAdminHome_SmtpBasicAuthRetirementMicrosoftConfigFile', [
'[mail]',
'config/config.ini.php',
$announcementLink,
'</a>',
]);
}

$notification = new Notification($message);
$notification->raw = true;
$notification->title = Piwik::translate('CoreAdminHome_SmtpBasicAuthRetirementMicrosoftTitle');
$notification->priority = Notification::PRIORITY_HIGH;
$notification->context = Notification::CONTEXT_WARNING;
// persistent, so the reporting UI doesn't clear it before the user closes it
$notification->type = Notification::TYPE_PERSISTENT;
$notification->flags = Notification::FLAG_CLEAR;
NotificationManager::notify(self::NOTIFICATION_ID, $notification);

if ($session !== null) {
$session->shown = true;
}
}

/**
* Whether the given `[mail]` config section sends through SMTP with a password login. Matches
* Transport::initSmtpTransport(), except that blank values count as unset.
*
* @param array<string, mixed> $mail
*/
public static function appliesTo(array $mail): bool
{
if (($mail['transport'] ?? '') !== 'smtp' || trim((string) ($mail['host'] ?? '')) === '') {
return false;
}

$type = trim((string) ($mail['type'] ?? ''));

return $type !== '' && !SmtpTokenProvider::isOAuthType($type);
}

/**
* Removes the warning because it no longer applies. Unlike closing it, this lets it show again in the same
* session once it applies again.
*/
public static function cancel(): void
{
NotificationManager::cancel(self::NOTIFICATION_ID);

$session = self::getSession();
// unsetting a missing key raises a notice on PHP 7 when there is no $_SESSION yet
if ($session !== null && isset($session->shown)) {
unset($session->shown);
}
}

/**
* Null when there is no session, as creating the namespace would start one.
*/
private static function getSession(): ?SessionNamespace
{
return Session::isWritable() && Session::isReadable()
? new SessionNamespace(self::NOTIFICATION_ID)
: null;
}
}
3 changes: 3 additions & 0 deletions plugins/CoreAdminHome/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@
"SendPluginUpdateCommunication": "Send an email when a plugin update is available",
"SendPluginUpdateCommunicationHelp": "An email will be sent to Super Users when there is a new version available for a plugin.",
"SettingsSaveSuccess": "Settings updated.",
"SmtpBasicAuthRetirementMicrosoft": "From the end of December 2026, Microsoft will disable password-based SMTP authentication by default. If you use Microsoft 365 to send emails from Matomo, update your authentication method to OAuth 2.0 in %1$syour email settings%2$s to keep scheduled reports, alerts and other emails working. %3$sLearn more%4$s",
"SmtpBasicAuthRetirementMicrosoftConfigFile": "From the end of December 2026, Microsoft will disable password-based SMTP authentication by default. If you use Microsoft 365 to send emails from Matomo, update your authentication method to OAuth 2.0 in the %1$s section of your %2$s file to keep scheduled reports, alerts and other emails working. %3$sLearn more%4$s",
"SmtpBasicAuthRetirementMicrosoftTitle": "Microsoft 365 email authentication is changing",
"SmtpOAuthAuthenticationHelp": "Matomo requests an access token from your email provider with the settings below and signs in with it instead of a password.",
"SmtpOAuthCertificate": "Certificate",
"SmtpOAuthCertificateConfigured": "Matomo signs in with the certificate at %1$s, set in config.ini.php.",
Expand Down
4 changes: 2 additions & 2 deletions plugins/CoreAdminHome/templates/generalSettings.twig
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
{{ 'General_GoTo2'|translate }}:
{% if isGeneralSettingsAdminEnabled %}
<a href="#/archivingSettings">{{ 'CoreAdminHome_ArchivingSettings'|translate }}</a>
{% if not isMultiServerEnvironment %}
{% if areMailSettingsShown %}
<a href="#/mailSettings">{{ 'CoreAdminHome_EmailServerSettings'|translate }}</a>
{% endif %}
{% endif %}
Expand All @@ -40,7 +40,7 @@
today-archive-time-to-live-default="{{ todayArchiveTimeToLiveDefault }}"
></div>

{% if not isMultiServerEnvironment %}
{% if areMailSettingsShown %}
<div
vue-entry="CoreAdminHome.SmtpSettings"
mail="{{ mail|json_encode }}"
Expand Down
35 changes: 35 additions & 0 deletions plugins/CoreAdminHome/tests/Integration/ControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
use Piwik\Db;
use Piwik\Exception\UnexpectedWebsiteFoundException;
use Piwik\Mail\OAuth\SmtpTokenProvider;
use Piwik\Notification;
use Piwik\Notification\Manager as NotificationManager;
use Piwik\Plugins\CoreAdminHome\CoreAdminHome;
use Piwik\Plugins\CoreAdminHome\Controller;
use Piwik\Plugins\CoreAdminHome\OptOutManager;
use Piwik\Plugins\CoreAdminHome\SmtpBasicAuthRetirementNotification;
use Piwik\Piwik;
use Piwik\Plugins\Login\PasswordVerifier;
use Piwik\Plugins\UsersManager\API as UsersManagerAPI;
Expand Down Expand Up @@ -354,6 +357,37 @@ public function testSetMailSettingsRemovesThePasswordWhenOAuthIsUsed(): void
$this->assertSame('', Config::getInstance()->mail['password']);
}

/**
* @dataProvider getSavedLoginsForTheSmtpPasswordLoginWarning
*/
public function testSetMailSettingsRemovesTheSmtpPasswordLoginWarningOnceItNoLongerApplies(
bool $useOAuth,
array $changes,
bool $isWarningKept
): void {
$notificationId = SmtpBasicAuthRetirementNotification::NOTIFICATION_ID;
NotificationManager::notify($notificationId, new Notification('Switch to OAuth 2.0'));

$request = $useOAuth
? $this->getOAuthMailSettingsRequest($changes)
: $changes + $this->getMailSettingsRequest('post.example.test');
$response = $this->postMailSettings($request);

$this->assertSame('success', $response['result']);
$this->assertSame($isWarningKept, $response['smtpPasswordLoginWarningApplies']);
$this->assertSame(
$isWarningKept,
array_key_exists($notificationId, NotificationManager::getPendingInMemoryNotifications())
);
}

public function getSavedLoginsForTheSmtpPasswordLoginWarning(): iterable
{
yield 'switched to OAuth 2.0' => [true, [], false];
yield 'switched to mail() instead of SMTP' => [false, ['mailUseSmtp' => '0', 'mailType' => 'Login'], false];
yield 'still a password login' => [false, ['mailType' => 'Login'], true];
}

public function testSetMailSettingsRemovesTheClientSecretWhenTheCertificateIsUsed(): void
{
$this->setStoredOAuthSettings();
Expand Down Expand Up @@ -704,6 +738,7 @@ public function testWhatIsNewLeavesInternalLinksUnchangedWhenNoDefaultIdSiteIsAv
public function tearDown(): void
{
$this->deleteAllChanges();
NotificationManager::cancelAllNotifications();
$_GET = $this->backupGet;
$_POST = $this->backupPost;
$_REQUEST = $this->backupRequest;
Expand Down
Loading
Loading