Skip to content

fix(dashboard): copy links from menus on insecure contexts - #907

Merged
T3ST3ST3R0N merged 1 commit into
PasarGuard:devfrom
Lingikaushikreddy:fix/clipboard-copy-inside-menus
Oct 8, 2026
Merged

T3ST3ST3R0N merged 1 commit into
PasarGuard:devfrom
Lingikaushikreddy:fix/clipboard-copy-inside-menus

Conversation

@Lingikaushikreddy

Copy link
Copy Markdown
Contributor

Fixes #890.

Cause

When the panel is served over plain HTTP (a LAN IP via UVICORN_HOST, or UVICORN_UDS behind a proxy), window.isSecureContext is false, so useClipboard skips navigator.clipboard and falls back to document.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, so select() selects nothing. execCommand('copy') still returns true, so the success toast shows but the clipboard is unchanged. That matches the report. The subscription URL CopyButton works because it isn't inside the menu.

Fix

  • useClipboard: in the fallback, first set the text from a copy event (clipboardData.setData + preventDefault) and call execCommand('copy'). This doesn't depend on focus or selection. The textarea path stays as a last resort, and the secure-context navigator.clipboard path is unchanged.
  • "Copy user ID" in the same menu called navigator.clipboard.writeText directly, 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 from http://192.168.x.x so isSecureContext === false, and a focusin handler that returns focus to the menu like Radix FocusScope does. The clipboard was read back from a localhost page:

with focus trap without focus trap
current textarea fallback returns true, clipboard unchanged copies
copy-event fallback (this PR) copies copies

Also on this branch: VITE_BASE_API=/ bun run build succeeds. tsc -p tsconfig.app.json reports the same number of errors as dev. ESLint on the two changed files goes from 11 to 10 problems (the removed one is an unused error binding).

Not changed: api-key-modal.tsx also calls navigator.clipboard.writeText directly, so it has the same insecure-context issue. I can move it to the hook here or in a follow-up.

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
@coderabbitai

coderabbitai Bot commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: bb9aa065-5e5a-43ec-acbd-d9450b33529c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Lingikaushikreddy

Copy link
Copy Markdown
Contributor Author

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 (@radix-ui/react-dropdown-menu 2.1.24, what ^2.1.24 resolves to here): modal defaults to true, the menu passes that through as trapFocus, and FocusScope with trapped installs the focusin handler that pulls focus back into the menu. That is the behaviour the reduced page reproduced, and action-buttons.tsx renders DropdownMenu without overriding modal.

Happy to record a run against the real panel if you'd prefer that over the reduced repro.

@T3ST3ST3R0N
T3ST3ST3R0N merged commit cf93b3f into PasarGuard:dev Oct 8, 2026
4 checks passed
@T3ST3ST3R0N

Copy link
Copy Markdown
Collaborator

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 api-key-modal.tsx to the same hook in a follow-up PR would be very welcome.

T3ST3ST3R0N added a commit that referenced this pull request Oct 10, 2026
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.
Free-Guy-IR added a commit to Free-Guy-IR/panel that referenced this pull request Nov 2, 2026
… 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.
Free-Guy-IR pushed a commit to Free-Guy-IR/panel that referenced this pull request Nov 3, 2026
…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)
Free-Guy-IR added a commit to Free-Guy-IR/panel that referenced this pull request Nov 3, 2026
…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.
Free-Guy-IR pushed a commit to Free-Guy-IR/panel that referenced this pull request Nov 4, 2026
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants