Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
detectEditors,
configureMcp,
ApiError,
buildMacClipboardArgs,
type Model,
type AspectRatio,
type Style,
Expand Down Expand Up @@ -123,7 +124,7 @@ async function copyToClipboard(imagePath: string): Promise<boolean> {
const { execFileSync } = await import('node:child_process')
try {
if (process.platform === 'darwin') {
execFileSync('osascript', ['-e', `set the clipboard to (read (POSIX file "${imagePath}") as TIFF picture)`])
execFileSync('osascript', buildMacClipboardArgs(imagePath))
} else {
execFileSync('xclip', ['-selection', 'clipboard', '-t', 'image/png', '-i', imagePath])
}
Expand Down
12 changes: 12 additions & 0 deletions src/core/clipboard.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { describe, it, expect } from 'vitest'
import { buildMacClipboardArgs } from './clipboard.js'

describe('buildMacClipboardArgs', () => {
it('passes image path as argv, not interpolated script', () => {
const maliciousPath = 'safe" ) & do shell script "touch /tmp/pwned" & ("'
const args = buildMacClipboardArgs(maliciousPath)

expect(args.at(-1)).toBe(maliciousPath)
expect(args.slice(0, -1).join(' ')).not.toContain(maliciousPath)
})
})
13 changes: 13 additions & 0 deletions src/core/clipboard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export function buildMacClipboardArgs(imagePath: string): string[] {
return [
'-e',
'on run argv',
'-e',
'set imagePath to POSIX file (item 1 of argv)',
'-e',
'set the clipboard to (read imagePath as TIFF picture)',
'-e',
'end run',
imagePath,
]
}
1 change: 1 addition & 0 deletions src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ export { ApiError } from './types.js'
export { timeAgo } from './utils.js'
export { initiateDeviceAuth, pollForToken } from './device-auth.js'
export { detectEditors, configureMcp, type EditorInfo } from './mcp-config.js'
export { buildMacClipboardArgs } from './clipboard.js'