mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 14:48:28 +00:00
chore: Enable "curly" rule to avoid single-statement if confusion/errors.
This commit is contained in:
@@ -24,7 +24,9 @@ function isErrno(err: unknown): err is NodeJS.ErrnoException {
|
||||
|
||||
export function parseSshTarget(raw: string): SshParsedTarget | null {
|
||||
const trimmed = raw.trim().replace(/^ssh\s+/, "");
|
||||
if (!trimmed) return null;
|
||||
if (!trimmed) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const [userPart, hostPart] = trimmed.includes("@")
|
||||
? ((): [string | undefined, string] => {
|
||||
@@ -40,15 +42,23 @@ export function parseSshTarget(raw: string): SshParsedTarget | null {
|
||||
const host = hostPart.slice(0, colonIdx).trim();
|
||||
const portRaw = hostPart.slice(colonIdx + 1).trim();
|
||||
const port = Number.parseInt(portRaw, 10);
|
||||
if (!host || !Number.isFinite(port) || port <= 0) return null;
|
||||
if (!host || !Number.isFinite(port) || port <= 0) {
|
||||
return null;
|
||||
}
|
||||
// Security: Reject hostnames starting with '-' to prevent argument injection
|
||||
if (host.startsWith("-")) return null;
|
||||
if (host.startsWith("-")) {
|
||||
return null;
|
||||
}
|
||||
return { user: userPart, host, port };
|
||||
}
|
||||
|
||||
if (!hostPart) return null;
|
||||
if (!hostPart) {
|
||||
return null;
|
||||
}
|
||||
// Security: Reject hostnames starting with '-' to prevent argument injection
|
||||
if (hostPart.startsWith("-")) return null;
|
||||
if (hostPart.startsWith("-")) {
|
||||
return null;
|
||||
}
|
||||
return { user: userPart, host: hostPart, port: 22 };
|
||||
}
|
||||
|
||||
@@ -86,7 +96,9 @@ async function canConnectLocal(port: number): Promise<boolean> {
|
||||
async function waitForLocalListener(port: number, timeoutMs: number): Promise<void> {
|
||||
const startedAt = Date.now();
|
||||
while (Date.now() - startedAt < timeoutMs) {
|
||||
if (await canConnectLocal(port)) return;
|
||||
if (await canConnectLocal(port)) {
|
||||
return;
|
||||
}
|
||||
await new Promise((r) => setTimeout(r, 50));
|
||||
}
|
||||
throw new Error(`ssh tunnel did not start listening on localhost:${port}`);
|
||||
@@ -100,7 +112,9 @@ export async function startSshPortForward(opts: {
|
||||
timeoutMs: number;
|
||||
}): Promise<SshTunnel> {
|
||||
const parsed = parseSshTarget(opts.target);
|
||||
if (!parsed) throw new Error(`invalid SSH target: ${opts.target}`);
|
||||
if (!parsed) {
|
||||
throw new Error(`invalid SSH target: ${opts.target}`);
|
||||
}
|
||||
|
||||
let localPort = opts.localPortPreferred;
|
||||
try {
|
||||
@@ -155,7 +169,9 @@ export async function startSshPortForward(opts: {
|
||||
});
|
||||
|
||||
const stop = async () => {
|
||||
if (child.killed) return;
|
||||
if (child.killed) {
|
||||
return;
|
||||
}
|
||||
child.kill("SIGTERM");
|
||||
await new Promise<void>((resolve) => {
|
||||
const t = setTimeout(() => {
|
||||
|
||||
Reference in New Issue
Block a user