Skip to content

fix: load room history on insecure origins - #41708

Open
Hardik180704 wants to merge 1 commit into
RocketChat:developfrom
Hardik180704:codex/fix-room-history-random-id
Open

fix: load room history on insecure origins#41708
Hardik180704 wants to merge 1 commit into
RocketChat:developfrom
Hardik180704:codex/fix-room-history-random-id

Conversation

@Hardik180704

@Hardik180704 Hardik180704 commented Aug 5, 2026

Copy link
Copy Markdown

Summary

  • replace the secure-context-only crypto.randomUUID() call in RoomHistoryManager with Rocket.Chat's browser-safe Random.id() utility
  • add a regression test proving message history loads when crypto.randomUUID is unavailable
  • add a patch changeset for @rocket.chat/meteor

Root cause

RoomHistoryManager.queue() generated an internal emitter key with crypto.randomUUID(). Browsers expose that API only in secure contexts, so opening Rocket.Chat over plain HTTP on a non-localhost origin rejected the history-loading promise before loadHistory could run.

The queue only requires a collision-resistant internal identifier, not UUID formatting. @rocket.chat/random is already used throughout the client and generates IDs with crypto.getRandomValues() when available, with its established fallback otherwise.

User impact

Message history can load again for self-hosted workspaces accessed through non-secure HTTP origins, while secure-origin behavior remains unchanged.

Validation

  • reproduced the original failure with a regression test: TypeError: crypto.randomUUID is not a function
  • yarn workspace @rocket.chat/meteor .testunit:jest --selectProjects client --runInBand client/lib/RoomHistoryManager.spec.ts
  • yarn workspace @rocket.chat/random test --runInBand
  • yarn eslint apps/meteor/app/ui-utils/client/lib/RoomHistoryManager.ts apps/meteor/client/lib/RoomHistoryManager.spec.ts
  • yarn changeset status

The full Meteor typecheck was also attempted; current develop reports unrelated existing errors in thread drafts, TOTP/OAuth endpoint typings, file-upload typings, and other untouched areas. No error referenced the changed files.

Fixes #41666

Review in cubic

Summary by CodeRabbit

  • Bug Fixes

    • Fixed message history loading on insecure HTTP connections when crypto.randomUUID is unavailable.
    • Improved compatibility for queued history requests across supported environments.
  • Tests

    • Added coverage to verify message history loads correctly without crypto.randomUUID.

@Hardik180704
Hardik180704 requested a review from a team as a code owner August 5, 2026 22:07
@dionisio-bot

dionisio-bot Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot

changeset-bot Bot commented Aug 5, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 935fd12

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@rocket.chat/meteor Patch
@rocket.chat/core-typings Patch
@rocket.chat/rest-typings Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3d7a2de0-268d-4de4-931b-058cccefbfba

📥 Commits

Reviewing files that changed from the base of the PR and between 692be5e and 935fd12.

📒 Files selected for processing (3)
  • .changeset/room-history-insecure-origin.md
  • apps/meteor/app/ui-utils/client/lib/RoomHistoryManager.ts
  • apps/meteor/client/lib/RoomHistoryManager.spec.ts
📜 Recent review details
⏰ Context from checks skipped due to timeout. (1)
  • GitHub Check: cubic · AI code reviewer
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • apps/meteor/client/lib/RoomHistoryManager.spec.ts
  • apps/meteor/app/ui-utils/client/lib/RoomHistoryManager.ts
**/*.spec.ts

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.spec.ts: Use descriptive test names that clearly communicate expected behavior in Playwright tests
Use .spec.ts extension for test files (e.g., login.spec.ts)

Files:

  • apps/meteor/client/lib/RoomHistoryManager.spec.ts
🧠 Learnings (8)
📚 Learning: 2026-03-16T21:50:37.589Z
Learnt from: amitb0ra
Repo: RocketChat/Rocket.Chat PR: 39676
File: .changeset/migrate-users-register-openapi.md:3-3
Timestamp: 2026-03-16T21:50:37.589Z
Learning: For changes related to OpenAPI migrations in Rocket.Chat/OpenAPI, when removing endpoint types and validators from rocket.chat/rest-typings (e.g., UserRegisterParamsPOST, /v1/users.register) document this as a minor changeset (not breaking) per RocketChat/Rocket.Chat-Open-API#150 Rule 7. Note that the endpoint type is re-exposed via a module augmentation .d.ts in the consuming package (e.g., packages/web-ui-registration/src/users-register.d.ts). In reviews, ensure the changeset clearly states: this is a non-breaking change, the major version should not be bumped, and the changeset reflects a minor version bump. Do not treat this as a breaking change during OpenAPI migrations.

Applied to files:

  • .changeset/room-history-insecure-origin.md
📚 Learning: 2026-02-10T16:32:42.586Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 38528
File: apps/meteor/client/startup/roles.ts:14-14
Timestamp: 2026-02-10T16:32:42.586Z
Learning: In Rocket.Chat's Meteor client code, DDP streams use EJSON and Date fields arrive as Date objects; do not manually construct new Date() in stream handlers (for example, in sdk.stream()). Only REST API responses return plain JSON where dates are strings, so implement explicit conversion there if needed. Apply this guidance to all TypeScript files under apps/meteor/client to ensure consistent date handling in DDP streams and REST responses.

Applied to files:

  • apps/meteor/client/lib/RoomHistoryManager.spec.ts
📚 Learning: 2026-05-11T20:30:35.265Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 40480
File: apps/meteor/client/meteor/startup/accounts.ts:59-61
Timestamp: 2026-05-11T20:30:35.265Z
Learning: In Rocket.Chat’s Meteor client code, when calling `dispatchToastMessage` with `{ type: 'error' }`, pass the raw caught error object as `message` without manual normalization. `dispatchToastMessage` is designed to accept `message: unknown` for error toasts, so avoid converting errors to strings (e.g., `String(error)`) or extracting `error.message` before passing them.

Applied to files:

  • apps/meteor/client/lib/RoomHistoryManager.spec.ts
📚 Learning: 2026-02-24T19:22:48.358Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 38493
File: apps/meteor/tests/e2e/omnichannel/omnichannel-send-pdf-transcript.spec.ts:66-67
Timestamp: 2026-02-24T19:22:48.358Z
Learning: In Playwright end-to-end tests (e.g., under apps/meteor/tests/e2e/...), prefer locating elements by translated text (getByText) and ARIA roles (getByRole) over data-qa attributes. If translation values change, update the corresponding test locators accordingly. Never use data-qa locators. This guideline applies to all Playwright e2e test specs in the repository and helps keep tests robust to UI text changes and accessible semantics.

Applied to files:

  • apps/meteor/client/lib/RoomHistoryManager.spec.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.

Applied to files:

  • apps/meteor/client/lib/RoomHistoryManager.spec.ts
  • apps/meteor/app/ui-utils/client/lib/RoomHistoryManager.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.

Applied to files:

  • apps/meteor/client/lib/RoomHistoryManager.spec.ts
  • apps/meteor/app/ui-utils/client/lib/RoomHistoryManager.ts
📚 Learning: 2026-03-06T18:10:15.268Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 39397
File: packages/gazzodown/src/code/CodeBlock.spec.tsx:47-68
Timestamp: 2026-03-06T18:10:15.268Z
Learning: In tests (especially those using testing-library/dom/jsdom) for Rocket.Chat components, the HTML <code> element has an implicit ARIA role of 'code'. Therefore, screen.getByRole('code') or screen.findByRole('code') will locate <code> elements even without a role attribute. Do not flag findByRole('code') as invalid in reviews; prefer using the implicit role instead of adding role="code" unless necessary for accessibility.

Applied to files:

  • apps/meteor/client/lib/RoomHistoryManager.spec.ts
📚 Learning: 2026-05-06T12:21:44.083Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 40256
File: apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx:121-149
Timestamp: 2026-05-06T12:21:44.083Z
Learning: Field wrappers in rocket.chat/fuselage-forms (Field, FieldLabel, FieldRow, FieldError, FieldHint) auto-create htmlFor/id associations, aria-describedby, and role="alert" for errors. Do not manually set htmlFor, id, aria-describedby, or role attributes when using these wrappers. This automatic wiring does not apply to plain rocket.chat/fuselage components, which require explicit ID wiring per the accessibility docs. In code reviews, prefer using fuselage-forms wrappers for form fields and verify there is no unnecessary manual ID/aria wiring in files that use these wrappers. If a component uses plain fuselage components, ensure proper id wiring as per docs.

Applied to files:

  • apps/meteor/client/lib/RoomHistoryManager.spec.ts
  • apps/meteor/app/ui-utils/client/lib/RoomHistoryManager.ts
🔇 Additional comments (3)
apps/meteor/app/ui-utils/client/lib/RoomHistoryManager.ts (1)

3-3: LGTM!

Also applies to: 95-95

apps/meteor/client/lib/RoomHistoryManager.spec.ts (1)

1-57: LGTM!

.changeset/room-history-insecure-origin.md (1)

1-5: LGTM!


Walkthrough

Room history request identifiers now use Random.id() instead of crypto.randomUUID(). Jest coverage verifies history loading when crypto.randomUUID is unavailable. A patch changeset documents the fix.

Changes

Room history request identifier

Layer / File(s) Summary
Request identifier fallback and validation
apps/meteor/app/ui-utils/client/lib/RoomHistoryManager.ts, apps/meteor/client/lib/RoomHistoryManager.spec.ts, .changeset/room-history-insecure-origin.md
RoomHistoryManager uses Random.id() for queued request identifiers. Tests cover history loading without crypto.randomUUID and verify the loadHistory arguments. The changeset records the patch release.
Estimated code review effort: 2 (Simple) ~10 minutes

Possibly related PRs

  • RocketChat/Rocket.Chat#40954: Both PRs modify RoomHistoryManager, but this PR changes request ID generation while that PR addresses pagination and scroll behavior.

Suggested labels: type: bug

Suggested reviewers: cardoso, tassoevan

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the primary fix: loading room history on insecure origins.
Linked Issues check ✅ Passed The change replaces secure-context-only crypto.randomUUID() with Random.id() and adds regression coverage for issue #41666.
Out of Scope Changes check ✅ Passed The dependency change, regression test, and patch changeset directly support the linked issue and PR objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 3 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/meteor/client/lib/RoomHistoryManager.spec.ts">

<violation number="1" location="apps/meteor/client/lib/RoomHistoryManager.spec.ts:51">
P3: The regression test only covers the first (non-queued) getMore call, where the Random.id() emitter key is generated but discarded; the queued path — a second getMore while one is in flight, where requestId is pushed into requestsList and routed via this.once(requestId, done) — is where the internal identifier actually matters and is left untested. Consider adding a second concurrent getMore to assert the queued request completes (Random.id() key routes the emitter event), and/or assert that messages are persisted via storeMany and isLoading returns to false.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic


try {
await expect(RoomHistoryManager.getMore('room-id')).resolves.toBeUndefined();
expect(mockedCallWithErrorHandling).toHaveBeenCalledWith('loadHistory', 'room-id', undefined, 50, undefined, false);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: The regression test only covers the first (non-queued) getMore call, where the Random.id() emitter key is generated but discarded; the queued path — a second getMore while one is in flight, where requestId is pushed into requestsList and routed via this.once(requestId, done) — is where the internal identifier actually matters and is left untested. Consider adding a second concurrent getMore to assert the queued request completes (Random.id() key routes the emitter event), and/or assert that messages are persisted via storeMany and isLoading returns to false.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/meteor/client/lib/RoomHistoryManager.spec.ts, line 51:

<comment>The regression test only covers the first (non-queued) getMore call, where the Random.id() emitter key is generated but discarded; the queued path — a second getMore while one is in flight, where requestId is pushed into requestsList and routed via this.once(requestId, done) — is where the internal identifier actually matters and is left untested. Consider adding a second concurrent getMore to assert the queued request completes (Random.id() key routes the emitter event), and/or assert that messages are persisted via storeMany and isLoading returns to false.</comment>

<file context>
@@ -0,0 +1,57 @@
+
+		try {
+			await expect(RoomHistoryManager.getMore('room-id')).resolves.toBeUndefined();
+			expect(mockedCallWithErrorHandling).toHaveBeenCalledWith('loadHistory', 'room-id', undefined, 50, undefined, false);
+		} finally {
+			Object.defineProperty(globalThis.crypto, 'randomUUID', { configurable: true, value: originalRandomUUID });
</file context>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

crypto.randomUUID() in RoomHistoryManager breaks message history on non-secure origins (plain HTTP, non-localhost) since 8.1

1 participant