Skip to content

fix(clipboard): fix Windows escaping, macOS/Linux shell injection, and Clipboard.copy typo#95

Merged
gregpriday merged 1 commit into
developfrom
feature/issue-86-clipboard-file-reference
Feb 26, 2026
Merged

fix(clipboard): fix Windows escaping, macOS/Linux shell injection, and Clipboard.copy typo#95
gregpriday merged 1 commit into
developfrom
feature/issue-86-clipboard-file-reference

Conversation

@gregpriday
Copy link
Copy Markdown
Owner

Summary

Fixes all four clipboard/file-reference bugs reported in issue #86.

Closes #86

Changes Made

  • src/api/copy.js — Fix Clipboard.copy(output)Clipboard.copyText(output) (the method Clipboard.copy did not exist; this was a TypeError at runtime)
  • src/utils/clipboard.js — Windows copyFileReference — Replace Set-Clipboard -Path (vulnerable to [/] glob expansion with no -LiteralPath available) with Windows Forms SetFileDropList via Base64-encoded -EncodedCommand; eliminates all shell quoting at the Node→PowerShell boundary and prevents wildcard interpretation of brackets
  • src/utils/clipboard.js — macOS copyFileReference + revealInFinder — Switch from execSync(\osascript -e '...'`)tospawnSync('osascript', ['-e', script]); eliminates single-quote shell injection for paths like /Users/it's/file.xml`
  • src/utils/clipboard.js — macOS revealInFinder — Fix no-op escape replace(/"/g, '"') → correct replace(/\\/g, '\\\\').replace(/"/g, '\\"') for AppleScript double-quoted strings
  • src/utils/clipboard.js — Linux revealInFinder — Switch from execSync(\xdg-open "${dir}"`)tospawnSync('xdg-open', [dir]); eliminates $`-expansion and double-quote injection
  • tests/setup-global-mocks.js — Add mock.default = mock to clipboardy mock so dynamic ESM import('clipboardy') resolves .default correctly in tests
  • tests/unit/utils/clipboard.test.js (new) — 23 unit tests covering all three platform branches and edge cases: single quotes, [/], $, &/|, UNC paths, backslashes, fallback behaviour
  • tests/unit/api/copy.test.js — 2 new tests: clipboard: true success path (asserts copyText is called) and error suppression (asserts clipboardError is recorded without throwing)

…d Clipboard.copy typo

- Fix Clipboard.copy() → Clipboard.copyText() in api/copy.js (TypeError fix)
- Windows copyFileReference: replace Set-Clipboard -Path (glob vulnerable) with
  Windows Forms SetFileDropList via Base64-encoded PowerShell; eliminates bracket
  wildcard expansion and bypasses all shell quoting at the Node→PS boundary
- macOS copyFileReference + revealInFinder: switch from execSync(osascript -e '...')
  to spawnSync(['osascript', '-e', script]); eliminates single-quote shell injection
- Windows revealInFinder: already used spawnSync; no change needed
- Linux revealInFinder: switch from execSync(xdg-open "...") to spawnSync(['xdg-open', dir]);
  eliminates $-expansion and double-quote injection
- Fix clipboardy mock: add mock.default = mock so dynamic ESM imports resolve correctly
- Add 23 unit tests in tests/unit/utils/clipboard.test.js covering all platforms
  and special-character edge cases
- Add 2 tests to copy.test.js: clipboard success path and error suppression branch
@gregpriday gregpriday merged commit 90043a4 into develop Feb 26, 2026
11 of 15 checks passed
@gregpriday gregpriday deleted the feature/issue-86-clipboard-file-reference branch February 26, 2026 03:20
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.

Clipboard and file-reference operations broken on Windows, plus cross-platform escaping bugs

1 participant