fix(security): harden imessage remote scp/ssh handling

This commit is contained in:
Peter Steinberger
2026-02-19 11:07:56 +01:00
parent cdb00fe242
commit 49d0def6d1
12 changed files with 150 additions and 12 deletions

View File

@@ -36,4 +36,31 @@ describe("config schema regressions", () => {
expect(res.ok).toBe(true);
});
it("accepts safe iMessage remoteHost", () => {
const res = validateConfigObject({
channels: {
imessage: {
remoteHost: "bot@gateway-host",
},
},
});
expect(res.ok).toBe(true);
});
it("rejects unsafe iMessage remoteHost", () => {
const res = validateConfigObject({
channels: {
imessage: {
remoteHost: "bot@gateway-host -oProxyCommand=whoami",
},
},
});
expect(res.ok).toBe(false);
if (!res.ok) {
expect(res.issues[0]?.path).toBe("channels.imessage.remoteHost");
}
});
});

View File

@@ -23,7 +23,7 @@ export type IMessageAccountConfig = {
cliPath?: string;
/** Optional Messages db path override. */
dbPath?: string;
/** Remote host for SCP when attachments live on a different machine (e.g., openclaw@192.168.64.3). */
/** Remote SSH host token for SCP attachment fetches (`host` or `user@host`). */
remoteHost?: string;
/** Optional default send service (imessage|sms|auto). */
service?: "imessage" | "sms" | "auto";

View File

@@ -1,4 +1,5 @@
import { z } from "zod";
import { isSafeScpRemoteHost } from "../infra/scp-host.js";
import {
normalizeTelegramCommandDescription,
normalizeTelegramCommandName,
@@ -804,7 +805,10 @@ export const IMessageAccountSchemaBase = z
configWrites: z.boolean().optional(),
cliPath: ExecutableTokenSchema.optional(),
dbPath: z.string().optional(),
remoteHost: z.string().optional(),
remoteHost: z
.string()
.refine(isSafeScpRemoteHost, "expected SSH host or user@host (no spaces/options)")
.optional(),
service: z.union([z.literal("imessage"), z.literal("sms"), z.literal("auto")]).optional(),
region: z.string().optional(),
dmPolicy: DmPolicySchema.optional().default("pairing"),