Skip to content

Commit b8645db

Browse files
authored
properly escape . in host -> ssh conversion (#421)
1 parent 2766d2f commit b8645db

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- Fix bug where checking for overridden properties incorrectly converted host name pattern to regular expression.
6+
57
## [v1.3.9](https://github.com/coder/vscode-coder/releases/tag/v1.3.9) (2024-12-12)
68

79
- Only show a login failure dialog for explicit logins (and not autologins).

src/sshSupport.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,39 @@ Host coder-v?code--*
6868
ProxyCommand: '/tmp/coder --header="X-BAR=foo" coder.dev',
6969
})
7070
})
71+
72+
it("properly escapes meaningful regex characters", () => {
73+
const properties = computeSSHProperties(
74+
"coder-vscode.dev.coder.com--matalfi--dogfood",
75+
`Host *
76+
StrictHostKeyChecking yes
77+
78+
# ------------START-CODER-----------
79+
# This section is managed by coder. DO NOT EDIT.
80+
#
81+
# You should not hand-edit this section unless you are removing it, all
82+
# changes will be lost when running "coder config-ssh".
83+
#
84+
Host coder.*
85+
StrictHostKeyChecking=no
86+
UserKnownHostsFile=/dev/null
87+
ProxyCommand /usr/local/bin/coder --global-config "/Users/matifali/Library/Application Support/coderv2" ssh --stdio --ssh-host-prefix coder. %h
88+
# ------------END-CODER------------
89+
90+
# --- START CODER VSCODE dev.coder.com ---
91+
Host coder-vscode.dev.coder.com--*
92+
StrictHostKeyChecking no
93+
UserKnownHostsFile=/dev/null
94+
ProxyCommand "/Users/matifali/Library/Application Support/Code/User/globalStorage/coder.coder-remote/dev.coder.com/bin/coder-darwin-arm64" vscodessh --network-info-dir "/Users/matifali/Library/Application Support/Code/User/globalStorage/coder.coder-remote/net" --session-token-file "/Users/matifali/Library/Application Support/Code/User/globalStorage/coder.coder-remote/dev.coder.com/session" --url-file "/Users/matifali/Library/Application Support/Code/User/globalStorage/coder.coder-remote/dev.coder.com/url" %h
95+
# --- END CODER VSCODE dev.coder.com ---%
96+
97+
`,
98+
)
99+
100+
expect(properties).toEqual({
101+
StrictHostKeyChecking: "yes",
102+
ProxyCommand:
103+
'"/Users/matifali/Library/Application Support/Code/User/globalStorage/coder.coder-remote/dev.coder.com/bin/coder-darwin-arm64" vscodessh --network-info-dir "/Users/matifali/Library/Application Support/Code/User/globalStorage/coder.coder-remote/net" --session-token-file "/Users/matifali/Library/Application Support/Code/User/globalStorage/coder.coder-remote/dev.coder.com/session" --url-file "/Users/matifali/Library/Application Support/Code/User/globalStorage/coder.coder-remote/dev.coder.com/url" %h',
104+
UserKnownHostsFile: "/dev/null",
105+
})
106+
})

src/sshSupport.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,11 @@ export function computeSSHProperties(host: string, config: string): Record<strin
8585
if (!config) {
8686
return
8787
}
88+
8889
// In OpenSSH * matches any number of characters and ? matches exactly one.
89-
if (!new RegExp("^" + config?.Host.replace(/\*/g, ".*").replace(/\?/g, ".") + "$").test(host)) {
90+
if (
91+
!new RegExp("^" + config?.Host.replace(/\./g, "\\.").replace(/\*/g, ".*").replace(/\?/g, ".") + "$").test(host)
92+
) {
9093
return
9194
}
9295
Object.assign(merged, config.properties)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy