Skip to content

fix(api): anchor username validation regex - #1388

Open
ydvvdinesh wants to merge 1 commit into
RocketChat:developfrom
ydvvdinesh:fix/api-username-validation-regex
Open

ydvvdinesh wants to merge 1 commit into
RocketChat:developfrom
ydvvdinesh:fix/api-username-validation-regex

Conversation

@ydvvdinesh

@ydvvdinesh ydvvdinesh commented Oct 16, 2026 •

Copy link
Copy Markdown

fix(api): anchor username validation regex

Acceptance Criteria fulfillment

  • Anchor username validation RegExp (/^[0-9a-zA-Z-_.]+$/) in EmbeddedChatApi.ts to prevent invalid characters from bypassing client-side validation.
  • Add comprehensive unit test suite in packages/api/src/EmbeddedChatApi.test.js validating alphanumeric names, space normalization, symbols rejection, and boundary conditions.

Description

In EmbeddedChatApi.ts, updateUserUsername previously checked username validity using /[0-9a-zA-Z-_.]+/. Because the regular expression lacked start (^) and end ($) anchors, any string containing at least one valid character (such as john@doe.com, user!name, or John Doe (Admin)) was treated as valid, bypassing client-side validation and submitting invalid usernames to the backend.

Anchoring the RegExp with /^[0-9a-zA-Z-_.]+$/ ensures that the entire username contains only permitted characters (0-9, a-z, A-Z, -, _, .).

PR Test Details

  • Run node --test packages/api/src/EmbeddedChatApi.test.js
  • 6/6 tests passing covering valid characters, space replacement to dots, symbol rejection, and empty strings.
  • Prettier code style verified with 0 errors.

- Anchor username validation RegExp with ^ and $ in EmbeddedChatApi.ts to prevent usernames with invalid characters from passing validation.

- Add unit tests covering alphanumeric, space-to-dot replacement, symbols rejection, and empty username cases.

Signed-off-by: Dinesh Yadav <bawwadinesh@gmail.com>
@CLAassistant

CLAassistant commented Oct 16, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

This branch has not been deployed

No deployments
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