Skip to content

Comments

Potential fix for code scanning alert no. 84: Insecure randomness#67

Merged
Dargon789 merged 1 commit intomasterfrom
alert-autofix-84
Oct 7, 2025
Merged

Potential fix for code scanning alert no. 84: Insecure randomness#67
Dargon789 merged 1 commit intomasterfrom
alert-autofix-84

Conversation

@Dargon789
Copy link
Owner

@Dargon789 Dargon789 commented Oct 7, 2025

Potential fix for https://github.com/Dargon789/sequence.js/security/code-scanning/84

To fix this problem, the generation of identifiers within generateId() (specifically the random component) must use a cryptographically secure random number generator. For browser environments, the correct API is window.crypto.getRandomValues, which returns a cryptographically secure random number. Replace the use of Math.random() with a string derived from secure random bytes, e.g., converting a Uint8Array (or Uint32Array) to a base36 string.

Edit the generateId() implementation in packages/wallet/dapp-client/src/DappTransport.ts so that instead of using Math.random(), it creates a random value by calling window.crypto.getRandomValues, then builds the ID string using this random value. No new imports are needed since the browser window.crypto is already available.


Suggested fixes powered by Copilot Autofix. Review carefully before merging.

Summary by Sourcery

Bug Fixes:

  • Replace insecure Math.random-based ID generation with crypto.getRandomValues-based randomness to address code scanning alert

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Signed-off-by: AU_gdev_19 <64915515+Dargon789@users.noreply.github.com>
@codesandbox
Copy link

codesandbox bot commented Oct 7, 2025

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@vercel
Copy link

vercel bot commented Oct 7, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
sequence-js-docs Ready Ready Preview Comment Oct 7, 2025 1:58pm
sequence-js-web Ready Ready Preview Comment Oct 7, 2025 1:58pm
sequence.js Building Building Preview Oct 7, 2025 1:58pm

@sourcery-ai
Copy link

sourcery-ai bot commented Oct 7, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

The PR refactors DappTransport.generateId to replace Math.random with window.crypto.getRandomValues for cryptographically secure randomness, converting the resulting Uint32Array value to a base36 string in the ID format.

Class diagram for updated DappTransport.generateId method

classDiagram
class DappTransport {
  +generateId(): string
}
DappTransport : -generateId() now uses window.crypto.getRandomValues
DappTransport : -generateId() returns `${Date.now().toString(36)}-${randStr}`
Loading

File-Level Changes

Change Details Files
Switch generateId to use secure random values instead of Math.random
  • Replace Math.random() call with window.crypto.getRandomValues
  • Create a Uint32Array and fill it with secure random bytes
  • Convert the random Uint32Array value to a base36 string
  • Update the returned ID string to include the secure random component
packages/wallet/dapp-client/src/DappTransport.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@Dargon789 Dargon789 merged commit 1869b3b into master Oct 7, 2025
13 of 15 checks passed
@Dargon789 Dargon789 deleted the alert-autofix-84 branch October 7, 2025 14:04
@Dargon789 Dargon789 restored the alert-autofix-84 branch October 7, 2025 14:17
@github-project-automation github-project-automation bot moved this from Todo to Done in web3-Defi-Gamefi Feb 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant