-
Notifications
You must be signed in to change notification settings - Fork 184
fix(core): fall back to node:crypto so randomUUID cannot throw on Node #599
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kalenkevich
merged 2 commits into
google:main
from
adilburaksen:fix/randomuuid-node-crypto-fallback
Aug 4, 2026
+57
−7
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2026 Google LLC | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| /** | ||
| * Browser stand-in for the `node:crypto` builtin, wired up by the alias in | ||
| * `build.js` so that the Node fallback in `env_aware_utils.ts` does not pull a | ||
| * Node builtin into the web bundle. | ||
| * | ||
| * `randomUUID` is reached here only after both `globalThis.crypto` branches in | ||
| * `env_aware_utils.ts` have been ruled out. In a browser that means the Web | ||
| * Crypto API is genuinely absent, so there is no secure source left to fall | ||
| * back to and the only correct move is to fail rather than degrade. | ||
| */ | ||
| export function randomUUID(): string { | ||
| throw new Error( | ||
| 'randomUUID: no cryptographically secure source of randomness is ' + | ||
| 'available. Neither crypto.randomUUID() nor crypto.getRandomValues() is ' + | ||
| 'present in this environment.', | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit. The doc comment claims more coverage than the alias actually gives: it says "the web build", but only the bundled web build is aliased, and that is not the one the package publishes.
Your PR description is careful about exactly this distinction — the code comment isn't, and the comment is what the next reader gets. I confirmed the gap rather than assuming it: from
dist/web/index_web.js,node:async_hooksis reachable throughutils/client_labels.js, andnode:path/node:fs/promisesthroughskills/loader.jsandutils/file_utils.js. So the sentence is wrong only about scope, not about the mechanism.Same wording question applies to
crypto_shim.ts's own header, though "does not pull a Node builtin into the web bundle" there is already accurate as written.