Merge PR #10795: Remote control: Do not register streams for async cancellations

This commit is contained in:
Kovid Goyal 2026-11-03 17:06:07 +05:30
commit 96ea662bc7
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
2 changed files with 24 additions and 4 deletions

View file

@ -233,10 +233,6 @@ def handle_cmd(
return {'ok': False, 'error': 'Streaming send of data is not supported for this command'}
if stream_id:
payload['stream_id'] = stream_id
active_streams[stream_id] = cmd['cmd']
if len(active_streams) > 32:
oldest = next(iter(active_streams))
del active_streams[oldest]
if async_id:
payload['async_id'] = async_id
if 'cancel_async' in cmd:
@ -247,6 +243,14 @@ def handle_cmd(
if len(active_async_requests) > 32:
oldest = next(iter(active_async_requests))
del active_async_requests[oldest]
if stream_id:
# Register the stream only after cancellations have returned, as they
# are allowed without authentication and requests on a registered
# stream are allowed without authentication as well
active_streams[stream_id] = cmd['cmd']
if len(active_streams) > 32:
oldest = next(iter(active_streams))
del active_streams[oldest]
try:
ans = c.response_from_kitty(boss, self_window or window, PayloadGetter(c, payload))
except Exception:

View file

@ -112,6 +112,22 @@ class TestRemoteControl(BaseTest):
self.assertIsNone(handle_cmd(Mock(spec=KittyBoss), None, pcmd, 0, None))
rfk.assert_not_called()
car.assert_called_once()
# a cancellation must not register its stream, otherwise later requests
# on that stream would be allowed without authentication
from kitty.remote_control import active_streams, close_active_stream
sid = 'cancel-async-stream'
self.addCleanup(close_active_stream, sid)
pcmd = {'cmd': 'run', 'version': [0, 26, 0], 'stream_id': sid, 'async': 'y', 'cancel_async': True}
self.assertIs(is_cmd_allowed(pcmd, None, False, {}), True)
command = command_for_name('run')
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()
self.assertNotIn(sid, active_streams)
pcmd = {'cmd': 'run', 'version': [0, 26, 0], 'stream_id': sid, 'payload': {'cmdline': ['true'], 'data': ''}}
self.assertIsNot(is_cmd_allowed(pcmd, None, False, {}), True)
def test_combine_parse_error_reporting(self):
from kitty.boss import Boss as KittyBoss