fix(app): generate blob ids without crypto.subtle in non-secure contexts - #42706
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes image paste failures in the web UI when accessed over plain HTTP on non-localhost origins by avoiding unconditional use of crypto.subtle and introducing a deterministic hashing fallback for blob IDs.
Changes:
- Compute blob IDs using SHA-256 via
crypto.subtle.digestwhen available. - Fall back to a deterministic pure-JS FNV-1a-based hash when
crypto.subtleis unavailable (non-secure contexts).
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
25
to
28
| const bytes = new Uint8Array(await blob.arrayBuffer()) | ||
| if (!crypto.subtle) return insecureContextID(bytes) | ||
| const id = Array.from(new Uint8Array(await crypto.subtle.digest("SHA-256", bytes))) | ||
| .map((byte) => byte.toString(16).padStart(2, "0")) |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #41706
Problem
blobID()callscrypto.subtle.digestunconditionally. Browsers do not exposecrypto.subtleover plain HTTP on a non-localhost origin, so pasting an image fromhttp://<server-ip>:4096throws.Fix
Keep SHA-256 content addressing when
crypto.subtleis available. Otherwise, generate a 128-bit ID withcrypto.getRandomValues(), which is available in insecure contexts.The fallback does not read or synchronously hash the blob. Deduplication is disabled only on the insecure HTTP path.
This supersedes #41710, which uses
Math.random()andDate.now()for the fallback ID.