RocketChat / RocketChat/EmbeddedChat
Infinite Busy-Wait Loop in handleTypingEvent Freezes Application
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 165
- Forks
- 381
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 1
Description
The handleTypingEvent function in packages/api/src/EmbeddedChatApi.ts contains a Denial of Service (DoS) vulnerability due to a busy-wait loop.
The code uses a synchronous while(typingHandlerLock) {} loop to implement a lock mechanism for managing typing status updates. In JavaScript's single-threaded event loop environment, this pattern is dangerous. If an exception occurs while the lock is held (set to 1) and the lock is not explicitly reset in a finally block or error handler, the lock remains held forever.
Any subsequent call to handleTypingEvent will enter the while loop and never exit, because the loop blocks the main thread, preventing any asynchronous callbacks (like setTimeout) or other code from running to release the lock. This causes the entire application process or browser tab to freeze with 100% CPU usage.
Steps to reproduce:
- Instantiate the
EmbeddedChatApi. - Trigger
handleTypingEventin a way that causes an error after the lock is acquired (typingHandlerLock = 1) but before it is released. - Trigger
handleTypingEventa second time with any arguments.
Expected behavior:
The application should handle errors gracefully and ensure that locks are always released (e.g., using try...finally). Synchronization shouldn't block the main thread; it should use asynchronous patterns like Promises or a task queue if ordering is strictly required.
Actual behavior:
The application freezes indefinitely on the second call. The node process or browser tab becomes unresponsive and must be force-killed.
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 packages/api/src/EmbeddedChatApi.ts and inspect handleTypingEvent, especially how typingHandlerLock is acquired and released. Reproduce the failure by triggering an error after acquisition, then call the handler again and observe the freeze. Done means errors cannot leave the lock permanently held and a second call no longer blocks the event loop indefinitely.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100