1 parent
b59170681e
commit
d5964f64a9
4 files changed
+64
No files matched your search
@@ -0,0 +1,5 @@
|
||||
Security: Block password and account changes via PATCH /graph/v1.0/me
|
||||
|
||||
`PATCH /graph/v1.0/me` no longer accepts `passwordProfile`, `accountEnabled`, or `onPremisesSamAccountName`. Use `POST /graph/v1.0/me/changePassword` to change your password.
|
||||
|
||||
https://github.com/owncloud/ocis/pull/12493
|
||||
@@ -52,6 +52,7 @@ type Service interface { //nolint:interfacebloat
|
||||
GetUser(w http.ResponseWriter, r *http.Request)
|
||||
PostUser(w http.ResponseWriter, r *http.Request)
|
||||
DeleteUser(w http.ResponseWriter, r *http.Request)
|
||||
PatchMe(w http.ResponseWriter, r *http.Request)
|
||||
PatchUser(w http.ResponseWriter, r *http.Request)
|
||||
ChangeOwnPassword(w http.ResponseWriter, r *http.Request)
|
||||
|
||||
|
||||
@@ -863,6 +863,21 @@ func (g Graph) PatchMe(w http.ResponseWriter, r *http.Request) {
|
||||
errorcode.InvalidRequest.Render(w, r, http.StatusBadRequest, "user is not allowed to change own mail")
|
||||
return
|
||||
}
|
||||
if changes.HasPasswordProfile() {
|
||||
logger.Info().Interface("user", changes).Msg("could not update user: user is not allowed to change own password via PATCH /me, use POST /me/changePassword")
|
||||
errorcode.InvalidRequest.Render(w, r, http.StatusBadRequest, "user is not allowed to change own password via PATCH /me, use POST /me/changePassword")
|
||||
return
|
||||
}
|
||||
if changes.HasAccountEnabled() {
|
||||
logger.Info().Interface("user", changes).Msg("could not update user: user is not allowed to change own accountEnabled")
|
||||
errorcode.InvalidRequest.Render(w, r, http.StatusBadRequest, "user is not allowed to change own accountEnabled")
|
||||
return
|
||||
}
|
||||
if changes.HasOnPremisesSamAccountName() {
|
||||
logger.Info().Interface("user", changes).Msg("could not update user: user is not allowed to change own onPremisesSamAccountName")
|
||||
errorcode.InvalidRequest.Render(w, r, http.StatusBadRequest, "user is not allowed to change own onPremisesSamAccountName")
|
||||
return
|
||||
}
|
||||
g.patchUser(w, r, userID, changes)
|
||||
}
|
||||
|
||||
|
||||
@@ -1133,6 +1133,49 @@ var _ = Describe("Users", func() {
|
||||
})
|
||||
})
|
||||
|
||||
Describe("PatchMe", func() {
|
||||
It("rejects passwordProfile changes (CWE-620)", func() {
|
||||
update := libregraph.NewUserUpdate()
|
||||
pp := libregraph.NewPasswordProfile()
|
||||
pp.SetPassword("newpassword")
|
||||
update.SetPasswordProfile(*pp)
|
||||
body, err := json.Marshal(update)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
r := httptest.NewRequest(http.MethodPatch, "/graph/v1.0/me", bytes.NewBuffer(body))
|
||||
r = r.WithContext(revactx.ContextSetUser(ctx, currentUser))
|
||||
svc.PatchMe(rr, r)
|
||||
|
||||
Expect(rr.Code).To(Equal(http.StatusBadRequest))
|
||||
})
|
||||
|
||||
It("rejects accountEnabled changes", func() {
|
||||
update := libregraph.NewUserUpdate()
|
||||
update.SetAccountEnabled(false)
|
||||
body, err := json.Marshal(update)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
r := httptest.NewRequest(http.MethodPatch, "/graph/v1.0/me", bytes.NewBuffer(body))
|
||||
r = r.WithContext(revactx.ContextSetUser(ctx, currentUser))
|
||||
svc.PatchMe(rr, r)
|
||||
|
||||
Expect(rr.Code).To(Equal(http.StatusBadRequest))
|
||||
})
|
||||
|
||||
It("rejects onPremisesSamAccountName changes", func() {
|
||||
update := libregraph.NewUserUpdate()
|
||||
update.SetOnPremisesSamAccountName("newusername")
|
||||
body, err := json.Marshal(update)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
r := httptest.NewRequest(http.MethodPatch, "/graph/v1.0/me", bytes.NewBuffer(body))
|
||||
r = r.WithContext(revactx.ContextSetUser(ctx, currentUser))
|
||||
svc.PatchMe(rr, r)
|
||||
|
||||
Expect(rr.Code).To(Equal(http.StatusBadRequest))
|
||||
})
|
||||
})
|
||||
|
||||
Describe("PatchUser", func() {
|
||||
var (
|
||||
user *libregraph.User
|
||||
|
||||
Reference in new issue
Block a user