Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(mcp): reject sources_add path on remote transport (#3724)

Garry Tan8d5bdfe12517
diff --git a/src/core/operations.ts b/src/core/operations.ts
index edd708817c..d7e3f7cae7 100644
--- a/src/core/operations.ts
+++ b/src/core/operations.ts
@@ -4422,11 +4422,12 @@ const sources_add: Operation = {
const isLocal = ctx.remote === false;
const remotePath = isLocal ? (p.path as string | undefined) ?? null : null;
const remoteCloneDir = isLocal ? (p.clone_dir as string | undefined) : undefined;
- if (!isLocal && (p.path !== undefined || p.clone_dir !== undefined)) {
- ctx.logger.warn(
- '[sources_add] ignoring path/clone_dir overrides on HTTP MCP transport ' +
- '(remote callers can only register a remote --url; the clone path is ' +
- 'fixed under $GBRAIN_HOME/clones/).',
+ if (!isLocal && p.path !== undefined) {
+ throw new OperationError(
+ 'invalid_params',
+ 'sources_add: path is not honored over MCP (security confinement). ' +
+ 'Register with --url instead, or run `gbrain sources add --path ...` on the host CLI.',
+ 'Use --url to register a remote source, or run the command locally with --path.',
);
}
diff --git a/test/sources-mcp.test.ts b/test/sources-mcp.test.ts
index f042a3ae41..f894593583 100644
--- a/test/sources-mcp.test.ts
+++ b/test/sources-mcp.test.ts
@@ -281,19 +281,18 @@ describe('sources_add — remote callers ignore path/clone_dir overrides', () =>
});
});
- test('remote sources_admin: path override (without url) gets nulled', async () => {
+ test('remote sources_admin: path override (without url) is rejected with an error', async () => {
await withEnv({ GBRAIN_HOME, PATH: fakePath() }, async () => {
const op = findOp('sources_add');
const ctx = ctxRemote(['sources_admin']);
- // Without a URL and with a remote-supplied path, the path is dropped.
- // The op then has neither path nor url, which is fine — it creates a
- // pure DB-only source row (local_path=null).
- const row = (await op.handler(ctx, {
+ // Remote callers must not silently succeed when passing path — the call
+ // should fail so the client knows the source was NOT registered with a
+ // usable local_path. Silent success + null local_path means sync --all
+ // skips the source forever (#3645).
+ await expect(op.handler(ctx, {
id: 'attack-path',
path: '/etc',
- })) as any;
- // local_path was nulled — /etc is NOT registered as a source.
- expect(row.local_path).toBeNull();
+ })).rejects.toThrow(/path.*clone_dir.*not honored|confinement/i);
});
});