Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(desktop,maker-remote-ssh): 处理 R8 review 的引号校验对齐

yan7b2ce4ef36ce
diff --git a/apps/desktop/src/main/remote-ssh/__tests__/agentProxy.test.ts b/apps/desktop/src/main/remote-ssh/__tests__/agentProxy.test.ts
index 3486004226..3f0648743d 100644
--- a/apps/desktop/src/main/remote-ssh/__tests__/agentProxy.test.ts
+++ b/apps/desktop/src/main/remote-ssh/__tests__/agentProxy.test.ts
@@ -318,8 +318,18 @@ describe('ssh-host-prefs-store agentProxy', () => {
expect(() =>
setSshHostAgentProxy('h1', { enabled: true, localHost: 'bad host', localPort: 7890 }),
).toThrow(/invalid agentProxy/);
+ expect(() =>
+ setSshHostAgentProxy('h1', { enabled: true, localPort: 7890, localHost: '127.0.0.1' }),
+ ).not.toThrow();
expect(() =>
setSshHostAgentProxy('h1', { enabled: true, localHost: '127.0.0.1', localPort: 0 }),
).toThrow(/invalid agentProxy/);
+ // 引号同样拒 (与 IPC / renderer 校验对齐, review: PR #715 copilot R8)。
+ expect(() =>
+ setSshHostAgentProxy('h1', { enabled: true, localHost: `12'7.0.0.1`, localPort: 7890 }),
+ ).toThrow(/invalid agentProxy/);
+ expect(() =>
+ setSshHostAgentProxy('h1', { enabled: true, localHost: '12"7.0.0.1', localPort: 7890 }),
+ ).toThrow(/invalid agentProxy/);
});
});
diff --git a/apps/desktop/src/main/remote-ssh/ssh-host-prefs-store.ts b/apps/desktop/src/main/remote-ssh/ssh-host-prefs-store.ts
index 1a8d8dbd9b..7e12ad9098 100644
--- a/apps/desktop/src/main/remote-ssh/ssh-host-prefs-store.ts
+++ b/apps/desktop/src/main/remote-ssh/ssh-host-prefs-store.ts
@@ -53,7 +53,12 @@ function normalizeAgentProxy(raw: unknown): SshHostAgentProxyPref | undefined {
const v = raw as Record<string, unknown>;
const localHost = typeof v.localHost === 'string' ? v.localHost.trim() : '';
const localPort = typeof v.localPort === 'number' ? v.localPort : NaN;
- if (!localHost || /\s/.test(localHost)) return undefined;
+ // 引号与空白同样拒 (与 IPC normalizeAgentProxyInput / renderer 校验对齐,
+ // review: PR #715 copilot R8): 手编 prefs 的脏值不应在启动时被恢复成
+ // 可用 pref, 然后晚到 net.connect 才以难懂的方式失败。
+ if (!localHost || /\s/.test(localHost) || localHost.includes("'") || localHost.includes('"')) {
+ return undefined;
+ }
if (!Number.isInteger(localPort) || localPort < 1 || localPort > 65535) return undefined;
return { enabled: v.enabled === true, localHost, localPort };
}
diff --git a/packages/maker-remote-ssh/src/RemoteHost.ts b/packages/maker-remote-ssh/src/RemoteHost.ts
index d93ce8521d..7707b3f30c 100644
--- a/packages/maker-remote-ssh/src/RemoteHost.ts
+++ b/packages/maker-remote-ssh/src/RemoteHost.ts
@@ -520,7 +520,15 @@ export class RemoteHost {
* 指定, 通常是 127.0.0.1 上的 Proxy 端口。
*/
async ensureRemoteForward(spec: RemoteForwardSpec): Promise<RemoteForward> {
- if (!spec.localHost || /\s/.test(spec.localHost)) {
+ // 引号与空白同样拒 (与 desktop IPC / prefs-store 校验对齐, review:
+ // PR #715 copilot R8): localHost 是 net.connect 的目的地, 含引号的值
+ // 会晚到 connect 时才以难懂的错误失败, 入口直接给清晰校验错误。
+ if (
+ !spec.localHost ||
+ /\s/.test(spec.localHost) ||
+ spec.localHost.includes("'") ||
+ spec.localHost.includes('"')
+ ) {
throw new Error(`ensureRemoteForward: invalid localHost "${spec.localHost}"`);
}
if (!Number.isInteger(spec.localPort) || spec.localPort < 1 || spec.localPort > 65535) {
diff --git a/packages/maker-remote-ssh/src/__tests__/remoteHostForward.test.ts b/packages/maker-remote-ssh/src/__tests__/remoteHostForward.test.ts
index ad5d881189..8a6331937a 100644
--- a/packages/maker-remote-ssh/src/__tests__/remoteHostForward.test.ts
+++ b/packages/maker-remote-ssh/src/__tests__/remoteHostForward.test.ts
@@ -193,6 +193,14 @@ describe('RemoteHost remote forwarding', () => {
await expect(
host.ensureRemoteForward({ localHost: '127.0.0.1', localPort: 7890, preferredRemotePort: 70000 }),
).rejects.toThrow(/preferredRemotePort/);
+ // localHost 的引号与空白同样拒 (与 desktop IPC / prefs-store 对齐,
+ // review: PR #715 copilot R8) — 否则晚到 net.connect 才以难懂的错误失败。
+ await expect(
+ host.ensureRemoteForward({ localHost: `12'7.0.0.1`, localPort: 7890 }),
+ ).rejects.toThrow(/localHost/);
+ await expect(
+ host.ensureRemoteForward({ localHost: '12"7.0.0.1', localPort: 7890 }),
+ ).rejects.toThrow(/localHost/);
});
it('is idempotent for the same local target (no duplicate forwardIn)', async () => {