diff --git a/CHANGELOG.md b/CHANGELOG.md index 029c36974eb..0b55cec4903 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Release Notes for Craft CMS 3.x +## Unreleased + +- Fixed a bug where `craft\web\Request::getIsPreview()` was returning `true` for requests with expired tokens. ([#14066](https://github.com/craftcms/cms/discussions/14066)) + ## 3.9.10 - 2024-01-02 - Fixed a bug where meta fields weren’t immediately showing change indicators when entries were autosaved. diff --git a/src/web/Request.php b/src/web/Request.php index 363849df4b2..999b10dcd86 100644 --- a/src/web/Request.php +++ b/src/web/Request.php @@ -710,7 +710,11 @@ public function getActionSegments() */ public function getIsPreview(): bool { - return $this->getQueryParam('x-craft-preview') !== null || $this->getQueryParam('x-craft-live-preview') !== null; + return ( + ($this->getQueryParam('x-craft-preview') ?? $this->getQueryParam('x-craft-live-preview')) !== null && + // If there's a token but it expired, they're looking at the live site + (!$this->getHadToken() || $this->getToken() !== null) + ); } /**