Skip to content

KEYCLOAK-14904: Fix AccountRestService - #7212

Merged
mposolda merged 1 commit into
keycloak:masterfrom
bosch-io:fix/UserModel_followup
Jul 28, 2020
Merged

mposolda merged 1 commit into
keycloak:masterfrom
bosch-io:fix/UserModel_followup

Conversation

@Martin-Idel-SI

@Martin-Idel-SI Martin-Idel-SI commented Jun 26, 2020 •

Copy link
Copy Markdown
Contributor

This is a followup for #7080

It fixes a bug and a potential exploit I just noticed while working on a followup for changing the database model - sadly one day too late:

When updating the account through the AccountRestService, username, email, firstName and lastName will be deleted from the attributes of the UserModel, i.e. the user will not have a valid username anymore. This was not noted before because all tests implicitly connect to a jpa/UserAdapter which stores the fields in different columns in the database and not as attributes, so in that case, nothing happens (caching might break though).

This is automatically fixed when introducing the LegacyProfile here: #7155
However, since that PR probably needs some time to be reviewed, I'll propose this fix in the meantime.
Sadly, I don't know a relatively cheap way to provide a test showing the problem (I guess I'd have to use an LDAP provider in conjunction with the AccountRestService)

In addition, I noticed that the code allows a user to set the username by setting an attribute named username - and this will set the username without any checks (I added a test to show that this is possible, it will fail with the current master). As a quick fix, I'll just not set the special attributes if they are specified in the representation without saying anything. Since this is an edge case that will also be handled in the UserProfile more gracefully soon, I hope this is enough for now.

I had a look at #7155 to try to figure out whether I missed something else, but couldn't see anything else. I also went through each usage of removeAttribute as this is the problematic function and found only this use and UserResource where this was already done correctly.

@Martin-Idel-SI

Copy link
Copy Markdown
Contributor Author

@mposolda I guess this is something you should have a look at. I'm sorry I was a day too late to just do this within the original PR...

@abstractj
abstractj requested a review from douglaspalmer June 26, 2020 18:08
@abstractj abstractj self-assigned this Jun 26, 2020
@abstractj
abstractj requested a review from mposolda June 26, 2020 18:09
@abstractj abstractj assigned mposolda and unassigned abstractj and mposolda Jun 26, 2020
@abstractj abstractj added area/server area/core Core server — startup, configuration, providers/SPIs, cross-cutting concerns kind/bug Categorizes a PR related to a bug labels Jun 26, 2020
- custom attributes in UserModel are removed during update
- this can break caching (doesn't break if user is written
  to database)
- also ensure that we don't accidentally change username
  and/or firstName/lastName through attributes
@Martin-Idel-SI
Martin-Idel-SI force-pushed the fix/UserModel_followup branch from 8c1b272 to cdc6e8e Compare July 27, 2020 15:58
@Martin-Idel-SI Martin-Idel-SI changed the title KEYCLOAK-14536 Followup: Fix AccountRestService KEYCLOAK-14904: Fix AccountRestService Jul 27, 2020

@mposolda mposolda left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Martin-Idel-SI Thanks for the PR and your analysis of this!

@mposolda
mposolda merged commit 330a3d8 into keycloak:master Jul 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Core server — startup, configuration, providers/SPIs, cross-cutting concerns kind/bug Categorizes a PR related to a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants