RocketChat / RocketChat/EmbeddedChat

Unsafe null destructuring in auth credentials

Open
#1,133 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:

When users aren't authenticated, API methods in EmbeddedChatApi.ts send the literal string "undefined" in auth headers instead of empty values. This happens because of unsafe destructuring: (await this.auth.getCurrentUser()) || {} returns an empty object when the user is null, causing userId and authToken to be undefined.

Steps to reproduce:
  1. Call any API method when user is not logged in
  2. Check the HTTP request headers
  3. See X-Auth-Token: "undefined" and X-User-Id: "undefined" (literal strings)
Expected behavior:

Auth headers should contain empty strings "" when user is not authenticated, not the literal string "undefined".

Actual behavior:

37 API methods send "undefined" as header values due to the unsafe pattern || {}. Headers.set() converts JavaScript undefined to the string "undefined".

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 how the 37 API methods obtain the current user and set authentication headers when no user is present. Reproduce an unauthenticated request and verify that both X-Auth-Token and X-User-Id contain empty strings rather than the literal "undefined".

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, authentication
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.