diff --git a/CHANGELOG.md b/CHANGELOG.md index e2ad6f1f0bd..6150b4b88e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Release Notes for Craft CMS 4 +## Unreleased + +- Fixed a bug where the control panel could display a notice about the Craft CMS license belonging to a different domain, even when accessing the control panel from the correct domain. ([#16396](https://github.com/craftcms/cms/issues/16396)) + ## 4.13.9 - 2025-01-06 - Fixed a bug where custom fields could cause validation errors when running the `users/create` command. diff --git a/src/base/ApplicationTrait.php b/src/base/ApplicationTrait.php index 302f791dd31..3ced3419304 100644 --- a/src/base/ApplicationTrait.php +++ b/src/base/ApplicationTrait.php @@ -619,7 +619,7 @@ public function getEditionHandle(): string */ public function getLicensedEdition(): ?int { - $licenseInfo = $this->getCache()->get('licenseInfo') ?: []; + $licenseInfo = $this->getCache()->get(App::licenseInfoCacheKey()) ?: []; if (!isset($licenseInfo['craft']['edition'])) { return null; diff --git a/src/helpers/Api.php b/src/helpers/Api.php index 7b86157e5de..50ab5bd504d 100644 --- a/src/helpers/Api.php +++ b/src/helpers/Api.php @@ -187,7 +187,8 @@ public static function processResponseHeaders(array $headers): void // license info if (isset($headers['x-craft-license-info'])) { - $oldLicenseInfo = $cache->get('licenseInfo') ?: []; + $licenseInfoCacheKey = App::licenseInfoCacheKey(); + $oldLicenseInfo = $cache->get($licenseInfoCacheKey) ?: []; $licenseInfo = []; $allCombinedInfo = array_filter(explode(',', reset($headers['x-craft-license-info']))); foreach ($allCombinedInfo as $combinedInfo) { @@ -216,7 +217,7 @@ public static function processResponseHeaders(array $headers): void 'timestamp' => $timestamp, ]; } - $cache->set('licenseInfo', $licenseInfo, $duration); + $cache->set($licenseInfoCacheKey, $licenseInfo, $duration); } } diff --git a/src/helpers/App.php b/src/helpers/App.php index 3f4ecc0b498..8ed1de3a357 100644 --- a/src/helpers/App.php +++ b/src/helpers/App.php @@ -1220,6 +1220,21 @@ public static function createFormattingLocale(): Locale return Craft::$app->getLocale(); } + /** + * Returns the cache key that licensing info should be stored with. + * + * @return string + * @internal + */ + public static function licenseInfoCacheKey(): string + { + $request = Craft::$app->getRequest(); + if ($request->getIsConsoleRequest()) { + return 'licenseInfo'; + } + return sprintf('licenseInfo@%s', $request->getHostName()); + } + /** * Returns all known licensing issues. * @@ -1237,7 +1252,8 @@ public static function licensingIssues(bool $withUnresolvables = true, bool $fet $updatesService = Craft::$app->getUpdates(); $cache = Craft::$app->getCache(); - $isInfoCached = $cache->exists('licenseInfo') && $updatesService->getIsUpdateInfoCached(); + $licenseInfoCacheKey = static::licenseInfoCacheKey(); + $isInfoCached = $cache->exists($licenseInfoCacheKey) && $updatesService->getIsUpdateInfoCached(); if (!$isInfoCached) { if (!$fetch) { @@ -1249,7 +1265,7 @@ public static function licensingIssues(bool $withUnresolvables = true, bool $fet $issues = []; - $allLicenseInfo = $cache->get('licenseInfo') ?: []; + $allLicenseInfo = $cache->get($licenseInfoCacheKey) ?: []; $pluginsService = Craft::$app->getPlugins(); $generalConfig = Craft::$app->getConfig()->getGeneral(); $consoleUrl = rtrim(Craft::$app->getPluginStore()->craftIdEndpoint, '/'); diff --git a/src/services/Plugins.php b/src/services/Plugins.php index f1f861f459e..2a4e862926c 100644 --- a/src/services/Plugins.php +++ b/src/services/Plugins.php @@ -1013,7 +1013,7 @@ public function getPluginInfo(string $handle): array $info['hasCpSettings'] = ($plugin !== null && $plugin->hasCpSettings); $info['licenseKey'] = $pluginInfo['licenseKey'] ?? null; - $licenseInfo = Craft::$app->getCache()->get('licenseInfo') ?? []; + $licenseInfo = Craft::$app->getCache()->get(App::licenseInfoCacheKey()) ?? []; $pluginCacheKey = StringHelper::ensureLeft($handle, 'plugin-'); $info['licenseId'] = $licenseInfo[$pluginCacheKey]['id'] ?? null; $info['licensedEdition'] = $licenseInfo[$pluginCacheKey]['edition'] ?? null; @@ -1195,10 +1195,11 @@ public function setPluginLicenseKey(string $handle, ?string $licenseKey = null): // Clear the plugin's cached license key status $cache = Craft::$app->getCache(); - $licenseInfo = $cache->get('licenseInfo') ?? []; + $cacheKey = App::licenseInfoCacheKey(); + $licenseInfo = $cache->get($cacheKey) ?? []; if (isset($licenseInfo[$handle])) { unset($licenseInfo[$handle]); - $cache->set('licenseInfo', $licenseInfo); + $cache->set($cacheKey, $licenseInfo); } return true; diff --git a/src/web/twig/variables/Cp.php b/src/web/twig/variables/Cp.php index 24892301cfb..880a4381837 100644 --- a/src/web/twig/variables/Cp.php +++ b/src/web/twig/variables/Cp.php @@ -489,7 +489,7 @@ public function settings(): array public function areAlertsCached(): bool { // The license key status gets cached on each Craftnet request - return (Craft::$app->getCache()->get('licenseInfo') !== false); + return (Craft::$app->getCache()->get(App::licenseInfoCacheKey()) !== false); } /**