Skip to content

Commit 79cf770

Browse files
authored
Fix client_idle_timeout enforcement for desktop sessions (#56052)
We had been updating the client activity tracker any time a message was sent from the client (browser or Teleport Connect) to the remote host. This approach was fine for the original RDP implmentation, as all messages sent in this direction were for user input (keypresses, mouse movement, scroll wheel, etc), but it is insufficient with the current RemoteFX implementation as there are some messages sent by the remote Windows hosts which require client acknowledgements. These acknowledgements were mistakenly being counted as client activity. Closes #55691
1 parent f699d89 commit 79cf770

File tree

4 files changed

+23
-11
lines changed

4 files changed

+23
-11
lines changed

lib/srv/desktop/rdp/rdpclient/client.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,19 @@ func (c *Client) startInputStreaming(stopCh chan struct{}) error {
417417
continue
418418
}
419419

420-
c.UpdateClientActivity()
420+
// If the message was due to user input, then we update client activity
421+
// in order to refresh the client_idle_timeout checks.
422+
//
423+
// Note: we count some of the directory sharing messages as client activity
424+
// because we don't want a session to be closed due to inactivity during a large
425+
// file transfer.
426+
switch msg.(type) {
427+
case tdp.KeyboardButton, tdp.MouseMove, tdp.MouseButton, tdp.MouseWheel,
428+
tdp.SharedDirectoryAnnounce, tdp.SharedDirectoryInfoResponse,
429+
tdp.SharedDirectoryReadResponse, tdp.SharedDirectoryWriteResponse:
430+
431+
c.UpdateClientActivity()
432+
}
421433

422434
if withheldResize != nil {
423435
c.cfg.Log.Debug("Sending withheld screen size to client")

web/packages/teleport/src/lib/tdp/client.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ export default class Client extends EventEmitterWebAuthnSender {
267267
this.handleRdpConnectionActivated(buffer);
268268
break;
269269
case MessageType.RDP_FASTPATH_PDU:
270-
this.handleRdpFastPathPDU(buffer);
270+
this.handleRdpFastPathPdu(buffer);
271271
break;
272272
case MessageType.CLIENT_SCREEN_SPEC:
273273
this.handleClientScreenSpec(buffer);
@@ -410,8 +410,8 @@ export default class Client extends EventEmitterWebAuthnSender {
410410
this.emit(TdpClientEvent.TDP_CLIENT_SCREEN_SPEC, spec);
411411
}
412412

413-
handleRdpFastPathPDU(buffer: ArrayBuffer) {
414-
let rdpFastPathPDU = this.codec.decodeRdpFastPathPDU(buffer);
413+
handleRdpFastPathPdu(buffer: ArrayBufferLike) {
414+
let rdpFastPathPdu = this.codec.decodeRdpFastPathPdu(buffer);
415415

416416
// This should never happen but let's catch it with an error in case it does.
417417
if (!this.fastPathProcessor)
@@ -422,13 +422,13 @@ export default class Client extends EventEmitterWebAuthnSender {
422422

423423
try {
424424
this.fastPathProcessor.process(
425-
rdpFastPathPDU,
425+
rdpFastPathPdu,
426426
this,
427427
(bmpFrame: BitmapFrame) => {
428428
this.emit(TdpClientEvent.TDP_BMP_FRAME, bmpFrame);
429429
},
430430
(responseFrame: ArrayBuffer) => {
431-
this.sendRdpResponsePDU(responseFrame);
431+
this.sendRdpResponsePdu(responseFrame);
432432
},
433433
(data: ImageData | boolean, hotspot_x?: number, hotspot_y?: number) => {
434434
this.emit(TdpClientEvent.POINTER, { data, hotspot_x, hotspot_y });
@@ -765,8 +765,8 @@ export default class Client extends EventEmitterWebAuthnSender {
765765
this.sendClientScreenSpec(spec);
766766
}
767767

768-
sendRdpResponsePDU(responseFrame: ArrayBuffer) {
769-
this.send(this.codec.encodeRdpResponsePDU(responseFrame));
768+
sendRdpResponsePdu(responseFrame: ArrayBufferLike) {
769+
this.send(this.codec.encodeRdpResponsePdu(responseFrame));
770770
}
771771

772772
// Emits an errType event and closes the websocket connection.

web/packages/teleport/src/lib/tdp/codec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ export default class Codec {
722722
}
723723

724724
// | message type (30) | data_length uint32 | data []byte |
725-
encodeRdpResponsePDU(responseFrame: ArrayBuffer): Message {
725+
encodeRdpResponsePdu(responseFrame: ArrayBufferLike): Message {
726726
const bufLen = BYTE_LEN + UINT_32_LEN + responseFrame.byteLength;
727727
const buffer = new ArrayBuffer(bufLen);
728728
const view = new DataView(buffer);
@@ -871,7 +871,7 @@ export default class Codec {
871871
}
872872

873873
// | message type (29) | data_length uint32 | data []byte |
874-
decodeRdpFastPathPDU(buffer: ArrayBuffer): RdpFastPathPdu {
874+
decodeRdpFastPathPdu(buffer: ArrayBufferLike): RdpFastPathPdu {
875875
const dv = new DataView(buffer);
876876
let offset = 0;
877877
offset += BYTE_LEN; // eat message type

web/packages/teleport/src/lib/tdp/playerClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ export class PlayerClient extends Client {
209209
// RDP response PDUs to the server during playback, which is unnecessary
210210
// and breaks the playback system.
211211
// eslint-disable-next-line @typescript-eslint/no-unused-vars
212-
sendRdpResponsePDU(responseFrame: ArrayBuffer) {
212+
sendRdpResponsePdu(responseFrame: ArrayBuffer) {
213213
return;
214214
}
215215

0 commit comments

Comments
 (0)