Repository navigation
fix(dashboard): copy links from menus on insecure contexts - #907
T3ST3ST3R0N merged 1 commit into
Conversation
On plain HTTP (LAN IP or UDS behind a proxy) navigator.clipboard is
unavailable, so useClipboard falls back to execCommand('copy') on a hidden
textarea. Inside the users action dropdown, the Radix focus trap pulls focus
back from the textarea, the selection is empty, and execCommand still returns
true: the success toast shows while the clipboard is unchanged.
Write the text from a copy event first, which does not depend on focus or
selection, and keep the textarea path as a last resort. Route the Copy user ID
action through the same hook instead of calling navigator.clipboard directly.
Fixes PasarGuard#890
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
To be precise about what I measured: the headless-Chrome run used a reduced page that imitates the focus trap, not the dashboard itself, so I want to back the claim about the real menu with something better than a resemblance. Checked in the installed dependency ( Happy to record a run against the real panel if you'd prefer that over the reduced repro. |
|
Thanks a lot, merged. The focus-trap diagnosis and the repro table made this easy to review, and we confirmed it in a browser over plain HTTP: every copy action in the row menus now puts the right text on the clipboard. If you have time, moving |
The API key creation dialog and the reissue dialog called navigator.clipboard.writeText directly. On plain HTTP navigator.clipboard is undefined, so the copy button threw and copied nothing; on HTTPS the success toast did not wait for the write. Use the shared useClipboard hook (which has the insecure-context fallbacks from #907) in both places, and show the usual "copy failed" toast when copying fails.
… to ff6e596 Every Port queue line in the panel and side-repository ledgers now says `security: yes` or `security: no`. Security: c9b445a (passkey client rename), eb50bfd, PasarGuard#938, PasarGuard#940, PasarGuard#942, the cryptography 50.0.2 security release, and the ten commits of upstream's PasarGuard#979 permission-leak batch (user list scopes, API-key permissions, HWID visibility, users.read, the Telegram inline search), which no branch ports yet. Checked with git ls-remote on 2026-10-09: upstream dev moved to ff6e596. The PasarGuard#979 batch, the node RPC fixes (PasarGuard#977, PasarGuard#978), the core-deletion restart (PasarGuard#934), dashboard fixes (PasarGuard#852, PasarGuard#907, PasarGuard#949, PasarGuard#952), performance changes (PasarGuard#945, PasarGuard#853, PasarGuard#855) and the merged dependabot bumps (ruff, uvloop, fastapi) join the queue; the ruff and uvloop conditional waivers ended when upstream merged them. Waived: PasarGuard#980 and its branch commit (the Telegram notifier workflow the fork deleted) and the superseded fastapi dependabot head b021d6f. The refs snapshot records the five new heads. Fork core-kit main 90701408 now contains upstream d2ecb5bd, so that ledger is empty. No side repository gained an upstream commit since 2026-10-07.
…d#907) On plain HTTP (LAN IP or UDS behind a proxy) navigator.clipboard is unavailable, so useClipboard falls back to execCommand('copy') on a hidden textarea. Inside the users action dropdown, the Radix focus trap pulls focus back from the textarea, the selection is empty, and execCommand still returns true: the success toast shows while the clipboard is unchanged. Write the text from a copy event first, which does not depend on focus or selection, and keep the textarea path as a last resort. Route the Copy user ID action through the same hook instead of calling navigator.clipboard directly. Fixes PasarGuard#890 (cherry picked from commit cf93b3f)
…exts Fork counterpart of upstream cf93b3f (PasarGuard#907), which routed the users menu Copy user ID action through useClipboard and gave the hook a copy-event path. The fork-only L2TP core form (features/core-editor/components/l2tp/l2tp-form.tsx) and MTProto instance form (features/core-editor/components/mtproto/ mtproto-instance-form.tsx) called navigator.clipboard directly; they now copy through the same hook. The API key copy buttons stay with upstream 6ad9a84, which the ledger re-decides.
The API key creation dialog and the reissue dialog called navigator.clipboard.writeText directly. On plain HTTP navigator.clipboard is undefined, so the copy button threw and copied nothing; on HTTPS the success toast did not wait for the write. Use the shared useClipboard hook (which has the insecure-context fallbacks from PasarGuard#907) in both places, and show the usual "copy failed" toast when copying fails. (cherry picked from commit 80d9501)
Fixes #890.
Cause
When the panel is served over plain HTTP (a LAN IP via
UVICORN_HOST, orUVICORN_UDSbehind a proxy),window.isSecureContextis false, souseClipboardskipsnavigator.clipboardand falls back todocument.execCommand('copy')on a hidden textarea."Copy links" / "links (base64)" run that fallback from inside the users action
DropdownMenu, while its Radix focus scope is still trapping focus. The trap pulls focus back from the textarea, soselect()selects nothing.execCommand('copy')still returnstrue, so the success toast shows but the clipboard is unchanged. That matches the report. The subscription URLCopyButtonworks because it isn't inside the menu.Fix
useClipboard: in the fallback, first set the text from acopyevent (clipboardData.setData+preventDefault) and callexecCommand('copy'). This doesn't depend on focus or selection. The textarea path stays as a last resort, and the secure-contextnavigator.clipboardpath is unchanged.navigator.clipboard.writeTextdirectly, which throws on insecure contexts. It now goes through the same hook.How I verified
A reduced repro in headless Chrome (Playwright,
channel: 'chrome'), with the page loaded fromhttp://192.168.x.xsoisSecureContext === false, and afocusinhandler that returns focus to the menu like RadixFocusScopedoes. The clipboard was read back from alocalhostpage:true, clipboard unchangedAlso on this branch:
VITE_BASE_API=/ bun run buildsucceeds.tsc -p tsconfig.app.jsonreports the same number of errors asdev. ESLint on the two changed files goes from 11 to 10 problems (the removed one is an unusederrorbinding).Not changed:
api-key-modal.tsxalso callsnavigator.clipboard.writeTextdirectly, so it has the same insecure-context issue. I can move it to the hook here or in a follow-up.