RocketChat / RocketChat/EmbeddedChat
Unsafe null destructuring in auth credentials
Nobody has claimed this yet.
- 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:
- Call any API method when user is not logged in
- Check the HTTP request headers
- See
X-Auth-Token: "undefined"andX-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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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