From 617ddee75b02e28c0958e18752c78e22d53299da Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 25 Oct 2026 09:11:02 +0530 Subject: [PATCH] Remote control: Harden handling of passwords for async requests --- docs/changelog.rst | 4 ++++ kitty/remote_control.py | 6 ++++-- kitty_tests/remote_control.py | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 327fcba03..ba64daf59 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -342,6 +342,10 @@ Detailed list of changes unresponsive peer blocking all remote control communication (:iss:`10672`, :pull:`10632`, :pull:`10688`, :pull:`10690`) +- Remote control: Fix a crafted request being able to bypass password based + remote control authentication by masquerading as a cancellation of an + asynchronous request + - ssh kitten: Preserve the permissions of copied directories, including nested directories, instead of using the permissions of the top level directory and the remote umask (:pull:`10727`) diff --git a/kitty/remote_control.py b/kitty/remote_control.py index 744ce4a42..4ae1ca689 100644 --- a/kitty/remote_control.py +++ b/kitty/remote_control.py @@ -180,12 +180,14 @@ def is_cmd_allowed(pcmd: dict[str, Any], window: Optional['Window'], from_socket sid = pcmd.get('stream_id', '') if sid and active_streams.get(sid, '') == pcmd['cmd']: return True - if 'cancel_async' in pcmd and pcmd.get('async_id'): + if 'cancel_async' in pcmd and str(pcmd.get('async', '')): # we allow these without authentication as they are sent on error # conditions and we can't have users prompted for these. The worst side # effect of a malicious cancel_async request is that it can prevent # another async request from getting a result, if it knows the async_id - # of that request. + # of that request. The condition here must match the one in + # handle_cmd() exactly, so that these requests are guaranteed to only + # cancel and never execute the command. return True pw = pcmd.get('password', '') if not pw: diff --git a/kitty_tests/remote_control.py b/kitty_tests/remote_control.py index cae570eaf..d11050d44 100644 --- a/kitty_tests/remote_control.py +++ b/kitty_tests/remote_control.py @@ -95,6 +95,24 @@ class TestRemoteControl(BaseTest): boss.dispatch_action.assert_not_called() boss.show_error.assert_not_called() + def test_cancel_async_auth_bypass(self): + from kitty.boss import Boss as KittyBoss + from kitty.remote_control import handle_cmd, is_cmd_allowed + + self.set_options({'remote_control_password': {'secret': frozenset(('ls',))}}) + base = {'cmd': 'send_text', 'version': [0, 26, 0], 'payload': {'data': 'text:x'}, 'cancel_async': True} + for extra in ({'async_id': 'x'}, {'async_id': 'x', 'password': 'wrong'}, {'async_id': 'x', 'password': 'secret'}, {'async': ''}): + with self.subTest(extra=extra): + self.assertIsNot(is_cmd_allowed({**base, **extra}, None, False, {}), True) + # a genuine cancellation is allowed without a password and must only cancel + pcmd = {**base, 'async': 'x'} + self.assertIs(is_cmd_allowed(pcmd, None, False, {}), True) + command = command_for_name('send_text') + with patch.object(command, 'response_from_kitty') as rfk, patch.object(command, 'cancel_async_request') as car: + self.assertIsNone(handle_cmd(Mock(spec=KittyBoss), None, pcmd, 0, None)) + rfk.assert_not_called() + car.assert_called_once() + def test_combine_parse_error_reporting(self): from kitty.boss import Boss as KittyBoss