Skip to content

fix(security): fallback to crypto.getRandomValues for idempotency keys on insecure origins - #720

Open
dezzy-music wants to merge 1 commit into
MergeFi:mainfrom
dezzy-music:fix/idempotency-key-insecure-origins-706
Open

dezzy-music wants to merge 1 commit into
MergeFi:mainfrom
dezzy-music:fix/idempotency-key-insecure-origins-706

Conversation

@dezzy-music

Copy link
Copy Markdown

Summary

Fixes #706.

In non-secure contexts (such as plain-HTTP staging or preview deployments), crypto.randomUUID is not available (only exposed when isSecureContext is true). The previous fallback immediately degraded to Math.random(), creating predictable, collision-prone idempotency keys.

Changes

  • Fall back to crypto.getRandomValues (which is accessible in non-secure contexts) when crypto.randomUUID is absent.
  • Formats the 16 random bytes as a compliant RFC 4122 v4 UUID with appropriate version (0x40) and variant (0x80) bits.
  • Retains defensive fallback to pseudo-random string for environments without Web Crypto API.
  • Added tests in utils.test.ts simulating insecure environments without crypto.randomUUID.

Verification

  • Ran Jest: 95/95 tests pass in src/lib/utils.test.ts.
  • Ran ESLint: 0 errors.

@vercel

vercel Bot commented Oct 13, 2026

Copy link
Copy Markdown

@dezzy-music is attempting to deploy a commit to the chonilius' projects Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
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.

generateIdempotencyKey falls back to Math.random on non-secure origins

1 participant