-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Escape user IDs correctly #112
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
otherwise lgtm
lib/models/users/matrix.js
Outdated
@@ -58,7 +59,7 @@ MatrixUser.prototype.set = function(key, val) { | |||
this._data[key] = val; | |||
}; | |||
|
|||
/** | |||
/**u |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
u
const badChars = new Set(this.localpart.replace(/([A-z0-9]|-|\.|=|_)+/g, "")); | ||
// NOTE: Currently Matrix accepts / in the userId, although going forward it will be removed. | ||
// NOTE: We also allow uppercase for the time being. | ||
const badChars = new Set(this.localpart.replace(/([A-Z]|[a-z]|[0-9]|-|\.|=|_)+/g, "")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should remove characters which aren't allowed, such as uppercase. I'm pretty sure Synapse has started failing to register uppercase usernames by now.
lib/models/users/matrix.js
Outdated
const code = c.charCodeAt(0); | ||
const hex = code.toString(16).toLowerCase(); | ||
if (code < 65 || code > 90) { | ||
// Alpha codes do not need escaping. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... but should be lowercased.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are we lowercasing them rather than escaping them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see why not. User IDs are semi-opaque anyways, so Bob and bob are just going to have to get along.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see that causing lots of unexpected conflicts :c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tbh I see anything we do here as creating unexpected conflicts. See also: IRC bridge creating duplicate users, resulting in the bridge doing it's own escaping.
Maybe we just keep uppercase as allowed (sorry) and never visit this code again.
spec/unit/matrix-user.spec.js
Outdated
@@ -6,8 +6,8 @@ describe("MatrixUser", function() { | |||
[ | |||
new MatrixUser("@test:localhost", null, false), | |||
new MatrixUser("@42:localhost", null, false), | |||
new MatrixUser("@Test42:localhost", null, false), | |||
new MatrixUser("@A=Good-set.of_chars:localhost", null, false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which means keeping this test to result in a lowercase version
12f0e0b
to
cab087b
Compare
This fixes #109. In addition, this PR adds a global variable to disable userid escaping for bridges that don't support it yet.