Remote control: Harden handling of passwords for async requests

This commit is contained in:
Kovid Goyal 2026-10-25 09:11:02 +05:30
parent c8f8aa5344
commit 617ddee75b
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
3 changed files with 26 additions and 2 deletions

View file

@ -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`)

View file

@ -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:

View file

@ -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