Skip to content

Commit ecef4ff

Browse files
committed
fix(auth): switch user edit to field allowlist
The edit() method passed $request->post() directly to User::update() after unsetting only a few keys. This denylist approach allowed injection of sensitive fields like role and api_token. Switching to $request->only() ensures only explicitly listed profile fields can be mass-assigned through this endpoint.
1 parent 4ed25f4 commit ecef4ff

1 file changed

Lines changed: 9 additions & 13 deletions

File tree

app/Http/Controllers/UserController.php

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -819,34 +819,30 @@ public function edit($id, Request $request)
819819
$Groups = new Group;
820820
$Groups = $Groups->findAll();
821821

822-
$data = $request->post();
823-
824822
if (! Fixometer::hasRole($User->find($id), 'Administrator')) {
825-
$sent_groups = $data['groups'];
823+
$sent_groups = $request->input('groups');
826824
}
827825

826+
$data = $request->only([
827+
'name', 'email', 'location', 'age', 'gender', 'country_code',
828+
'biography', 'language', 'newsletter', 'invites',
829+
]);
830+
828831
$error = false;
829832
// check for email in use
830833
$editingUser = $User->find($id);
831834
if ($editingUser->email !== $data['email'] && ! $User->checkEmail($data['email'])) {
832835
$error['email'] = 'The email you entered is already in use in our database. Please use another one.';
833836
}
834837

835-
if (! empty($data['new-password'])) {
836-
if ($data['new-password'] !== $data['password-confirm']) {
838+
if (! empty($request->input('new-password'))) {
839+
if ($request->input('new-password') !== $request->input('password-confirm')) {
837840
$error['password'] = 'The passwords are not identical!';
838841
} else {
839-
$data['password'] = Hash::make($data['new-password']);
842+
$data['password'] = Hash::make($request->input('new-password'));
840843
}
841844
}
842845

843-
unset($data['new-password']);
844-
unset($data['password-confirm']);
845-
846-
unset($data['groups']);
847-
unset($data['profile']);
848-
unset($data['id']);
849-
850846
if (! is_array($error)) {
851847
$u = $User->find($id)->update($data);
852848

0 commit comments

Comments
 (0)