Skip to content

Commit 8ae5178

Browse files
committed
fix(auto-reply): enforce canonical reset authorization
1 parent 0cad023 commit 8ae5178

2 files changed

Lines changed: 58 additions & 1 deletion

File tree

‎src/auto-reply/reply/reset-authorization.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export function isResetAuthorizedForContext(params: {
1010
commandAuthorized: boolean;
1111
}): boolean {
1212
const auth = resolveCommandAuthorization(params);
13-
if (!params.commandAuthorized && !auth.isAuthorizedSender) {
13+
if (!auth.isAuthorizedSender) {
1414
return false;
1515
}
1616
const provider = params.ctx.Provider;

‎src/auto-reply/reply/session.test.ts‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2752,6 +2752,63 @@ describe("initSessionState reset triggers in WhatsApp groups", () => {
27522752
} as OpenClawConfig;
27532753
}
27542754

2755+
it("requires canonical command authorization before rotating durable session state", async () => {
2756+
const sessionKey = "agent:main:whatsapp:group:owner-only-reset";
2757+
const storePath = await createStorePath("openclaw-group-reset-owner-only-");
2758+
const existingSessionId = "existing-owner-session";
2759+
await seedSessionStore({ storePath, sessionKey, sessionId: existingSessionId });
2760+
setActivePluginRegistry(
2761+
createTestRegistry([
2762+
{
2763+
pluginId: "whatsapp",
2764+
source: "test",
2765+
plugin: {
2766+
...createChannelTestPluginBase({ id: "whatsapp", label: "WhatsApp" }),
2767+
commands: { enforceOwnerForCommands: true },
2768+
},
2769+
},
2770+
]),
2771+
);
2772+
2773+
try {
2774+
const cfg = {
2775+
session: { store: storePath, idleMinutes: 999 },
2776+
channels: { whatsapp: { allowFrom: ["*"] } },
2777+
commands: { ownerAllowFrom: ["owner"] },
2778+
} as OpenClawConfig;
2779+
const baseContext = {
2780+
Body: "/new /model openai/gpt-5",
2781+
RawBody: "/new /model openai/gpt-5",
2782+
CommandBody: "/new /model openai/gpt-5",
2783+
2784+
To: "bot",
2785+
ChatType: "group",
2786+
SessionKey: sessionKey,
2787+
Provider: "whatsapp",
2788+
Surface: "whatsapp",
2789+
};
2790+
2791+
const denied = await initSessionState({
2792+
ctx: { ...baseContext, SenderId: "non-owner" },
2793+
cfg,
2794+
// Ingress admission alone must not bypass the channel's owner-only command policy.
2795+
commandAuthorized: true,
2796+
});
2797+
expect(denied.resetTriggered).toBe(false);
2798+
expect(denied.sessionId).toBe(existingSessionId);
2799+
2800+
const owner = await initSessionState({
2801+
ctx: { ...baseContext, SenderId: "owner" },
2802+
cfg,
2803+
commandAuthorized: true,
2804+
});
2805+
expect(owner.resetTriggered).toBe(true);
2806+
expect(owner.isNewSession).toBe(true);
2807+
} finally {
2808+
resetPluginRuntimeStateForTest();
2809+
}
2810+
});
2811+
27552812
it("applies WhatsApp group reset authorization across sender variants", async () => {
27562813
const sessionKey = "agent:main:whatsapp:group:[email protected]";
27572814
const existingSessionId = "existing-session-123";

0 commit comments

Comments
 (0)