-
-
Notifications
You must be signed in to change notification settings - Fork 239
Various security improvements #1473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| <?php | ||
|
|
||
| namespace Backend\Controllers; | ||
|
|
||
| use Backend\Behaviors\FormController; | ||
| use Backend\Classes\Controller; | ||
| use Backend\Facades\BackendAuth; | ||
| use Backend\Facades\BackendMenu; | ||
| use System\Classes\SettingsManager; | ||
|
|
||
| /** | ||
| * My Account controller | ||
| * | ||
| * Allows any authenticated backend user to manage their own account settings. | ||
| * Isolated from the Users controller to prevent privilege escalation via | ||
| * handler dispatch on a controller with degraded permissions. | ||
| * | ||
| * @package winter\wn-backend-module | ||
| * @author Winter CMS | ||
| */ | ||
| class MyAccount extends Controller | ||
| { | ||
| /** | ||
| * @var array Extensions implemented by this controller. | ||
| */ | ||
| public $implement = [ | ||
| FormController::class, | ||
| ]; | ||
|
|
||
| /** | ||
| * @var array Permissions required to view this page. | ||
| * Empty array — any logged-in user can access their own account. | ||
| */ | ||
| public $requiredPermissions = []; | ||
|
|
||
| /** | ||
| * @var string HTML body tag class | ||
| */ | ||
| public $bodyClass = 'compact-container'; | ||
|
|
||
| public $formLayout = 'sidebar'; | ||
|
|
||
| /** | ||
| * Constructor. | ||
| */ | ||
| public function __construct() | ||
| { | ||
| parent::__construct(); | ||
|
|
||
| BackendMenu::setContext('Winter.System', 'system', 'users'); | ||
| SettingsManager::setContext('Winter.Backend', 'myaccount'); | ||
| } | ||
|
|
||
| /** | ||
| * My Account page | ||
| */ | ||
| public function index() | ||
| { | ||
| $this->pageTitle = 'backend::lang.myaccount.menu_label'; | ||
| return $this->asExtension('FormController')->update($this->user->id, 'myaccount'); | ||
| } | ||
|
|
||
| /** | ||
| * Save handler for the My Account form | ||
| */ | ||
| public function index_onSave() | ||
| { | ||
| $result = $this->asExtension('FormController')->update_onSave($this->user->id, 'myaccount'); | ||
|
|
||
| /* | ||
| * If the password or login name has been updated, reauthenticate the user | ||
| */ | ||
| $loginChanged = $this->user->login != post('User[login]'); | ||
| $passwordChanged = strlen(post('User[password]')); | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if ($loginChanged || $passwordChanged) { | ||
| BackendAuth::login($this->user->reload(), true); | ||
| } | ||
|
|
||
| return $result; | ||
| } | ||
| } | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # =================================== | ||
| # Form Behavior Config | ||
| # =================================== | ||
|
|
||
| name: backend::lang.user.name | ||
| form: ~/modules/backend/models/user/fields.yaml | ||
| modelClass: Backend\Models\User | ||
| defaultRedirect: backend/myaccount | ||
|
|
||
| update: | ||
| redirect: backend/myaccount | ||
| redirectClose: backend/myaccount |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| <?php if ($this->user->hasAccess('backend.manage_users')): ?> | ||
| <?php Block::put('breadcrumb') ?> | ||
| <ul> | ||
| <li><a href="<?= Backend::url('backend/users') ?>"><?= e(trans('backend::lang.user.menu_label')) ?></a></li> | ||
| <li><?= e(trans($this->pageTitle)) ?></li> | ||
| </ul> | ||
| <?php Block::endPut() ?> | ||
| <?php endif ?> | ||
|
|
||
| <?php if (!$this->fatalError): ?> | ||
|
|
||
| <?php Block::put('form-contents') ?> | ||
| <div class="layout"> | ||
|
|
||
| <div class="layout-row"> | ||
| <?= $this->formRenderOutsideFields() ?> | ||
| <?= $this->formRenderPrimaryTabs() ?> | ||
| </div> | ||
|
|
||
| <div class="form-buttons"> | ||
| <div class="loading-indicator-container"> | ||
| <button | ||
| type="submit" | ||
| data-request="onSave" | ||
| data-browser-validate | ||
| data-request-data="redirect:0" | ||
| data-hotkey="ctrl+s, cmd+s" | ||
| data-load-indicator="<?= e(trans('backend::lang.form.saving')) ?>" | ||
| class="btn btn-primary"> | ||
| <?= e(trans('backend::lang.form.save')) ?> | ||
| </button> | ||
| </div> | ||
| </div> | ||
|
|
||
| </div> | ||
| <?php Block::endPut() ?> | ||
|
|
||
| <?php Block::put('form-sidebar') ?> | ||
| <div class="hide-tabs"><?= $this->formRenderSecondaryTabs() ?></div> | ||
| <?php Block::endPut() ?> | ||
|
|
||
| <?php Block::put('body') ?> | ||
| <?= Form::open(['class'=>'layout stretch']) ?> | ||
| <?= $this->makeLayout('form-with-sidebar') ?> | ||
| <?= Form::close() ?> | ||
| <?php Block::endPut() ?> | ||
|
|
||
| <?php else: ?> | ||
| <div class="control-breadcrumb"> | ||
| <?= Block::placeholder('breadcrumb') ?> | ||
| </div> | ||
| <div class="padded-container"> | ||
| <p class="flash-message static error"><?= e(trans($this->fatalError)) ?></p> | ||
| <p><a href="<?= Backend::url('backend') ?>" class="btn btn-default"><?= e(trans('backend::lang.form.return_to_list')) ?></a></p> | ||
| </div> | ||
| <?php endif ?> |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.