fix(ssh): reject hostnames with stray leading or trailing colons in p… · openclaw/openclaw@a2b3aab
miorbnli
·
2026-06-22
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -21,6 +21,13 @@ export type SshTunnel = {
|
21 | 21 | stop: () => Promise<void>; |
22 | 22 | }; |
23 | 23 | |
| 24 | +// Reject hosts that would corrupt the SSH HostName field or enable argument |
| 25 | +// injection: a leading '-' becomes an ssh option, and a stray leading/trailing |
| 26 | +// ':' (e.g. sliced from "host::22") produces an invalid HostName. |
| 27 | +function isMalformedHost(host: string): boolean { |
| 28 | +return host.startsWith("-") || host.startsWith(":") || host.endsWith(":"); |
| 29 | +} |
| 30 | + |
24 | 31 | export function parseSshTarget(raw: string): SshParsedTarget | null { |
25 | 32 | const trimmed = raw.trim().replace(/^ssh\s+/, ""); |
26 | 33 | if (!trimmed) { |
@@ -44,8 +51,7 @@ export function parseSshTarget(raw: string): SshParsedTarget | null {
|
44 | 51 | if (!host || port === undefined || port > 65535) { |
45 | 52 | return null; |
46 | 53 | } |
47 | | -// Security: Reject hostnames starting with '-' to prevent argument injection |
48 | | -if (host.startsWith("-")) { |
| 54 | +if (isMalformedHost(host)) { |
49 | 55 | return null; |
50 | 56 | } |
51 | 57 | return { user: userPart, host, port }; |
@@ -54,8 +60,7 @@ export function parseSshTarget(raw: string): SshParsedTarget | null {
|
54 | 60 | if (!hostPart) { |
55 | 61 | return null; |
56 | 62 | } |
57 | | -// Security: Reject hostnames starting with '-' to prevent argument injection |
58 | | -if (hostPart.startsWith("-")) { |
| 63 | +if (isMalformedHost(hostPart)) { |
59 | 64 | return null; |
60 | 65 | } |
61 | 66 | return { user: userPart, host: hostPart, port: 22 }; |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。