Skip to content

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

Merged
marceloceccon merged 1 commit into
mainfrom
alert-autofix-4
Jun 18, 2026
Merged

Potential fix for code scanning alert no. 4: Insecure randomness#4
marceloceccon merged 1 commit into
mainfrom
alert-autofix-4

Conversation

@marceloceccon

Copy link
Copy Markdown
Member

Potential fix for https://github.com/entropyvortex/clashcode/security/code-scanning/4

Use Node.js cryptographic randomness for key-like token generation in examples/keychain-setup.ts.

Best fix (without changing functionality):

  • Import Node’s built-in crypto module (randomBytes).
  • Replace the Math.random().toString(36).slice(2, 10) suffix with an 8-character suffix derived from randomBytes, e.g. randomBytes(6).toString('base64url').slice(0, 8).
    This preserves the same shape/purpose (short random demo suffix) while making randomness cryptographically secure.

Change only:

  • examples/keychain-setup.ts:
    • Add import { randomBytes } from 'node:crypto'
    • Replace fake key generation line.

No changes are required in src/config/keychain.ts.

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

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@marceloceccon marceloceccon marked this pull request as ready for review June 18, 2026 19:29
@marceloceccon marceloceccon merged commit 600d382 into main Jun 18, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant