RocketChat / RocketChat/EmbeddedChat

Fix: Username validation regex missing anchors

Open
#1,201 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
JavaScript
Stars
165
Forks
381
Avg merge
1d 2h
Merged PRs (30d)
1

Description

Description:

The current username validation regex /[0-9a-zA-Z-_.]+/ in EmbeddedChatApi.ts lacks start (^) and end ($) anchors. This causes the validation to pass for any string that contains at least one valid character, even if the rest of the string is invalid.

Steps to reproduce:
  1. Call updateUserUsername(userid, "@#$a@#$").
  2. Observe that usernameRegExp.test(newUserName) returns true because it matches the character "a".
  3. The method proceeds to attempt an update with an invalid username format.
Expected behavior:

The validation should fail if the string contains any characters outside the allowed set [0-9a-zA-Z-_.].

Actual behavior:

The validation passes if at least one character in the string matches the regex.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in EmbeddedChatApi.ts and inspect the usernameRegExp check used by updateUserUsername. Reproduce the issue with "@#$a@#$" and verify that usernames containing characters outside the allowed set fail validation while valid usernames continue to pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.