Skip to content

Commit 1dac0bd

Browse files
committed
fix: refuse a clipboard write that carries no text string
A schema-only validator can pass {action:'write'}; the writer then sent ["write", undefined], which arrives as null and joined to "", silently clearing the clipboard. The writer now refuses a missing text, and the daemon refuses write positionals with no text element or a non-string one. "" stays the explicit clear request. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016qAu53rMak1bXMuR5U2gF4
1 parent 2235c87 commit 1dac0bd

4 files changed

Lines changed: 38 additions & 3 deletions

File tree

‎packages/command-surface/src/system/index.test.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,13 @@ describe('system command interface', () => {
208208
]);
209209
});
210210

211+
test('clipboard writer refuses a write without text instead of sending a hole', () => {
212+
expectInvalidArgs(
213+
() => clipboardDaemonWriter({ action: 'write' }),
214+
'clipboard write requires text',
215+
);
216+
});
217+
211218
test('clipboard structured input requires text for write and refuses it for read', () => {
212219
const metadata = findCommandMetadata('clipboard');
213220
expectInvalidArgs(

‎packages/command-surface/src/system/index.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,12 @@ function readBackMode(value: unknown): BackMode | undefined {
786786
}
787787

788788
function clipboardPositionals(input: ClipboardCommandOptions): string[] {
789-
return input.action === 'read' ? ['read'] : ['write', input.text];
789+
if (input.action === 'read') return ['read'];
790+
// `""` clears the clipboard; only a missing text is refused.
791+
if (typeof input.text !== 'string') {
792+
throw new AppError('INVALID_ARGS', 'clipboard write requires text (use "" to clear).');
793+
}
794+
return ['write', input.text];
790795
}
791796

792797
function readKeyboardInput(positionals: string[]): Record<string, unknown> {

‎packages/daemon/src/execution/handlers/__tests__/session-clipboard.test.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,26 @@ test('clipboard write forwards an explicit empty string as a clear', async () =>
163163
expect(response.ok && response.data).toMatchObject({ action: 'write', textLength: 0 });
164164
});
165165

166+
// A peer that serializes a missing text sends `["write", null]`; joining it would clear the
167+
// clipboard, so the write is refused instead.
168+
test.each([[['write']], [['write', null]], [['write', 'a', null]]])(
169+
'clipboard write refuses positionals %j that carry no text string',
170+
async (positionals) => {
171+
const spies = harness({ read: available, write: available });
172+
await expect(
173+
handleSessionClipboardCommand({
174+
...request(positionals as string[]),
175+
...spies,
176+
platformServices: daemonPlatformServicesFixture(),
177+
}),
178+
).rejects.toMatchObject({
179+
code: 'INVALID_ARGS',
180+
message: 'clipboard write requires text (use "" to clear clipboard)',
181+
});
182+
expect(spies.writeClipboard).not.toHaveBeenCalled();
183+
},
184+
);
185+
166186
// ADR 0019 §9: the parsed subcommand selects exactly one use, so a request inspects facts once
167187
// and binds once — never both halves, and never a bind per operation.
168188
test.each([{ positionals: ['read'] }, { positionals: ['write', 'text'] }])(

‎packages/daemon/src/execution/handlers/session-clipboard.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,13 @@ async function executeClipboardWrite(
8787
context: DaemonCommandContext,
8888
positionals: readonly string[],
8989
): Promise<Record<string, unknown>> {
90-
if (positionals.length < 2) {
90+
// A wire peer can send `["write", null]` for a missing text; joining it would clear the
91+
// clipboard, so every text element must be a string.
92+
const textParts: readonly unknown[] = positionals.slice(1);
93+
if (textParts.length === 0 || textParts.some((part) => typeof part !== 'string')) {
9194
throw new AppError('INVALID_ARGS', 'clipboard write requires text (use "" to clear clipboard)');
9295
}
93-
const text = positionals.slice(1).join(' ');
96+
const text = textParts.join(' ');
9497
const input: ClipboardWriteInput = { ...clipboardInput(context), text };
9598
await runtime.operations.writeClipboard(input);
9699
return {

0 commit comments

Comments
 (0)