Skip to content

Commit ba080f9

Browse files
Jasmine ZhangJasmine Zhang
authored andcommitted
fix: refresh hooks token validation PR
1 parent 95f66a3 commit ba080f9

3 files changed

Lines changed: 31 additions & 1 deletion

File tree

src/config/config.hooks-module-paths.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,22 @@ describe("config hooks module paths", () => {
111111
"hooks.mappings.0.channel",
112112
);
113113
});
114+
115+
it("rejects hooks.enabled=true without hooks.token", () => {
116+
expectRejectedIssuePath(
117+
{
118+
agents: { list: [{ id: "openclaw" }] },
119+
hooks: { enabled: true },
120+
},
121+
"hooks.token",
122+
);
123+
});
124+
125+
it("accepts hooks.enabled=true when hooks.token is present", () => {
126+
const res = validateConfigObjectWithPlugins({
127+
agents: { list: [{ id: "openclaw" }] },
128+
hooks: { enabled: true, token: "secret" },
129+
});
130+
expect(res.ok).toBe(true);
131+
});
114132
});

src/config/validation.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,6 +1598,15 @@ function validateConfigObjectWithPluginsBase(
15981598
validateWebSearchProvider();
15991599
validateConfiguredModelRefs();
16001600

1601+
if (config.hooks?.enabled === true && !config.hooks?.token?.trim()) {
1602+
issues.push({
1603+
path: "hooks.token",
1604+
message:
1605+
"hooks.enabled is true but hooks.token is not set. " +
1606+
"Set hooks.token before enabling hooks (for example with `openclaw config set hooks.token <redacted>` or a redacted `openclaw gateway call config.patch --params ...`).",
1607+
});
1608+
}
1609+
16011610
if (!hasExplicitPluginsConfig) {
16021611
if (issues.length > 0) {
16031612
return { ok: false, issues, warnings };

src/gateway/hooks.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ export function resolveHooksConfig(cfg: OpenClawConfig): HooksConfigResolved | n
5252
}
5353
const token = normalizeOptionalString(cfg.hooks?.token);
5454
if (!token) {
55-
throw new Error("hooks.enabled requires hooks.token");
55+
throw new Error(
56+
"hooks.enabled requires hooks.token. " +
57+
"Set hooks.token before enabling hooks (for example with `openclaw config set hooks.token <redacted>` or a redacted `openclaw gateway call config.patch --params ...`).",
58+
);
5659
}
5760
const rawPath = normalizeOptionalString(cfg.hooks?.path) || DEFAULT_HOOKS_PATH;
5861
const withSlash = rawPath.startsWith("/") ? rawPath : `/${rawPath}`;

0 commit comments

Comments
 (0)