Skip to content

Fixed plain HTTP UUID creation#135

Merged
matt1398 merged 4 commits intomatt1398:mainfrom
RubbaBoy:fix/uuid-non-secure-context-fallback
Apr 5, 2026
Merged

Fixed plain HTTP UUID creation#135
matt1398 merged 4 commits intomatt1398:mainfrom
RubbaBoy:fix/uuid-non-secure-context-fallback

Conversation

@RubbaBoy
Copy link
Copy Markdown
Contributor

@RubbaBoy RubbaBoy commented Mar 25, 2026

If this is connected to in a non-localhost/electron context (such as forwarding the port this is hosted on from another machine), the application is unusable due to errors when trying to use crypto.randomUUID(), as this is only available in a secure context.

This PR creates a secure fallback for this method if unavailable.

Summary by CodeRabbit

  • Refactor

    • Switched app-wide ID generation to a centralized UUID generator for consistent, environment‑compatible IDs across settings, panes, tabs, and navigation requests.
  • Tests

    • Added tests verifying UUID v4 conformance and deterministic fallback behavior when native UUID support is unavailable.

@coderabbitai coderabbitai bot added the bug Something isn't working label Mar 25, 2026
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a robust solution for generating UUIDs within the application, specifically addressing issues encountered when running in non-secure contexts outside of localhost or Electron. By centralizing UUID generation into a new utility function with a secure fallback, the application's stability and usability are significantly improved, preventing errors that previously rendered it unusable in certain deployment scenarios.

Highlights

  • Robust UUID Generation: Implemented a new generateUUID utility function that provides a secure fallback mechanism for UUID generation, ensuring functionality even in non-secure contexts.
  • Widespread Adoption: Replaced all direct instances of crypto.randomUUID() with the new generateUUID() utility across various components, store slices, and type definitions.
  • Enhanced Application Stability: Addressed an issue where the application became unusable in non-localhost/electron contexts due to crypto.randomUUID() being unavailable, thereby improving overall stability.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request centralizes UUID generation by introducing a new generateUUID utility function in stringUtils.ts. This function uses crypto.randomUUID() when available and falls back to crypto.getRandomValues() for broader compatibility. The new utility is then adopted across various components and store slices for generating IDs. A review comment suggests adding an explicit check for the crypto object's existence within the generateUUID function to prevent potential ReferenceErrors and improve its robustness.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 25, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5fd978d7-5830-4197-b5dc-39c7f975355f

📥 Commits

Reviewing files that changed from the base of the PR and between c013b6e and df7940a.

📒 Files selected for processing (7)
  • src/renderer/components/settings/NotificationTriggerSettings/utils/trigger.ts
  • src/renderer/components/settings/sections/WorkspaceSection.tsx
  • src/renderer/store/slices/paneSlice.ts
  • src/renderer/store/slices/tabSlice.ts
  • src/renderer/types/tabs.ts
  • src/renderer/utils/stringUtils.ts
  • test/renderer/utils/stringUtils.test.ts
✅ Files skipped from review due to trivial changes (4)
  • src/renderer/components/settings/sections/WorkspaceSection.tsx
  • src/renderer/store/slices/paneSlice.ts
  • src/renderer/types/tabs.ts
  • src/renderer/components/settings/NotificationTriggerSettings/utils/trigger.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/renderer/utils/stringUtils.ts
  • test/renderer/utils/stringUtils.test.ts

📝 Walkthrough

Walkthrough

Replaces direct crypto.randomUUID() calls with a shared generateUUID() helper across renderer code, adds generateUUID() to src/renderer/utils/stringUtils.ts (with a fallback), and adds Vitest tests for the new generator.

Changes

Cohort / File(s) Summary
UUID Generator Utility
src/renderer/utils/stringUtils.ts
Added exported generateUUID(): string that uses crypto.randomUUID() when available and falls back to constructing a UUID v4 via crypto.getRandomValues() with correct version/variant masking and formatting.
Store Updates
src/renderer/store/slices/paneSlice.ts, src/renderer/store/slices/tabSlice.ts
Replaced direct crypto.randomUUID() usage with generateUUID() for pane and tab ID creation in split/move/open flows.
Components & Types
Notification / Workspace / Types
src/renderer/components/settings/NotificationTriggerSettings/utils/trigger.ts, src/renderer/components/settings/sections/WorkspaceSection.tsx, src/renderer/types/tabs.ts
Switched UUID generation to import and use generateUUID() for notification trigger IDs, new SSH profile IDs, and TabNavigationRequest IDs.
Tests
test/renderer/utils/stringUtils.test.ts
Added Vitest tests covering both crypto.randomUUID path (spied) and fallback path (mocked crypto.getRandomValues), asserting UUID v4 format, version/variant bits, and deterministic fallback output.

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 and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/renderer/utils/stringUtils.ts (1)

15-21: Add tests for the UUID fallback path in src/renderer/utils/stringUtils.ts.

The existing test suite mocks crypto.randomUUID but doesn't cover the getRandomValues fallback branch. Since this fallback is essential for non-secure contexts, add a test that:

  1. Stubs crypto.randomUUID as undefined
  2. Verifies the fallback produces valid UUID v4 format with correct version and variant bits
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/renderer/utils/stringUtils.ts` around lines 15 - 21, Write a unit test
that forces the fallback branch by stubbing crypto.randomUUID to undefined and
stubbing crypto.getRandomValues to return a deterministic 16-byte Uint8Array;
import the UUID generator from src/renderer/utils/stringUtils.ts and call it,
then assert the returned string matches the UUID v4 pattern and specifically
verify the version nibble (the 13th hex character, i.e., the 7th byte after
masking) is '4' and the variant bits (the 17th hex character, i.e., the 9th
byte) are one of 8, 9, a, or b to ensure correct version and variant handling of
the getRandomValues fallback.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/renderer/utils/stringUtils.ts`:
- Around line 15-21: Write a unit test that forces the fallback branch by
stubbing crypto.randomUUID to undefined and stubbing crypto.getRandomValues to
return a deterministic 16-byte Uint8Array; import the UUID generator from
src/renderer/utils/stringUtils.ts and call it, then assert the returned string
matches the UUID v4 pattern and specifically verify the version nibble (the 13th
hex character, i.e., the 7th byte after masking) is '4' and the variant bits
(the 17th hex character, i.e., the 9th byte) are one of 8, 9, a, or b to ensure
correct version and variant handling of the getRandomValues fallback.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 91f56f4d-0c67-496b-9498-eec89e3cb3e1

📥 Commits

Reviewing files that changed from the base of the PR and between f23e881 and 1d0f6f2.

📒 Files selected for processing (6)
  • src/renderer/components/settings/NotificationTriggerSettings/utils/trigger.ts
  • src/renderer/components/settings/sections/WorkspaceSection.tsx
  • src/renderer/store/slices/paneSlice.ts
  • src/renderer/store/slices/tabSlice.ts
  • src/renderer/types/tabs.ts
  • src/renderer/utils/stringUtils.ts

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
test/renderer/utils/stringUtils.test.ts (1)

8-11: Align this test’s assertion with its title.

This assertion validates UUID shape, but it does not verify delegation behavior. Consider either renaming the test to reflect format validation or asserting branch-specific behavior.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/renderer/utils/stringUtils.test.ts` around lines 8 - 11, The test titled
"delegates to crypto.randomUUID when available" only checks format; change it to
assert delegation by mocking/spying on crypto.randomUUID and verifying it was
called and its return used: in the test for generateUUID(), stub
globalThis.crypto.randomUUID (or use jest.spyOn(globalThis.crypto,
'randomUUID')) to return a known value, call generateUUID(), expect the spy
toHaveBeenCalled() and expect the result toEqual the stubbed value (optionally
also assert it matches UUID_V4_PATTERN), or alternatively rename the test to
"returns a UUID v4 string" if you prefer to only validate format; reference
generateUUID and UUID_V4_PATTERN when making this change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@test/renderer/utils/stringUtils.test.ts`:
- Around line 8-11: The test titled "delegates to crypto.randomUUID when
available" only checks format; change it to assert delegation by mocking/spying
on crypto.randomUUID and verifying it was called and its return used: in the
test for generateUUID(), stub globalThis.crypto.randomUUID (or use
jest.spyOn(globalThis.crypto, 'randomUUID')) to return a known value, call
generateUUID(), expect the spy toHaveBeenCalled() and expect the result toEqual
the stubbed value (optionally also assert it matches UUID_V4_PATTERN), or
alternatively rename the test to "returns a UUID v4 string" if you prefer to
only validate format; reference generateUUID and UUID_V4_PATTERN when making
this change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ec4e34df-fca3-40d9-87f5-fec6355e9cb2

📥 Commits

Reviewing files that changed from the base of the PR and between 1d0f6f2 and a94ed3d.

📒 Files selected for processing (2)
  • src/renderer/utils/stringUtils.ts
  • test/renderer/utils/stringUtils.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/renderer/utils/stringUtils.ts

@willwebster5
Copy link
Copy Markdown

Pulled locally and confirmed this fixed my same issue.

@matt1398 matt1398 force-pushed the fix/uuid-non-secure-context-fallback branch from c013b6e to df7940a Compare April 5, 2026 06:37
@matt1398 matt1398 merged commit d205fc8 into matt1398:main Apr 5, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants