tabby-rdp 0.5.2 → 0.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/drives.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SharedDrives = exports.WINDOW_OPEN_FILES = exports.MAX_OPEN_FILES = void 0;
3
+ exports.SharedDrives = exports.WINDOW_OPEN_FILES = exports.MAX_LISTED = exports.MAX_OPEN_FILES = void 0;
4
4
  exports.sharedFolders = sharedFolders;
5
5
  exports.driveName = driveName;
6
6
  exports.openFilesInWindow = openFilesInWindow;
@@ -51,6 +51,17 @@ const READ_LIMIT = 4 * 1024 * 1024;
51
51
  * far fewer open. More are refused (EMFILE) until the server closes some.
52
52
  */
53
53
  exports.MAX_OPEN_FILES = 1024;
54
+ /**
55
+ * Names one folder's listing gives the server at most (security review, finding 4). IronRDP keeps a listing whole with
56
+ * each folder handle the server opens, and the server decides how many it opens and which folder each lists: a shared
57
+ * folder with a great many names, listed again and again, would have the desktop's memory fill with copies of it. A
58
+ * folder anyone browses has far fewer; past this many, the rest aren't listed, and the log says so. What is left out is
59
+ * still there to open by its path (an open is a lookup of its own), though not to find by a query of the folder: IronRDP
60
+ * answers a query for one name, a pattern or all of them from this listing (patch 0015), so a name left out isn't
61
+ * found that way. This caps what one handle holds, not how many handles the server may hold, which stays IronRDP's to
62
+ * bound: the server can still have the desktop keep as many listings as it opens handles.
63
+ */
64
+ exports.MAX_LISTED = 10000;
54
65
  /**
55
66
  * Files all the desktops in a window may have open at once. The window's descriptors are one process's, so a limit per
56
67
  * desktop alone would let several desktops together hold that many times more. The window may have 8192 open on
@@ -136,6 +147,8 @@ class SharedDrives {
136
147
  this.full = false;
137
148
  /** The connection ended (see dispose): nothing more is opened, and what was still opening is closed again. */
138
149
  this.disposed = false;
150
+ /** A listing was cut short (see MAX_LISTED): said once. */
151
+ this.listCut = false;
139
152
  // RDPDR device ids are the session's: the audio device, when there is one, takes 0 in IronRDP.
140
153
  this.drives = folders.map((folder, i) => {
141
154
  this.byId.set(i + 1, folder);
@@ -312,7 +325,28 @@ class SharedDrives {
312
325
  }
313
326
  async list(deviceId, remote) {
314
327
  const { local } = await this.locate(deviceId, remote, true);
315
- return fsp.readdir(local);
328
+ // Read a few names at a time, up to MAX_LISTED: not the whole folder first (readdir), only to cut it short. Which
329
+ // names those are is the file system's order to read them in, not one the user could tell (the remote shows
330
+ // them sorted).
331
+ const names = [];
332
+ const dir = await fsp.opendir(local);
333
+ try {
334
+ for await (const entry of dir) {
335
+ if (names.length === exports.MAX_LISTED) {
336
+ if (!this.listCut) {
337
+ this.listCut = true;
338
+ this.log(`drives: a folder of more than ${exports.MAX_LISTED} names was listed: the remote gets ${exports.MAX_LISTED} of them, in no particular order (the rest are still there to open by path)`);
339
+ }
340
+ break;
341
+ }
342
+ names.push(entry.name);
343
+ }
344
+ }
345
+ finally {
346
+ // Closed by the loop as it ends, but for a read that throws.
347
+ await dir.close().catch(() => null);
348
+ }
349
+ return names;
316
350
  }
317
351
  async open(deviceId, remote, mode) {
318
352
  if (this.disposed) {
package/dist/h264.js ADDED
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MAX_H264_DECODERS = void 0;
4
+ exports.createH264Decoder = createH264Decoder;
5
+ /** Active and retiring browser decoders together, within one desktop session. */
6
+ exports.MAX_H264_DECODERS = 16;
7
+ /**
8
+ * Keep the vendor instance intact: IronRDP calls its endSurfaces hook even without another video frame, and the
9
+ * decoder owns pending-byte accounting, retiring decoders, readbacks and statistics. Capacity exhaustion follows
10
+ * its normal failure path, which reconnects without H.264; the plugin must not evict its private surface state.
11
+ */
12
+ function createH264Decoder(Decoder, options = {}) {
13
+ return new Decoder({ ...options, maxDecoders: exports.MAX_H264_DECODERS });
14
+ }
@@ -27,7 +27,6 @@ function terminalInputs(container) {
27
27
  /** An Angular factory provides one instance per plugin window; this module itself needs no Angular runtime. */
28
28
  class HostCompatibility {
29
29
  constructor(sources) {
30
- this.nativeModalDragRegion = null;
31
30
  const xtermDeclaration = text(read(() => {
32
31
  const terminal = sources.terminalPackage?.();
33
32
  return text(terminal?.dependencies?.['@xterm/xterm']) ?? text(terminal?.devDependencies?.['@xterm/xterm']);
@@ -37,25 +36,11 @@ class HostCompatibility {
37
36
  electron: text(sources.electron), node: text(sources.node), xtermDeclaration,
38
37
  xtermMajor: declaredMajor(xtermDeclaration),
39
38
  });
40
- this.modalStyle = sources.modalStyle ?? ((element, pseudo) => getComputedStyle(element, pseudo));
41
- }
42
- /** Probe each modal; themes and UI scale can change while the application is running. */
43
- hasNativeModalDragRegion(modal) {
44
- let supported = false;
45
- try {
46
- const style = this.modalStyle(modal, '::before');
47
- supported = style.content !== 'none' && style.content !== 'normal' && style.display !== 'none' &&
48
- style.getPropertyValue('-webkit-app-region') === 'drag' && parseFloat(style.height) > 0;
49
- }
50
- catch { }
51
- this.nativeModalDragRegion = supported;
52
- return supported;
53
39
  }
54
40
  snapshot(pane) {
55
41
  return {
56
42
  ...this.info,
57
43
  capabilities: {
58
- nativeModalDragRegion: this.nativeModalDragRegion,
59
44
  terminalInput: pane ? terminalInputs(pane).length > 0 : null,
60
45
  },
61
46
  };
@@ -63,14 +48,13 @@ class HostCompatibility {
63
48
  /** Local build information and observed capabilities only; no config, accounts, paths or connection details. */
64
49
  diagnosticLines(pane) {
65
50
  const info = this.snapshot(pane);
66
- const { nativeModalDragRegion, terminalInput } = info.capabilities;
67
- const drag = nativeModalDragRegion === null ? 'unobserved' : nativeModalDragRegion ? 'host' : 'plugin fallback';
51
+ const { terminalInput } = info.capabilities;
68
52
  const input = terminalInput === null ? 'unobserved' : terminalInput ? 'available' : 'unavailable';
69
53
  return [
70
54
  `Host: ${info.name ?? 'unknown'} ${info.version ?? 'unknown'} on ${info.platform ?? 'unknown'}`,
71
55
  `Runtime: Electron ${info.electron ?? 'unknown'}, Node ${info.node ?? 'unknown'}`,
72
56
  `Terminal: xterm ${info.xtermDeclaration ?? 'unknown'} (host declaration)`,
73
- `Compatibility: modal drag region ${drag}; terminal input ${input}`,
57
+ `Compatibility: terminal input ${input}`,
74
58
  ];
75
59
  }
76
60
  }
package/dist/index.js CHANGED
@@ -30,7 +30,7 @@ const ui_1 = require("./ui");
30
30
  let RemoteDesktopModule = class RemoteDesktopModule {
31
31
  constructor(app, hotkeys, desktop, header, targets, keyboard, injector) {
32
32
  const compat = injector.get(hostCompat_1.HostCompatibility);
33
- (0, desktop_service_1.installStyle)(compat);
33
+ (0, desktop_service_1.installStyle)();
34
34
  header.install();
35
35
  // Passwords go to Tabby's Vault while it is enabled (as Tabby's SSH passwords do), else to the system keychain.
36
36
  try {
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IronRDPLoader = void 0;
4
+ /** Loads and compiles once; every connection attempt gets fresh glue, classes, memory and allocator. */
5
+ class IronRDPLoader {
6
+ constructor(load) {
7
+ this.load = load;
8
+ this.source = null;
9
+ }
10
+ async create(level) {
11
+ const pending = this.source ??= this.load();
12
+ let source;
13
+ try {
14
+ source = await pending;
15
+ }
16
+ catch (error) {
17
+ if (this.source === pending) {
18
+ this.source = null;
19
+ }
20
+ throw error;
21
+ }
22
+ // A failed/trapped instance does not invalidate shared compiled code or another desktop's instance.
23
+ return source.createBackend(source.module, level);
24
+ }
25
+ }
26
+ exports.IronRDPLoader = IronRDPLoader;
package/dist/keyboard.js CHANGED
@@ -117,7 +117,18 @@ let DesktopKeyboard = class DesktopKeyboard {
117
117
  route(event) {
118
118
  const pane = this.startedOn.has(event) ? this.startedOn.get(event) : this.coveredPane();
119
119
  const focused = document.activeElement;
120
- if (!pane || focused?.tagName !== 'IRON-REMOTE-DESKTOP' || !pane.element.nativeElement.contains(focused)) {
120
+ if (focused?.tagName !== 'IRON-REMOTE-DESKTOP') {
121
+ return;
122
+ }
123
+ if (!pane || !pane.element.nativeElement.contains(focused)) {
124
+ // A desktop has the focus though its pane isn't the one the user is in (see
125
+ // RemoteDesktopService.letGoUnlessInFront, which takes it back a moment after the pane is left): IronRDP,
126
+ // whose listener comes after this one and only looks at the focus, would send it the key, view only or not.
127
+ // It goes nowhere instead, a keyup too: IronRDP lets go of nothing as its canvas loses the focus (only as
128
+ // the window does, or as the pointer leaves the canvas), so the keys the desktop still holds on the remote
129
+ // are let go of as the focus is taken back, this one among them.
130
+ event.stopImmediatePropagation();
131
+ event.preventDefault();
121
132
  return;
122
133
  }
123
134
  this.routing = pane;
package/dist/ntlm.js CHANGED
@@ -190,18 +190,25 @@ function ntlmV2Response(hash, serverChallenge, targetInfo, time, clientChallenge
190
190
  */
191
191
  function authenticateMessage(negotiate, challenge, account) {
192
192
  const server = parseChallenge(challenge);
193
+ // The sign-in is bound to the TLS connection and the service it is for by the pairs the client adds to the server's
194
+ // target information (see clientTargetInfo), and covered whole by the integrity code, which goes with the server's
195
+ // time among those pairs. A challenge without target information, or without the time, would have the answer go
196
+ // out bound to neither, with an LMv2 response besides that binds nothing either: one a gateway could pass on to
197
+ // another service that only checks the binding when it is there. Every Windows since Vista sends both, and an RD
198
+ // Gateway is a Windows Server 2012 R2 or later: such a challenge is refused (security review, finding 5).
199
+ if (!server.targetInfo.length) {
200
+ throw new Error('the gateway\'s NTLM challenge has no target information, so the sign-in couldn\'t be bound to this connection: not answered');
201
+ }
202
+ if (!avPair(server.targetInfo, AV_TIMESTAMP)) {
203
+ throw new Error('the gateway\'s NTLM challenge doesn\'t say when it is, so the sign-in couldn\'t be bound to this connection: not answered');
204
+ }
193
205
  const split = /^([^\\]+)\\(.+)$/.exec(account.username);
194
206
  const [domain, username] = split ? [split[1], split[2]] : [account.domain ?? '', account.username];
195
- // The server says when it is (a timestamp among its pairs) on every Windows since Vista: the response then
196
- // carries an integrity code, and the LM response is left empty.
197
- const timed = !!avPair(server.targetInfo, AV_TIMESTAMP);
198
- const targetInfo = server.targetInfo.length
199
- ? clientTargetInfo(server.targetInfo, { mic: timed, channelBinding: account.channelBinding, targetName: account.targetName })
200
- : server.targetInfo;
207
+ const targetInfo = clientTargetInfo(server.targetInfo, { mic: true, channelBinding: account.channelBinding, targetName: account.targetName });
201
208
  const hash = ntlmV2Hash(username, domain, account.password);
202
- const clientChallenge = (0, crypto_1.randomBytes)(8);
203
- const { response, sessionKey } = ntlmV2Response(hash, server.challenge, targetInfo, undefined, clientChallenge);
204
- const lm = timed ? Buffer.alloc(24) : Buffer.concat([hmacMd5(hash, server.challenge, clientChallenge), clientChallenge]);
209
+ const { response, sessionKey } = ntlmV2Response(hash, server.challenge, targetInfo);
210
+ // No LM response next to the server's time: the NT response and the integrity code are the proof.
211
+ const lm = Buffer.alloc(24);
205
212
  const fields = [lm, response, utf16(domain), utf16(username), utf16(account.workstation ?? ''), Buffer.alloc(0)];
206
213
  // 64 bytes of fields and flags, 8 of version (none), 16 of integrity code, then what the fields point at.
207
214
  const header = Buffer.alloc(88);
@@ -218,8 +225,6 @@ function authenticateMessage(negotiate, challenge, account) {
218
225
  NEGOTIATE_128 | NEGOTIATE_56;
219
226
  header.writeUInt32LE((server.flags & ours & ~NEGOTIATE_VERSION) >>> 0, 60);
220
227
  const message = Buffer.concat([header, ...fields]);
221
- if (timed) {
222
- hmacMd5(sessionKey, negotiate, challenge, message).copy(message, 72);
223
- }
228
+ hmacMd5(sessionKey, negotiate, challenge, message).copy(message, 72);
224
229
  return message;
225
230
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FLOW_WINDOW = void 0;
3
+ exports.SERVER_BACKLOG = exports.FLOW_WINDOW = void 0;
4
4
  exports.normalizeFingerprint = normalizeFingerprint;
5
5
  exports.preconnectionPdu = preconnectionPdu;
6
6
  exports.offersNla = offersNla;
@@ -32,9 +32,8 @@ function fingerprintOf(der) {
32
32
  return normalizeFingerprint((0, crypto_1.createHash)('sha256').update(der).digest('hex'));
33
33
  }
34
34
  /**
35
- * What answers to the remote's requests may have taken of the window's memory, read for it or handed to the connection,
36
- * beyond what the proxy has read from the connection (see ServerFlow): four of the largest parts of files a request
37
- * gets. A link stays busy with far less, as the proxy lets no more than HIGH_WATER wait for the server.
35
+ * What answers to the remote's requests may have taken of the window's memory, read for it, handed to the connection
36
+ * or waiting in the proxy for the server (see ServerFlow): four of the largest parts of files a request gets.
38
37
  */
39
38
  exports.FLOW_WINDOW = 64 * 1024 * 1024;
40
39
  /** The answer to a server without Network Level Authentication where nobody decides otherwise: refused. */
@@ -509,8 +508,15 @@ const MAX_EARLY = 256 * 1024;
509
508
  const MAX_CLIENTS = 4;
510
509
  /** A WebSocket message from the client: RDP PDUs, at most a few megabytes for a shared drive's read. */
511
510
  const MAX_MESSAGE = 32 * 1024 * 1024;
512
- /** Data waiting for the other side past this pauses the side it comes from, until half of it is gone. */
511
+ /** Data waiting for the client past this pauses the server, until half of it is gone. */
513
512
  const HIGH_WATER = 8 * 1024 * 1024;
513
+ /**
514
+ * What may wait in the proxy for a server that doesn't take it, before the connection ends (see send). Answers keep
515
+ * within FLOW_WINDOW of it and one message more (see ServerFlow), so the rest of what the client sends (input, sound,
516
+ * and the clipboard's answers, which nothing else bounds) always has HIGH_WATER at least: far more than it needs while
517
+ * the server reads.
518
+ */
519
+ exports.SERVER_BACKLOG = exports.FLOW_WINDOW + MAX_MESSAGE + HIGH_WATER;
514
520
  /**
515
521
  * Sends the client's X.224 request upstream, reads the confirm, then does TLS there. With a pre-connection blob, that
516
522
  * goes first; without an X.224 request (a Hyper-V VM's console), TLS follows the blob at once and X.224 is the
@@ -527,6 +533,8 @@ async function handshake(openUpstream, destination, pcb, x224Request, legacyTls,
527
533
  }
528
534
  const raw = await openUpstream(destination, signal);
529
535
  track(raw);
536
+ // What this handshake opened, in order, for destroyAll if it fails.
537
+ const opened = [raw];
530
538
  try {
531
539
  if (gone()) {
532
540
  throw new Error('the client left');
@@ -556,6 +564,7 @@ async function handshake(openUpstream, destination, pcb, x224Request, legacyTls,
556
564
  ...name ? { host: name, ca: (0, authorities_1.certificateAuthorities)(), ...(0, net_1.isIP)(name) ? {} : { servername: name } } : {},
557
565
  ...legacyTls ? KEY_ENCIPHERMENT_ONLY_TLS : {}, ...options.tls,
558
566
  });
567
+ opened.push(upstream);
559
568
  track(upstream);
560
569
  // An error after the one the handshake below waits for (the stream under it failing as the socket is destroyed,
561
570
  // which a TLS socket over a stream passes on as its own) would have no listener until the relay is up, and an
@@ -571,10 +580,22 @@ async function handshake(openUpstream, destination, pcb, x224Request, legacyTls,
571
580
  return { raw, upstream, x224 };
572
581
  }
573
582
  catch (e) {
574
- raw.destroy();
583
+ destroyAll(opened);
575
584
  throw e;
576
585
  }
577
586
  }
587
+ /**
588
+ * Destroys streams opened one over the other (the stream to the server, then TLS over it), the last opened first. TLS
589
+ * over a socket works inside the socket's own handle (Node's TLSWrap), and a socket destroyed under TLS still using it
590
+ * frees what TLS then reads: right after the handshake, where a certificate refused at once ends the connection, that
591
+ * crashed Tabby's window (a segmentation fault, in Node as in Electron). TLS destroyed first is done with the socket
592
+ * before the socket goes. (Over a stream of JavaScript, an SSH channel or a gateway's tunnel, the order did no harm.)
593
+ */
594
+ function destroyAll(streams) {
595
+ for (const stream of [...streams].reverse()) {
596
+ stream.destroy();
597
+ }
598
+ }
578
599
  /** Whether `given` is the secret, compared in a time that doesn't tell how much of it was right. */
579
600
  function sameSecret(given, secret) {
580
601
  const bytes = Buffer.from(given);
@@ -610,13 +631,16 @@ async function startRDCleanPathProxy(openUpstream, checkCertificate, log = () =>
610
631
  let legacyTls = false;
611
632
  const stats = { bytesIn: 0, bytesOut: 0 };
612
633
  // The room (see ServerFlow): what was taken for answers and not read from the connection since, the client whose
613
- // connection that is (the latest to reach the relay: a reconnect can overlap the connection it replaces), and what
614
- // waits for room. Once the proxy is closed there is room for good: nothing more goes anywhere.
634
+ // connection that is (the latest to reach the relay: a reconnect can overlap the connection it replaces), the
635
+ // stream to its server, where what the proxy read waits for the server, and what waits for room. Once the proxy is
636
+ // closed there is room for good: nothing more goes anywhere.
615
637
  let owed = 0;
616
638
  let flowClient = null;
639
+ let flowUpstream = null;
617
640
  let roomWaiters = [];
618
641
  let shut = false;
619
- const hasRoom = () => shut || owed < exports.FLOW_WINDOW;
642
+ const backlog = () => flowUpstream?.writableLength ?? 0;
643
+ const hasRoom = () => shut || owed + backlog() < exports.FLOW_WINDOW;
620
644
  const roomMade = () => {
621
645
  if (roomWaiters.length && hasRoom()) {
622
646
  const go = roomWaiters;
@@ -666,25 +690,36 @@ async function startRDCleanPathProxy(openUpstream, checkCertificate, log = () =>
666
690
  closed = true;
667
691
  leaving.abort();
668
692
  clearTimeout(deadline);
669
- for (const stream of streams) {
670
- stream.destroy();
671
- }
693
+ destroyAll(streams);
672
694
  // What was handed to this connection went with it: the next starts with all the room.
673
695
  if (flowClient === ws) {
674
696
  flowClient = null;
697
+ flowUpstream = null;
675
698
  owed = 0;
676
699
  roomMade();
677
700
  }
678
701
  };
679
702
  let deadline = setTimeout(() => stage === 'hello' && ws.terminate(), HELLO_TIMEOUT_MS);
680
703
  const toServer = options.autologon ? autologon() : (data) => data;
704
+ // The proxy reads the client whatever the server does: what the server doesn't take yet waits here, where it is
705
+ // counted, and not in the client's own queue to send, where nothing is (IronRDP's WebSocket sends without
706
+ // looking at it). The room keeps answers within bounds (see ServerFlow); the clipboard's answers, which the
707
+ // remote can ask for again and again, aren't counted there, so the connection ends once more waits than
708
+ // SERVER_BACKLOG. Each write taken by the server makes room again. A server that reads, slowly, can end up
709
+ // there too: what is pasted there from here goes as it is, however large (nothing bounds it), and more of it
710
+ // than SERVER_BACKLOG on a link that takes long to carry it waits here meanwhile. So the failure says how much
711
+ // waited, not only that the server stopped taking it.
681
712
  const send = (data) => {
682
713
  const out = toServer(data);
683
- // The server (or the SSH channel to it) not keeping up: stop reading from the client until it has (see
684
- // ServerFlow).
685
- if (out.length && !upstream.write(out) && upstream.writableLength > HIGH_WATER) {
686
- ws.pause();
687
- upstream.once('drain', () => ws.resume());
714
+ if (closed || !out.length) {
715
+ return;
716
+ }
717
+ upstream.write(out, roomMade);
718
+ if (upstream.writableLength > exports.SERVER_BACKLOG) {
719
+ failure = `more than ${Math.round(exports.SERVER_BACKLOG / 1024 / 1024)} MB sent to the server waited for it to take them (${Math.round(upstream.writableLength / 1024 / 1024)} MB): it stopped reading, or the link is too slow for what was sent`;
720
+ log(`RDCleanPath relay ended: ${failure}`);
721
+ ws.terminate();
722
+ end();
688
723
  }
689
724
  };
690
725
  failure = null;
@@ -706,12 +741,13 @@ async function startRDCleanPathProxy(openUpstream, checkCertificate, log = () =>
706
741
  ws.on('message', async (data) => {
707
742
  if (stage === 'relay') {
708
743
  stats.bytesOut += data.length;
709
- // Read from the connection: as much room again (see ServerFlow).
744
+ // Read from the connection: no longer waiting there, but in the proxy, for as long as the server doesn't
745
+ // take it (see ServerFlow).
710
746
  if (flowClient === ws) {
711
747
  owed = Math.max(0, owed - data.length);
712
- roomMade();
713
748
  }
714
749
  send(data);
750
+ roomMade();
715
751
  return;
716
752
  }
717
753
  if (stage === 'handshake') {
@@ -812,6 +848,7 @@ async function startRDCleanPathProxy(openUpstream, checkCertificate, log = () =>
812
848
  stage = 'relay';
813
849
  // The room is this connection's from now on, all of it (see ServerFlow).
814
850
  flowClient = ws;
851
+ flowUpstream = upstream;
815
852
  owed = 0;
816
853
  roomMade();
817
854
  // PROTOCOL_HYBRID_EX in the server's negotiation response: an Early User Authorization Result follows CredSSP.
@@ -872,6 +909,7 @@ async function startRDCleanPathProxy(openUpstream, checkCertificate, log = () =>
872
909
  token,
873
910
  stats,
874
911
  get failure() { return failure; },
912
+ get backlog() { return backlog(); },
875
913
  close: () => {
876
914
  // Stops listening, and ends the clients there are: close() alone waits for them.
877
915
  wss.close();
package/dist/rdpFile.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MICROPHONE_NOTE = void 0;
3
+ exports.MAX_RDP_FILE = exports.MICROPHONE_NOTE = void 0;
4
4
  exports.parseRdpFile = parseRdpFile;
5
5
  /**
6
6
  * The note for a file that asks for the microphone: not applied while the setting is off. With it on, every desktop
@@ -53,6 +53,11 @@ function decode(data) {
53
53
  }
54
54
  return b.toString('utf8');
55
55
  }
56
+ /**
57
+ * The most an .rdp file may be: one Remote Desktop Connection saves is a few KB, a signed one a few more. A larger one is
58
+ * refused before it is read: what it holds would be parsed on the thread that runs Tabby's window.
59
+ */
60
+ exports.MAX_RDP_FILE = 1024 * 1024;
56
61
  /** The connection a .rdp file describes, or null without a usable `full address`. */
57
62
  function parseRdpFile(data) {
58
63
  const settings = new Map();
@@ -60,9 +65,13 @@ function parseRdpFile(data) {
60
65
  // twice, differently, gets the narrower of the two rather than whichever line comes last.
61
66
  let clipboardOff = false;
62
67
  for (const line of decode(data).split(/\r?\n/)) {
63
- const m = /^\s*([^:]+?)\s*:\s*([sib])\s*:(.*)$/i.exec(line);
64
- if (m) {
65
- const key = m[1].toLowerCase();
68
+ // The name up to the first colon, trimmed after: a pattern with room for spaces on both sides of the name (as
69
+ // `\s*([^:]+?)\s*:` had) tries every way of splitting a line of spaces without a colon before it fails, in time
70
+ // that grows with the cube of its length, and a line of a few thousand spaces held up Tabby's window for seconds
71
+ // (security review, finding 2). This one takes a line's length, whatever it holds.
72
+ const m = /^([^:]*):\s*([sib])\s*:(.*)$/i.exec(line);
73
+ const key = m?.[1].trim().toLowerCase();
74
+ if (m && key) {
66
75
  const value = m[3].trim();
67
76
  settings.set(key, value);
68
77
  clipboardOff ||= key === 'redirectclipboard' && /^[+-]?\d+$/.test(value) && Number(value) === 0;
@@ -124,7 +124,7 @@ exports.RDPTabRecovery = RDPTabRecovery = __decorate([
124
124
  // ---- profile settings --------------------------------------------------------------------------
125
125
  /**
126
126
  * The profile's own fields in Tabby's profile editor (name, group, icon and color are Tabby's). Plain DOM like the
127
- * rest of the plugin, writing to the profile as you type.
127
+ * rest of the plugin. Address and gateway edits stay in the form until Save validates both of them.
128
128
  */
129
129
  let RDPProfileSettingsComponent = class RDPProfileSettingsComponent {
130
130
  constructor(element, injector) {
@@ -188,6 +188,7 @@ let RDPProfileSettingsComponent = class RDPProfileSettingsComponent {
188
188
  Applies on the next connection.</div>
189
189
  </div>`;
190
190
  const field = (name) => root.querySelector(`[name="${name}"]`);
191
+ this.connectionInputs = { address: field('address'), gateway: field('gateway') };
191
192
  field('address').value = o.host ? (0, desktopForm_1.formatAddress)(o.host, o.port || 3389) : '';
192
193
  field('kind').value = o.kind === 'gnome' || o.kind === 'xrdp' ? o.kind : 'windows';
193
194
  field('username').value = o.username ?? '';
@@ -196,10 +197,6 @@ let RDPProfileSettingsComponent = class RDPProfileSettingsComponent {
196
197
  const text = field('address').value;
197
198
  const address = (0, desktopForm_1.parseAddress)(text);
198
199
  root.querySelector('[data-for=address]').textContent = text.trim() && !address ? 'This doesn\'t look like an address.' : '';
199
- if (address) {
200
- o.host = address.host;
201
- o.port = address.port;
202
- }
203
200
  });
204
201
  field('kind').addEventListener('change', () => {
205
202
  const kind = field('kind').value;
@@ -227,12 +224,12 @@ let RDPProfileSettingsComponent = class RDPProfileSettingsComponent {
227
224
  ownAccount();
228
225
  field('username').addEventListener('input', () => { o.username = field('username').value.trim(); });
229
226
  field('domain').addEventListener('input', () => { o.domain = field('domain').value.trim(); });
230
- // The gateway, and its account where that isn't the desktop's (offered once there is a gateway and a saved account).
227
+ // The gateway, and its separate account or sign-in prompt.
231
228
  const gateway = field('gateway');
232
229
  const gatewayAccount = field('gatewayAccount');
233
230
  gateway.value = o.gateway ?? '';
234
- gatewayAccount.append(new Option('The same as the desktop\'s', ''), ...accounts.map(a => new Option(label(a), a.id)));
235
- if (o.gatewayAccount && !accounts.some(a => a.id === o.gatewayAccount)) {
231
+ gatewayAccount.append(new Option('The same as the desktop\'s', ''), new Option('Ask for a gateway account when connecting', accounts_1.ASK_GATEWAY_ACCOUNT), ...accounts.map(a => new Option(label(a), a.id)));
232
+ if (o.gatewayAccount && o.gatewayAccount !== accounts_1.ASK_GATEWAY_ACCOUNT && !accounts.some(a => a.id === o.gatewayAccount)) {
236
233
  gatewayAccount.append(new Option('(a saved account that no longer exists)', o.gatewayAccount));
237
234
  }
238
235
  gatewayAccount.value = o.gatewayAccount ?? '';
@@ -241,10 +238,7 @@ let RDPProfileSettingsComponent = class RDPProfileSettingsComponent {
241
238
  root.querySelector('[data-for=gateway]').textContent = text && !(0, gateway_1.parseGateway)(text) ? 'A name or address, with :port if it isn\'t 443.' : '';
242
239
  root.querySelector('[data-gateway-account]').hidden = !text || gatewayAccount.options.length < 2;
243
240
  };
244
- gateway.addEventListener('input', () => {
245
- o.gateway = gateway.value.trim();
246
- gatewayChanged();
247
- });
241
+ gateway.addEventListener('input', gatewayChanged);
248
242
  gatewayAccount.addEventListener('change', () => { o.gatewayAccount = gatewayAccount.value; });
249
243
  gatewayChanged();
250
244
  // Its own clipboard sharing, or the setting's (named, as it is now).
@@ -265,10 +259,45 @@ let RDPProfileSettingsComponent = class RDPProfileSettingsComponent {
265
259
  }
266
260
  save() {
267
261
  const o = this.profile.options;
262
+ if (this.connectionInputs) {
263
+ const { address: addressInput, gateway: gatewayInput } = this.connectionInputs;
264
+ const addressText = addressInput.value.trim();
265
+ const address = (0, desktopForm_1.parseAddress)(addressText);
266
+ const gatewayText = gatewayInput.value.trim();
267
+ // Empty addresses are useful in group/type defaults. They clear the destination instead of retaining it.
268
+ const addressError = addressText && !address ? 'This doesn\'t look like an address.' : '';
269
+ const gatewayError = gatewayText && !(0, gateway_1.parseGateway)(gatewayText) ? 'A name or address, with :port if it isn\'t 443.' : '';
270
+ const root = this.element.nativeElement;
271
+ root.querySelector('[data-for=address]').textContent = addressError;
272
+ root.querySelector('[data-for=gateway]').textContent = gatewayError;
273
+ if (addressError || gatewayError) {
274
+ ;
275
+ (addressError ? addressInput : gatewayInput).focus();
276
+ // Tabby invokes this synchronous hook before cleaning the proxy and closing the modal. Throwing
277
+ // stops that Save operation; a return value would be ignored by the host.
278
+ throw new Error(`Cannot save this RDP profile: ${addressError || gatewayError}`);
279
+ }
280
+ // Commit the two connection fields together only after both drafts pass validation.
281
+ o.host = address?.host ?? '';
282
+ // A blank destination carries no port edit: keep custom/inherited ports in group and type defaults.
283
+ if (address) {
284
+ o.port = address.port;
285
+ }
286
+ o.gateway = gatewayText;
287
+ }
268
288
  const { id, account, via, gateway } = this.before;
269
289
  if (!id) {
270
290
  return;
271
291
  }
292
+ if (!o.host) {
293
+ // A saved profile's address cleared: the desktop it led to is gone from it, as when the profile is removed
294
+ // (see RDPProfilesService.deleteProfile). Not for the type's or a group's defaults, which have no id of
295
+ // their own (an empty address is useful there): profiles that name that address keep what is saved for it.
296
+ if (!via && this.profile.id) {
297
+ this.injector.get(desktop_service_1.RemoteDesktopService).forgetDesktop(id, true, `"${this.profile.name}"`).catch(() => null);
298
+ }
299
+ return;
300
+ }
272
301
  if ((o.via ?? '') !== via) {
273
302
  // Reached another way, it is another desktop. A direct one's saved passwords (through any gateway, the ones
274
303
  // it had before included) and certificate were its own; one behind a host shares them with that host's
@@ -374,8 +403,9 @@ let RDPProfilesService = class RDPProfilesService extends tabby_core_1.QuickConn
374
403
  }
375
404
  deleteProfile(profile) {
376
405
  // A direct desktop's saved passwords (through any gateway: one it went through before too) and certificate are
377
- // its own; one behind a host shares them with that host's desktop at the same address.
378
- if (!profile.options.via) {
406
+ // its own; one behind a host shares them with that host's desktop at the same address. A profile without an
407
+ // address of its own leads to no desktop of its own: desktopIdOf would name 127.0.0.1:3389 for it.
408
+ if (!profile.options.via && (0, desktops_1.configText)(profile.options.host)) {
379
409
  this.injector.get(desktop_service_1.RemoteDesktopService).forgetDesktop((0, desktops_1.desktopIdOf)(profile.options), true, `"${profile.name}"`).catch(() => null);
380
410
  }
381
411
  }
package/dist/releases.js CHANGED
@@ -310,6 +310,7 @@ class ReleaseManager {
310
310
  if (reason) {
311
311
  throw new Error(reason);
312
312
  }
313
+ const targetFloor = this.catalog.versions.find(p => p.version === version).policy.rollbackFloor;
313
314
  if (version === this.running) {
314
315
  progress('success', `tabby-rdp ${version} is already running.`);
315
316
  return;
@@ -339,6 +340,8 @@ class ReleaseManager {
339
340
  this.state.previous = this.running;
340
341
  this.state.pending = version;
341
342
  this.state.removed = false;
343
+ // Record the target's data boundary before restart, while older windows may still be running.
344
+ this.state.rollbackFloor = greatest(this.state.rollbackFloor, targetFloor);
342
345
  if (returnToStable) {
343
346
  this.state.channel = 'stable';
344
347
  }