The best way to control Claude Code, Codex and more from any computer or phone
fix(ssh): Host patterns match Unicode aliases byte by byte like OpenSSH (#38184)
Co-authored-by: Grok 4.7 <noreply@x.ai>
Wout Stiens committed
Nov 17, 2026 at 16:39 UTC
100ba49a65c0da19219e1e43216c5a619b269aa3
2 files changed
+11
-9
packages/ssh/src/config.test.ts
+3
-2
@@ -90,7 +90,7 @@ describe("ssh config", () => {
90
yield* fs.makeDirectory(path.join(sshDir, "single.d"));
91
yield* fs.writeFileString(
92
path.join(sshDir, "config"),
93
- "Include config.d/*\nInclude config.d/.literal.conf\nInclude config.d/.enabled-*.conf\nInclude explicit-directory\nInclude single.d/team?one.conf\nInclude single.d/exact??.conf\nHost real\n HostName real.example.com\nHost svc?x\n HostName wrong.example.com\nHost svc\u2028x\n HostName correct.example.com\n",
93
+ "Include config.d/*\nInclude config.d/.literal.conf\nInclude config.d/.enabled-*.conf\nInclude explicit-directory\nInclude single.d/team?one.conf\nInclude single.d/exact??.conf\nHost real\n HostName real.example.com\nHost svc?x\n HostName wrong.example.com\nHost svc\u2028x\n HostName correct.example.com\nHost svc\u00f8x\n HostName byte-correct.example.com\n",
94
);
95
for (const [index, separator] of ["\u2028", "\u2029"].entries()) {
96
yield* fs.writeFileString(
@@ -131,7 +131,7 @@ describe("ssh config", () => {
131
);
132
yield* fs.writeFileString(
133
path.join(sshDir, "known_hosts"),
134
- "known.example.com ssh-ed25519 AAAA\n",
134
+ "known.example.com ssh-ed25519 AAAA\nbyte-correct.example.com ssh-ed25519 AAAA\n",
135
);
136
137
const hosts = yield* discoverSshHosts({ homeDir });
@@ -145,6 +145,7 @@ describe("ssh config", () => {
145
["real", "real.example.com", "ssh-config"],
146
["single-ascii", "single-ascii.example.com", "ssh-config"],
147
["svc\u2028x", "correct.example.com", "ssh-config"],
148
+ ["svc\u00f8x", "byte-correct.example.com", "ssh-config"],
149
["team", "team.example.com", "ssh-config"],
150
["unicode-0", "unicode-0.example.com", "ssh-config"],
151
["unicode-1", "unicode-1.example.com", "ssh-config"],
packages/ssh/src/config.ts
+8
-7
@@ -92,16 +92,17 @@ function escapeRegex(value: string): string {
92
93
const utf8 = new TextEncoder();
94
95
-// OpenSSH's glob matches UTF-8 bytes, so `?` consumes one byte of a filename.
95
function globBytes(value: string): string {
96
return Array.from(utf8.encode(value), (byte) => String.fromCharCode(byte)).join("");
97
}
98
100
-function globToRegExp(pattern: string): RegExp {
101
- return new RegExp(
102
- `^${escapeRegex(pattern).replace(/\\\*/gu, "[^]*").replace(/\\\?/gu, ".")}$`,
99
+// OpenSSH matches Include globs and Host patterns on UTF-8 bytes, so `?` consumes one byte.
100
+function globMatcher(pattern: string): (value: string) => boolean {
101
+ const regex = new RegExp(
102
+ `^${escapeRegex(globBytes(pattern)).replace(/\\\*/gu, "[^]*").replace(/\\\?/gu, ".")}$`,
103
"u",
104
);
105
+ return (value) => regex.test(globBytes(value));
106
}
107
108
function hasGlobWildcard(value: string): boolean {
@@ -126,7 +127,7 @@ const expandGlob = Effect.fnUntraced(function* (
127
const directoryIsGlob = hasGlobWildcard(directoryPattern);
128
const directories = directoryIsGlob ? yield* expandGlob(directoryPattern) : [directoryPattern];
129
129
- const matcher = globToRegExp(globBytes(basePattern));
130
+ const matches = globMatcher(basePattern);
131
const matchedPaths: string[] = [];
132
for (const directory of directories) {
133
if (!(yield* fs.exists(directory))) continue;
@@ -137,7 +138,7 @@ const expandGlob = Effect.fnUntraced(function* (
138
: yield* fs.readDirectory(directory);
139
for (const entry of entries) {
140
if (entry.startsWith(".") && !basePattern.startsWith(".")) continue;
140
- if (!matcher.test(globBytes(entry))) {
141
+ if (!matches(entry)) {
142
continue;
143
}
144
const entryPath = path.join(directory, entry);
@@ -165,7 +166,7 @@ function matchesHostPatterns(alias: string, patterns: ReadonlyArray<string>): bo
166
const hostPattern = negated ? pattern.slice(1) : pattern;
167
const matches =
168
hostPattern === "*" ||
168
- (hasSshPattern(hostPattern) ? globToRegExp(hostPattern).test(alias) : hostPattern === alias);
169
+ (hasSshPattern(hostPattern) ? globMatcher(hostPattern)(alias) : hostPattern === alias);
170
if (!matches) continue;
171
if (negated) return false;
172
matched = true;