Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit928315f

Browse files
f0sselkylecarbs
authored andcommitted
fix: allow admins to reset their own pass without old_password (#2222)
1 parent8eaa853 commit928315f

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

‎coderd/users.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,6 @@ func (api *API) putUserStatus(status database.UserStatus) func(rw http.ResponseW
384384
func (api*API)putUserPassword(rw http.ResponseWriter,r*http.Request) {
385385
var (
386386
user=httpmw.UserParam(r)
387-
apiKey=httpmw.APIKey(r)
388387
params codersdk.UpdateUserPasswordRequest
389388
)
390389

@@ -410,10 +409,13 @@ func (api *API) putUserPassword(rw http.ResponseWriter, r *http.Request) {
410409
return
411410
}
412411

413-
// we want to require old_password field if the user is changing their
414-
// own password. This is to prevent a compromised session from being able
415-
// to change password and lock out the user.
416-
ifuser.ID==apiKey.UserID {
412+
// admins can change passwords without sending old_password
413+
ifparams.OldPassword=="" {
414+
if!api.Authorize(rw,r,rbac.ActionUpdate,rbac.ResourceUser.WithID(user.ID.String())) {
415+
return
416+
}
417+
}else {
418+
// if they send something let's validate it
417419
ok,err:=userpassword.Compare(string(user.HashedPassword),params.OldPassword)
418420
iferr!=nil {
419421
httpapi.Write(rw,http.StatusInternalServerError, httpapi.Response{

‎coderd/users_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,14 +480,14 @@ func TestUpdateUserPassword(t *testing.T) {
480480
})
481481
require.Error(t,err,"member should not be able to update own password without providing old password")
482482
})
483-
t.Run("AdminCantUpdateOwnPasswordWithoutOldPassword",func(t*testing.T) {
483+
t.Run("AdminCanUpdateOwnPasswordWithoutOldPassword",func(t*testing.T) {
484484
t.Parallel()
485485
client:=coderdtest.New(t,nil)
486486
_=coderdtest.CreateFirstUser(t,client)
487487
err:=client.UpdateUserPassword(context.Background(),"me", codersdk.UpdateUserPasswordRequest{
488488
Password:"newpassword",
489489
})
490-
require.Error(t,err,"admin should not be able to update own password without providing old password")
490+
require.NoError(t,err,"admin should be able to update own password without providing old password")
491491
})
492492
}
493493

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp