Skip to content

Conversation

@ajbeaven
Copy link

In messenger chat, when a user's id has a character that would cause an html attribute to be invalid, anyone chatting with that user will not be able to see any messages. This occurs because the userid is used to create the id for an element that needs to be retrieved to add messages inside.

This is a pretty hacky fix, so do with it what you will. I'm replacing some non-alphanumeric characters that are actually valid in ids but simplicity's sake, I'm just replacing all of them. Here's the HTML 4 specification for what id attributes are allowed if you wanted to do it a bit better (HTML5 is slightly more permissive):

ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").

So yeah, simplicity wins.

Using this, there is potential that usernames could be duplicated (probably unlikely) or this code exploited. I would suggest not using the userid to create the id for the panel in the first place, and rather assign a auto generated id for the user when they connect to the chat, generating the id attribute based off that. That is, if assigning an id to this element is even necessary at all.

In messenger chat, when a user's id has a character that would cause an
html attribute to be invalid, anyone chatting with that user will not be
able to see any messages. This occurs because the userid is used to
create the id for an element that needs to be retrieved to add messages
inside.
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.

1 participant