fix(cli): validate PuTTY jump tab addresses with net.isIP

The display-host check accepted malformed colon strings such as a:b:c and
rejected IPv4-mapped and zone-scoped IPv6 targets. Use Node's IP parser so
only real addresses become the tab title.

Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com>
This commit is contained in:
Cursor Agentand陈大猫 committed 2026-10-22 13:18:31 +00:00
1 parent 59ba1b3917
commit 09819e97ab
2 files changed
+37 -4

No files matched your search

+3 -4
View File
@@ -1,3 +1,5 @@
const net = require("net");
const SSH_PROTOCOL = "ssh";
const TELNET_PROTOCOL = "telnet";
@@ -145,10 +147,7 @@ function isDisplayIpv4(value) {
}
function isDisplayIpv6(value) {
if (!looksLikeIpv6(value)) return false;
if (!/^[0-9a-f:]+$/i.test(value)) return false;
const compressed = value.match(/::/g);
return !compressed || compressed.length === 1;
return net.isIP(value) === 6;
}
// A leftover IP positional is the PuTTY analogue of SecureCRT /N: the TCP
+34
View File
@@ -428,6 +428,40 @@ test("parsePuttyCommandLine does not guess a tab name from several leftover addr
assert.equal(parsed?.tabName, undefined);
});
test("parsePuttyCommandLine names IPv4-mapped and zone-scoped IPv6 jump targets", () => {
const mapped = parsePuttyCommandLine([
"Netcatty.exe",
"-ssh",
"alice@[::ffff:192.0.2.10]@198.51.100.20",
"-pw",
"example",
]);
assert.equal(mapped?.hostname, "198.51.100.20");
assert.equal(mapped?.tabName, "::ffff:192.0.2.10");
const zoned = parsePuttyCommandLine([
"Netcatty.exe",
"-ssh",
"alice@[fe80::1%eth0]@198.51.100.20",
"-pw",
"example",
]);
assert.equal(zoned?.hostname, "198.51.100.20");
assert.equal(zoned?.tabName, "fe80::1%eth0");
});
test("parsePuttyCommandLine does not title a jump tab with a malformed colon string", () => {
const parsed = parsePuttyCommandLine([
"Netcatty.exe",
"-ssh",
"alice@a:b:c@198.51.100.20",
"-pw",
"example",
]);
assert.equal(parsed?.hostname, "198.51.100.20");
assert.equal(parsed?.tabName, undefined);
});
test("parsePuttyCommandLine uses a bracketed IPv6 target inside a jump login", () => {
const parsed = parsePuttyCommandLine([
"Netcatty.exe",