diff --git a/src/web/public/keyboard-accessory.js b/src/web/public/keyboard-accessory.js index 4c3ec8bb..8423427e 100644 --- a/src/web/public/keyboard-accessory.js +++ b/src/web/public/keyboard-accessory.js @@ -1227,7 +1227,9 @@ const KeyboardAccessoryBar = { app._predictiveEcho?.clearPredictions(); // Match xterm's prepareTextForTerminal(): CR keeps embedded newlines inside // the single-line input transport and is what terminal.paste() emitted. - const pasteText = text.replace(/\r?\n/g, '\r'); + // Paste markers inside the text are dropped first: a clipboard carrying + // `ESC[201~` would end the bracket early and run the rest without Enter. + const pasteText = text.replace(/\x1b\[20[01]~/g, '').replace(/\r?\n/g, '\r'); if (pasteText.length > this._composerMaxLength) { app.showToast?.(`${label} is too long to send (maximum ${this._composerMaxLength.toLocaleString()} characters)`, 'error'); return false; diff --git a/test/mobile-prompt-composer.test.ts b/test/mobile-prompt-composer.test.ts index e7559eff..9e26355f 100644 --- a/test/mobile-prompt-composer.test.ts +++ b/test/mobile-prompt-composer.test.ts @@ -652,6 +652,17 @@ describe('mobile shell Paste', () => { expect(app._sendInputAsync).toHaveBeenCalledWith('session-1', '\x1b[200~echo one\recho two\x1b[201~'); }); + it('drops paste markers inside the text, so a pasted ESC[201~ cannot end the bracket early', () => { + const { app, input, send } = openShellPaste(); + // A pastejacking page can put the end marker on the clipboard: everything + // after it would be typed as keys, and its CR would run a command. + input.value = 'echo safe\x1b[201~\nrm -rf ~/x\x1b[200~'; + + send.click(); + + expect(app._sendInputAsync).toHaveBeenCalledWith('session-1', '\x1b[200~echo safe\rrm -rf ~/x\x1b[201~'); + }); + it('refuses a paste longer than one input frame and keeps the text for trimming', () => { const { app, bar, document, input, send } = openShellPaste(); input.value = 'x'.repeat(bar._composerMaxLength + 1);