Repository navigation
fix(ui): make request IDs and copying work over plain HTTP - #1583
Merged
Merged
Conversation
`crypto.randomUUID` and `navigator.clipboard` exist only in secure contexts (HTTPS or localhost). Served over plain HTTP behind a proxy, every action that makes an ID failed with "crypto.randomUUID is not a function": starting, cancelling and rerunning runs, acknowledging, and changing triggers. Copy buttons either threw or said "Copied" without copying. - `newRequestId()` uses `crypto.randomUUID` where it exists, and otherwise builds an RFC 4122 version 4 UUID from `crypto.getRandomValues`, which every context has. - `copyText()` uses the Clipboard API where it exists and works, and otherwise copies from a hidden textarea. Copy buttons say "Copied" only when the text was copied. - A unit check keeps `crypto.randomUUID` and `navigator.clipboard` out of everything but these two helpers. - Tests: the fallback's format, version and variant bits, and uniqueness; in a browser with both APIs removed before the app loads, a plan (which makes a request ID) opens, and Copy as sqb build copies.
…nd help copy a secret by hand - The fallback copy puts back the person's own selection and focus, without scrolling, after copying from its hidden textarea. - When a one-time secret can't be copied, it is selected, with a hint to copy it with Ctrl+C (⌘C on a Mac).
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.
Why
Served over plain HTTP from a host name, for example behind a proxy, the UI page is not a secure context.
crypto.randomUUIDandnavigator.clipboarddon't exist there, so every action that makes a request ID failed with "crypto.randomUUID is not a function", and copy buttons did nothing.Changes
newRequestId(ui/src/lib/browser/request-id.ts) usescrypto.randomUUIDwhere the page has it and otherwise builds a version 4 UUID fromcrypto.getRandomValues. The API client and the mock large project use it.copyText(ui/src/lib/browser/clipboard.ts) uses the Clipboard API where it exists and otherwise copies through a hidden text area, keeping what the person had selected. Copy buttons, the selection bar, the SQL viewer and the plan page use it.crypto.randomUUIDornavigator.clipboarddirectly.DuckShop: no edge case added. This is browser behaviour in the UI, not a project shape, data value or lifecycle sequence.
Verification
npm run check(0 errors),npm test(83 files, 593 tests),npm run build.insecure-contextspec removes both APIs before the app loads and checks that a plan opens, copying works and keeps the selection, and the secret hint shows; thelayoutandbudgetsprojects pass.