Repository navigation
KEYCLOAK-14904: Fix AccountRestService - #7212
Merged
Merged
Conversation
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... |
- 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
force-pushed
the
fix/UserModel_followup
branch
from
July 27, 2020 15:58
8c1b272 to
cdc6e8e
Compare
mposolda
approved these changes
Jul 28, 2020
mposolda
left a comment
Contributor
There was a problem hiding this comment.
@Martin-Idel-SI Thanks for the PR and your analysis of this!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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,firstNameandlastNamewill be deleted from the attributes of theUserModel, i.e. the user will not have a valid username anymore. This was not noted before because all tests implicitly connect to ajpa/UserAdapterwhich 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
usernameby setting an attribute namedusername- 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
removeAttributeas this is the problematic function and found only this use andUserResourcewhere this was already done correctly.