Skip to content

Commit

Permalink
#408 Fix privilege escalation
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Dec 22, 2017
1 parent 5a86df3 commit 53bb970
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions thehive-backend/app/controllers/UserCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,22 @@ class UserCtrl @Inject() (
@Timed
def update(id: String): Action[Fields] = authenticated(Roles.read).async(fieldsBodyParser) { implicit request
if (id == request.authContext.userId || request.authContext.roles.contains(Roles.admin)) {
if (request.body.contains("password") || request.body.contains("key"))
logger.warn("Change password or key using update operation is deprecated. Please use dedicated API (setPassword, changePassword or renewKey)")
userSrv.update(id, request.body.unset("password").unset("key")).map { user
renderer.toOutput(OK, user)
if (request.body.contains("password")) {
Future.failed(AuthorizationError("You must use dedicated API (setPassword, changePassword) to update password"))
}
else if (request.body.contains("key")) {
Future.failed(AuthorizationError("You must use dedicated API (renewKey, removeKey) to update key"))
}
else if (request.body.contains("role") && !request.authContext.roles.contains(Roles.admin)) {
Future.failed(AuthorizationError("You are not permitted to change user role"))
}
else if (request.body.contains("status") && !request.authContext.roles.contains(Roles.admin)) {
Future.failed(AuthorizationError("You are not permitted to change user status"))
}
else {
userSrv.update(id, request.body.unset("password").unset("key")).map { user
renderer.toOutput(OK, user)
}
}
}
else {
Expand Down

0 comments on commit 53bb970

Please sign in to comment.