Repository navigation
[6.x] Return to plugin settings after "Save and continue editing" - #20619
Merged
Merged
Conversation
Save and continue editing posts no redirect, so saveSettings() fell back
to back(), which follows the Referer. A browser that sends only the origin
as the Referer landed on the front-end homepage. Craft 5's settings form
posted an explicit redirect to settings/plugins/{handle}; default to that.
Amp-Thread-ID: https://ampcode.com/threads/T-01a1cf29-3473-71f2-90eb-bc081d7fb15b
Co-authored-by: Amp <amp@ampcode.com>
📚 Storybook previews@craftcms/ui — open Storybook No changed components detected in this Storybook. resources/js — open Storybook No changed components detected in this Storybook. |
[ci skip] Amp-Thread-ID: https://ampcode.com/threads/T-01a1cf29-3473-71f2-90eb-bc081d7fb15b Co-authored-by: Amp <amp@ampcode.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
On a plugin's settings screen, "Save and continue editing" (the Save menu item and Ctrl/Command + S) posts no
redirect.PluginsController::saveSettings()then fell back toback(), which follows the Referer header. A browser that sends only the origin as the Referer, such as one in an embedded frame or withReferrer-Policy: origin, saved successfully and then landed on the front-end homepage.How 5.x handled it. 5.x never used the Referer here:
settings/plugins/_settings.twiggave "Save and continue editing" an explicit hashed redirect tosettings/plugins/{handle}, marked as the save shortcut.Controller::asSuccess()fell back toredirectToPostedUrl(), which used the current request's path.Why the fix is in
saveSettings()and notasSuccess(). The 5.x request-path fallback worked because 5.x forms posted to their own page URL with anactionparam. 6.x posts to dedicated routes such assettings/plugins/{handle}/enableandutilities/clear-caches, many of which have no GET route. MakingasSuccess()fall back to the request URL would send those requests to a 404 or 405. Here, the 5.x behavior was the explicit redirect to the settings page, and that's what this restores:redirectstill wins, so the plain Save button still lands on Settings.plugins/save-plugin-settingsaction from their own pages (the yii2-adapter bridge) keepback(). Sending them tosettings/plugins/{handle}could take them away from a custom settings page.Other things the port missed, not changed here:
CpScreenResponse::saveShortcutRedirectUrl()(set byVolumesControllerandEditElementController) reaches the Inertia shell assaveShortcutRedirect, but nothing inresources/jsreads it. It's also sent unencrypted, so the client couldn't post it asredirectas it is. In 5.x,cp.twighashed it andCP.jsposted it on Ctrl/Command + S. Those screens currently work anyway, throughasModelSuccess()'s fallback to the edit URL.asSuccess()'sback()have the same exposure to an origin-only Referer.asFailure()'sback()and Laravel'surl()->previous()forValidationExceptionand form requests. With an origin-only Referer, a plugin settings save that fails validation still redirects to/. A fix for that would cover every control panel form, so it belongs in its own change.Evidence
New test in
PluginsControllerTest:Expected 'https://localhost/admin/settings/plugins/test-plugin',Actual 'http://localhost'.After: passes, along with the rest of
PluginsControllerTest(39 tests).