wezterm icon indicating copy to clipboard operation
wezterm copied to clipboard

fix(term): loop defang_paste until no embedded bracketed markers remain

Open molloyzak13 opened this issue 5 months ago • 2 comments

The bracketed paste defanging in send_paste strips embedded \x1b[200~ and \x1b[201~ sequences from pasted text so an attacker can't inject their own paste boundaries. The current code does a single pass of str::replace, which finds non-overlapping matches. That means a crafted input like \x1b\x1b[200~[200~ gets the inner pair stripped on pass one, leaving \x1b[200~[200~ — the outer sequences recombine into a valid marker that hits the terminal.

The fix extracts a defang_paste helper that loops until the output stabilises. On each iteration it clones the current string, runs both replaces, and breaks if nothing changed. The logic is the same, it just runs it to a fixed point.

Added six unit tests: plain text, single start marker, single end marker, both markers, the reporter's double-nested exploit case, triple nesting, and mixed double-nested start+end. The double-nested case fails on the old single-pass code (asserts "[200~injected" against "injected") and passes with the loop. Ran the full term test suite — all 231 existing tests pass plus the 6 new ones.

Closes #7784.

molloyzak13 avatar Jun 15 '26 07:06 molloyzak13

[!WARNING] This looks a lot like a bot account, it was created yesterday and opened 15 security issues on 15 repos, as well as ~30 PRs (most closed by the account itself..)..

The changes might be good though, worth checking out (except the doc comments ^^')

bew avatar Jun 15 '26 09:06 bew

Fair observation. The account's new and I've been shipping a lot of small fixes, I get that the volume looks odd from the outside. Happy to address any review notes.

molloyzak13 avatar Jun 15 '26 10:06 molloyzak13