Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Limit UserIds to a length that fits in a state key #5198

Merged

Conversation

ReidAnderson
Copy link
Contributor

@ReidAnderson ReidAnderson commented May 17, 2019

Pull Request Checklist

  • Pull request is based on the develop branch
  • Pull request includes a changelog file
  • Pull request includes a sign off

Hello, this is my first PR that I've made against anything Matrix related. So definitely let me know if I've gone wrong anywhere, more than happy to make some changes (or if this is the wrong place entirely for the validation).

This should fix #5057, and require that user ids be no more than 256 characters.

And based off the contributing doc, it sounds like this goes here:

Signed-off-by: Reid Anderson

@richvdh richvdh self-requested a review May 17, 2019 10:22
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

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

Thanks very much for this - it looks great!

The only thing is that https://matrix.org/docs/spec/appendices.html#user-identifiers says that the maximum length for a userid is 255 chars. I don't remember the exact reason, but we should probably follow the spec.

The other thing is that it would probably be best to factor out a constant. We already have a MAX_ALIAS_LENGTH in synapse.api.constants - I suggest you add a MAX_USERID_LENGTH next to it.

@@ -123,10 +126,12 @@ def check_username(self, localpart, guest_access_token=None,

self.check_user_id_not_appservice_exclusive(user_id)

if len(user_id) > 256:
if len(user_id) > MAX_ALIAS_LENGTH:
Copy link
Member

Choose a reason for hiding this comment

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

this should be MAX_USERID_LENGTH

Copy link
Contributor

Choose a reason for hiding this comment

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

For reference, this looks fixed on master now synapse/handlers/register.py#L104

@ReidAnderson
Copy link
Contributor Author

@richvdh Thanks for the crazy quick reviews. Should be updated and I've tested it out against riot/local synapse.

@codecov
Copy link

codecov bot commented May 20, 2019

Codecov Report

Merging #5198 into develop will decrease coverage by 0.01%.
The diff coverage is 100%.

@@             Coverage Diff             @@
##           develop    #5198      +/-   ##
===========================================
- Coverage    62.17%   62.15%   -0.02%     
===========================================
  Files          336      336              
  Lines        34716    34719       +3     
  Branches      5690     5691       +1     
===========================================
- Hits         21583    21581       -2     
- Misses       11598    11600       +2     
- Partials      1535     1538       +3

Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

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

lgtm!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants