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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- Element edit pages once again redirect to their referral URL on save. ([#18483](https://github.com/craftcms/cms/pull/18483))
- Added `craft\filters\IpRateLimitIdentity`. ([#18510](https://github.com/craftcms/cms/pull/18510))
- Removed thamtech/yii2-ratelimiter-advanced. ([#18510](https://github.com/craftcms/cms/pull/18510))
- Fixed a bug where global set GraphQL query caches weren’t getting invalidated when global sets were updated. ([#18479](https://github.com/craftcms/cms/issues/18479))
Expand All @@ -16,6 +17,7 @@
- Fixed a JavaScript error that could occur on element edit pages.
- Fixed a bug where cross-site validation errors weren’t preventing elements from getting saved. ([#18292](https://github.com/craftcms/cms/issues/18292))
- Fixed a bug where failure messages when pasting elements weren’t getting displayed properly.
- Fixed a bug where `craft\helpers\UrlHelper::cpReferralUrl()` was returning the referrer URL even if it had the same URI as the current page. ([#18483](https://github.com/craftcms/cms/pull/18483))

## 5.9.14 - 2026-02-25

Expand Down
2 changes: 1 addition & 1 deletion src/controllers/ElementsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ public function actionEdit(?ElementInterface $element, ?int $elementId = null):
[$docTitle, $title] = $this->_editElementTitles($element);
$enabledForSite = $element->getEnabledForSite();
$hasRoute = $element->getRoute() !== null;
$redirectUrl = $this->request->getValidatedQueryParam('returnUrl') ?? ElementHelper::postEditUrl($element);
$redirectUrl = $this->request->getValidatedQueryParam('returnUrl') ?? UrlHelper::cpReferralUrl() ?? ElementHelper::postEditUrl($element);

// Site statuses
if ($canEditMultipleSites) {
Expand Down
12 changes: 10 additions & 2 deletions src/helpers/UrlHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -584,8 +584,7 @@ public static function cpReferralUrl(): ?string
{
$referrer = Craft::$app->getRequest()->getReferrer();

// Make sure it didn't refer itself
if ($referrer === Craft::$app->getRequest()->getFullUri()) {
if ($referrer === null) {
return null;
}

Expand All @@ -594,6 +593,15 @@ public static function cpReferralUrl(): ?string
return null;
}

// to ensure we're comparing uris strip base cp url and query string from the referrer first
$referrerFullUri = ltrim(StringHelper::removeLeft($referrer, self::baseCpUrl()), '/');
$referrerFullUri = substr($referrerFullUri, 0, strpos($referrerFullUri, '?') ?: null);

// Make sure it didn't refer itself
if ($referrerFullUri === Craft::$app->getRequest()->getFullUri()) {
return null;
}

return $referrer;
}

Expand Down
Loading