mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-07 07:11:06 +00:00
Require owner access for /allowlist writes (#59836)
* fix(allowlist): require owner access for writes * docs(changelog): note allowlist owner gate fix --------- Co-authored-by: Jacob Tomlinson <jtomlinson@nvidia.com>
This commit is contained in:
@@ -19,6 +19,7 @@ import {
|
||||
} from "../../routing/session-key.js";
|
||||
import { normalizeStringEntries } from "../../shared/string-normalization.js";
|
||||
import {
|
||||
rejectNonOwnerCommand,
|
||||
rejectUnauthorizedCommand,
|
||||
requireCommandFlagEnabled,
|
||||
requireGatewayClientScopeForInternalChannel,
|
||||
@@ -387,6 +388,11 @@ export const handleAllowlistCommand: CommandHandler = async (params, allowTextCo
|
||||
return { shouldContinue: false, reply: { text: lines.join("\n") } };
|
||||
}
|
||||
|
||||
const nonOwner = rejectNonOwnerCommand(params, "/allowlist");
|
||||
if (nonOwner) {
|
||||
return nonOwner;
|
||||
}
|
||||
|
||||
const missingAdminScope = requireGatewayClientScopeForInternalChannel(params, {
|
||||
label: "/allowlist write",
|
||||
allowedScopes: ["operator.admin"],
|
||||
|
||||
@@ -2011,6 +2011,7 @@ describe("handleCommands /allowlist", () => {
|
||||
commands: { text: true, config: true },
|
||||
channels: { telegram: { allowFrom: ["123"] } },
|
||||
} as OpenClawConfig);
|
||||
params.command.senderIsOwner = true;
|
||||
const result = await handleCommands(params);
|
||||
|
||||
expect(result.shouldContinue).toBe(false);
|
||||
@@ -2053,6 +2054,7 @@ describe("handleCommands /allowlist", () => {
|
||||
AccountId: "work",
|
||||
},
|
||||
);
|
||||
params.command.senderIsOwner = true;
|
||||
const result = await handleCommands(params);
|
||||
|
||||
expect(result.shouldContinue, "selected account scope").toBe(false);
|
||||
@@ -2092,6 +2094,7 @@ describe("handleCommands /allowlist", () => {
|
||||
Provider: "telegram",
|
||||
Surface: "telegram",
|
||||
});
|
||||
params.command.senderIsOwner = true;
|
||||
const result = await handleCommands(params);
|
||||
|
||||
expect(result.shouldContinue).toBe(false);
|
||||
@@ -2099,6 +2102,41 @@ describe("handleCommands /allowlist", () => {
|
||||
expect(writeConfigFileMock.mock.calls.length).toBe(previousWriteCount);
|
||||
});
|
||||
|
||||
it("blocks allowlist writes from authorized non-owner senders, including cross-channel targets", async () => {
|
||||
const cfg = {
|
||||
commands: {
|
||||
text: true,
|
||||
config: true,
|
||||
allowFrom: { telegram: ["*"] },
|
||||
ownerAllowFrom: ["discord:owner-discord-id"],
|
||||
},
|
||||
channels: {
|
||||
telegram: { allowFrom: ["*"], configWrites: true },
|
||||
discord: { allowFrom: ["owner-discord-id"], configWrites: true },
|
||||
},
|
||||
} as OpenClawConfig;
|
||||
const params = buildPolicyParams(
|
||||
"/allowlist add dm --channel discord attacker-discord-id",
|
||||
cfg,
|
||||
{
|
||||
Provider: "telegram",
|
||||
Surface: "telegram",
|
||||
SenderId: "telegram-attacker",
|
||||
From: "telegram-attacker",
|
||||
},
|
||||
);
|
||||
|
||||
expect(params.command.isAuthorizedSender).toBe(true);
|
||||
expect(params.command.senderIsOwner).toBe(false);
|
||||
|
||||
const result = await handleCommands(params);
|
||||
|
||||
expect(result.shouldContinue).toBe(false);
|
||||
expect(result.reply).toBeUndefined();
|
||||
expect(writeConfigFileMock).not.toHaveBeenCalled();
|
||||
expect(addChannelAllowFromStoreEntryMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("removes default-account entries from scoped and legacy pairing stores", async () => {
|
||||
removeChannelAllowFromStoreEntryMock
|
||||
.mockResolvedValueOnce({
|
||||
@@ -2115,6 +2153,7 @@ describe("handleCommands /allowlist", () => {
|
||||
channels: { telegram: { allowFrom: ["123"] } },
|
||||
} as OpenClawConfig;
|
||||
const params = buildPolicyParams("/allowlist remove dm --store 789", cfg);
|
||||
params.command.senderIsOwner = true;
|
||||
const result = await handleCommands(params);
|
||||
|
||||
expect(result.shouldContinue).toBe(false);
|
||||
@@ -2137,6 +2176,7 @@ describe("handleCommands /allowlist", () => {
|
||||
channels: { telegram: { allowFrom: ["123"] } },
|
||||
} as OpenClawConfig;
|
||||
const params = buildPolicyParams("/allowlist add dm --account __proto__ 789", cfg);
|
||||
params.command.senderIsOwner = true;
|
||||
const result = await handleCommands(params);
|
||||
|
||||
expect(result.shouldContinue).toBe(false);
|
||||
@@ -2196,6 +2236,7 @@ describe("handleCommands /allowlist", () => {
|
||||
Provider: testCase.provider,
|
||||
Surface: testCase.provider,
|
||||
});
|
||||
params.command.senderIsOwner = true;
|
||||
const result = await handleCommands(params);
|
||||
|
||||
expect(result.shouldContinue).toBe(false);
|
||||
|
||||
Reference in New Issue
Block a user