Skip to content
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

Merged
merged 4 commits into from
Jun 28, 2019
Merged

Escape user IDs correctly #112

merged 4 commits into from
Jun 28, 2019

Conversation

Half-Shot
Copy link
Contributor

This fixes #109. In addition, this PR adds a global variable to disable userid escaping for bridges that don't support it yet.

@Half-Shot Half-Shot requested a review from turt2live June 27, 2019 23:28
@Half-Shot Half-Shot changed the base branch from master to develop June 27, 2019 23:28
@turt2live turt2live changed the title Hs/escaping fixes Escape user IDs correctly Jun 27, 2019
Copy link
Member

@turt2live turt2live left a comment

Choose a reason for hiding this comment

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

otherwise lgtm

@@ -58,7 +59,7 @@ MatrixUser.prototype.set = function(key, val) {
this._data[key] = val;
};

/**
/**u
Copy link
Member

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, ""));
Copy link
Member

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.

const code = c.charCodeAt(0);
const hex = code.toString(16).toLowerCase();
if (code < 65 || code > 90) {
// Alpha codes do not need escaping.
Copy link
Member

Choose a reason for hiding this comment

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

... but should be lowercased.

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

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.

@@ -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)
Copy link
Member

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

@Half-Shot Half-Shot merged commit 346cea3 into develop Jun 28, 2019
@Half-Shot Half-Shot deleted the hs/escaping-fixes branch September 29, 2020 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants