Skip to content

Commit 26f89ec

Browse files
committed
fix: scope channel secret targets
1 parent ba39536 commit 26f89ec

2 files changed

Lines changed: 46 additions & 1 deletion

File tree

src/cli/command-secret-targets.import.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,29 @@ describe("command secret targets module import", () => {
4848
includeInConfigure: true,
4949
includeInAudit: true,
5050
},
51+
{
52+
id: "channels.telegram.gatewayToken",
53+
targetType: "gateway.auth.token",
54+
configFile: "openclaw.json",
55+
pathPattern: "gateway.auth.token",
56+
secretShape: "secret_input",
57+
expectedResolvedValue: "string",
58+
includeInPlan: true,
59+
includeInConfigure: true,
60+
includeInAudit: true,
61+
},
62+
{
63+
id: "channels.telegram.gatewayTokenRef",
64+
targetType: "channels.telegram.gatewayTokenRef",
65+
configFile: "openclaw.json",
66+
pathPattern: "channels.telegram.gatewayToken",
67+
refPathPattern: "gateway.auth.token",
68+
secretShape: "sibling_ref",
69+
expectedResolvedValue: "string",
70+
includeInPlan: true,
71+
includeInConfigure: true,
72+
includeInAudit: true,
73+
},
5174
],
5275
},
5376
},
@@ -67,6 +90,8 @@ describe("command secret targets module import", () => {
6790
});
6891

6992
expect(targets.has("channels.telegram.botToken")).toBe(true);
93+
expect(targets.has("channels.telegram.gatewayToken")).toBe(false);
94+
expect(targets.has("channels.telegram.gatewayTokenRef")).toBe(false);
7095
expect(targets.has("agents.defaults.memorySearch.remote.apiKey")).toBe(true);
7196
expect(listReadOnlyChannelPluginsForConfig).toHaveBeenCalledWith(
7297
expect.any(Object),

src/cli/command-secret-targets.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,26 @@ function getChannelSecretTargetIds(): string[] {
7474
return cachedChannelSecretTargetIds;
7575
}
7676

77+
function isScopedChannelSecretTargetEntry(params: {
78+
pluginId: string;
79+
entry: {
80+
id: string;
81+
configFile?: string;
82+
pathPattern?: string;
83+
refPathPattern?: string;
84+
};
85+
}): boolean {
86+
const allowedPrefix = `channels.${params.pluginId}.`;
87+
return (
88+
params.entry.id.startsWith(allowedPrefix) &&
89+
params.entry.configFile === "openclaw.json" &&
90+
typeof params.entry.pathPattern === "string" &&
91+
params.entry.pathPattern.startsWith(allowedPrefix) &&
92+
(params.entry.refPathPattern === undefined ||
93+
params.entry.refPathPattern.startsWith(allowedPrefix))
94+
);
95+
}
96+
7797
function getConfiguredChannelSecretTargetIds(
7898
config: OpenClawConfig,
7999
env: NodeJS.ProcessEnv = process.env,
@@ -84,7 +104,7 @@ function getConfiguredChannelSecretTargetIds(
84104
includePersistedAuthState: false,
85105
})) {
86106
for (const entry of plugin.secrets?.secretTargetRegistryEntries ?? []) {
87-
if (entry.id.startsWith(`channels.${plugin.id}.`)) {
107+
if (isScopedChannelSecretTargetEntry({ pluginId: plugin.id, entry })) {
88108
targetIds.add(entry.id);
89109
}
90110
}

0 commit comments

Comments
 (0)