Fix crypto.randomUUID() unavailable in HTTP contexts#19573
Fix crypto.randomUUID() unavailable in HTTP contexts#19573tobyxdd wants to merge 1 commit intomlflow:masterfrom
Conversation
|
@tobyxdd Thank you for the contribution! Could you fix the following issue(s)? ⚠ DCO checkThe DCO check failed. Please sign off your commit(s) by following the instructions here. See https://github.com/mlflow/mlflow/blob/master/CONTRIBUTING.md#sign-your-work for more details. |
Signed-off-by: Toby Huang <toby.huang@astrabot.com>
77e009b to
f8a5e67
Compare
There was a problem hiding this comment.
Pull request overview
This PR fixes a critical issue where crypto.randomUUID() was causing the MLflow UI to break when deployed over HTTP. The API requires a secure context (HTTPS, localhost, or file://) and throws an error in plain HTTP environments. The solution introduces a generateUUID() utility that attempts to use crypto.randomUUID() first and falls back to crypto.getRandomValues() which works in all contexts.
- Creates a new
generateUUID()utility with secure and non-secure context support - Replaces all occurrences of
crypto.randomUUID()with the new utility function
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| mlflow/server/js/src/common/utils/generateUUID.ts | New utility function that generates UUIDs with fallback for HTTP contexts |
| mlflow/server/js/src/telemetry/worker/TelemetryLogger.worker.ts | Updates session ID generation to use the new utility |
| mlflow/server/js/src/telemetry/TelemetryClient.ts | Updates installation ID generation to use the new utility |
| mlflow/server/js/src/experiment-tracking/pages/experiment-page-tabs/side-nav/ExperimentPageSideNavSection.tsx | Updates view ID generation to use the new utility |
| mlflow/server/js/src/common/components/MlflowSidebar.tsx | Updates view ID generation to use the new utility |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // Fallback using crypto.getRandomValues() which works in insecure contexts | ||
| const bytes = new Uint8Array(16); | ||
| crypto.getRandomValues(bytes); |
There was a problem hiding this comment.
The fallback implementation doesn't handle the case where crypto.getRandomValues() might also be unavailable (e.g., in very old browsers or non-browser environments). Consider adding a check for crypto.getRandomValues() availability and wrapping it in a try-catch block to provide a more graceful error message if UUID generation fails completely.
There was a problem hiding this comment.
I am not expert of front-end, do we need to consider the case crypto.getRandomValues() might also be unavailable (e.g., in very old browsers or non-browser environments) ? @tobyxdd
| export function generateUUID(): string { | ||
| if (typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function') { | ||
| try { | ||
| return crypto.randomUUID(); | ||
| } catch { | ||
| // Falls through to fallback | ||
| } | ||
| } | ||
|
|
||
| // Fallback using crypto.getRandomValues() which works in insecure contexts | ||
| const bytes = new Uint8Array(16); | ||
| crypto.getRandomValues(bytes); | ||
|
|
||
| // Set version (4) and variant (RFC4122) bits | ||
| bytes[6] = (bytes[6] & 0x0f) | 0x40; | ||
| bytes[8] = (bytes[8] & 0x3f) | 0x80; | ||
|
|
||
| const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, '0')).join(''); | ||
| return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`; | ||
| } |
There was a problem hiding this comment.
This new utility function lacks test coverage. Since other utilities in the same directory (e.g., ActionUtils, StringUtils, FileUtils) have accompanying test files, consider adding tests for generateUUID to verify both the secure context path and the fallback mechanism work correctly.
There was a problem hiding this comment.
shall we use the existing lib https://www.npmjs.com/package/uuid
or embed the code from the uuid lib ?
|
Documentation preview for f8a5e67 is available at: More info
|
|
the issue has caused many complaints so we decide to release a patch version soon, to unblock the release, I filed a new PR with some updates #19644 and merged it. still appreciating your contribution! |
🛠 DevTools 🛠
Install mlflow from this PR
For Databricks, use the following command:
Related Issues/PRs
#19480
What changes are proposed in this pull request?
crypto.randomUUID()requires a secure context (HTTPS, localhost, or file://). When MLflow is deployed over plain HTTP, this API throws an error, breaking the UI.This PR created
generateUUID()utility that:crypto.randomUUID()first (for secure contexts)crypto.getRandomValues()which works in all contextsHow is this PR tested?
Does this PR require documentation update?
Release Notes
Is this a user-facing change?
Fix broken frontend when server is using HTTP protocol
What component(s), interfaces, languages, and integrations does this PR affect?
Components
area/tracking: Tracking Service, tracking client APIs, autologgingarea/models: MLmodel format, model serialization/deserialization, flavorsarea/model-registry: Model Registry service, APIs, and the fluent client calls for Model Registryarea/scoring: MLflow Model server, model deployment tools, Spark UDFsarea/evaluation: MLflow model evaluation features, evaluation metrics, and evaluation workflowsarea/gateway: MLflow AI Gateway client APIs, server, and third-party integrationsarea/prompts: MLflow prompt engineering features, prompt templates, and prompt managementarea/tracing: MLflow Tracing features, tracing APIs, and LLM tracing functionalityarea/projects: MLproject format, project running backendsarea/uiux: Front-end, user experience, plotting, JavaScript, JavaScript dev serverarea/build: Build and test infrastructure for MLflowarea/docs: MLflow documentation pagesHow should the PR be classified in the release notes? Choose one:
rn/none- No description will be included. The PR will be mentioned only by the PR number in the "Small Bugfixes and Documentation Updates" sectionrn/breaking-change- The PR will be mentioned in the "Breaking Changes" sectionrn/feature- A new user-facing feature worth mentioning in the release notesrn/bug-fix- A user-facing bug fix worth mentioning in the release notesrn/documentation- A user-facing documentation change worth mentioning in the release notesShould this PR be included in the next patch release?
Yesshould be selected for bug fixes, documentation updates, and other small changes.Noshould be selected for new features and larger changes. If you're unsure about the release classification of this PR, leave this unchecked to let the maintainers decide.What is a minor/patch release?
Bug fixes, doc updates and new features usually go into minor releases.
Bug fixes and doc updates usually go into patch releases.