Skip to content

Commit 02772b0

Browse files
steipetecoygeek
andcommitted
fix(security): require sender-only matching for elevated allowFrom
Co-authored-by: coygeek <[email protected]>
1 parent 51b0772 commit 02772b0

File tree

3 files changed

+59
-2
lines changed

3 files changed

+59
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Docs: https://docs.openclaw.ai
3737
- Sandbox/Media: map container workspace paths (`/workspace/...` and `file:///workspace/...`) back to the host sandbox root for outbound media validation, preventing false deny errors for sandbox-generated local media. (#23083) Thanks @echo931.
3838
- Sandbox/Docker: apply custom bind mounts after workspace mounts and prioritize bind-source resolution on overlapping paths, so explicit workspace binds are no longer ignored. (#22669) Thanks @tasaankaeris.
3939
- Exec approvals/Forwarding: restore Discord text forwarding when component approvals are not configured, and carry request snapshots through resolve events so resolved notices still forward after cache misses/restarts. (#22988) Thanks @bubmiller.
40+
- Security/Elevated: match `tools.elevated.allowFrom` against sender identities only (not recipient `ctx.To`), closing a recipient-token bypass for `/elevated` authorization. (#11022) Thanks @coygeek.
4041
- Config/Memory: allow `"mistral"` in `agents.defaults.memorySearch.provider` and `agents.defaults.memorySearch.fallback` schema validation. (#14934) Thanks @ThomsenDrake.
4142
- Security/Feishu: enforce ID-only allowlist matching for DM/group sender authorization, normalize Feishu ID prefixes during checks, and ignore mutable display names so display-name collisions cannot satisfy allowlist entries. This ships in the next npm release. Thanks @jiseoung for reporting.
4243
- Feishu/Commands: in group chats, command authorization now falls back to top-level `channels.feishu.allowFrom` when per-group `allowFrom` is not set, so `/command` no longer gets blocked by an unintended empty allowlist. (#23756)
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { describe, expect, it } from "vitest";
2+
import type { OpenClawConfig } from "../../config/config.js";
3+
import type { MsgContext } from "../templating.js";
4+
import { resolveElevatedPermissions } from "./reply-elevated.js";
5+
6+
function buildConfig(allowFrom: string[]): OpenClawConfig {
7+
return {
8+
tools: {
9+
elevated: {
10+
allowFrom: {
11+
whatsapp: allowFrom,
12+
},
13+
},
14+
},
15+
} as OpenClawConfig;
16+
}
17+
18+
function buildContext(overrides?: Partial<MsgContext>): MsgContext {
19+
return {
20+
Provider: "whatsapp",
21+
Surface: "whatsapp",
22+
From: "whatsapp:+15550001111",
23+
SenderE164: "+15550001111",
24+
To: "+15559990000",
25+
...overrides,
26+
} as MsgContext;
27+
}
28+
29+
describe("resolveElevatedPermissions", () => {
30+
it("authorizes when sender matches allowFrom", () => {
31+
const result = resolveElevatedPermissions({
32+
cfg: buildConfig(["+15550001111"]),
33+
agentId: "main",
34+
provider: "whatsapp",
35+
ctx: buildContext(),
36+
});
37+
38+
expect(result.enabled).toBe(true);
39+
expect(result.allowed).toBe(true);
40+
expect(result.failures).toHaveLength(0);
41+
});
42+
43+
it("does not authorize when only recipient matches allowFrom", () => {
44+
const result = resolveElevatedPermissions({
45+
cfg: buildConfig(["+15559990000"]),
46+
agentId: "main",
47+
provider: "whatsapp",
48+
ctx: buildContext(),
49+
});
50+
51+
expect(result.enabled).toBe(true);
52+
expect(result.allowed).toBe(false);
53+
expect(result.failures).toContainEqual({
54+
gate: "allowFrom",
55+
key: "tools.elevated.allowFrom.whatsapp",
56+
});
57+
});
58+
});

src/auto-reply/reply/reply-elevated.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,6 @@ function isApprovedElevatedSender(params: {
9797
addToken(params.ctx.SenderE164);
9898
addToken(params.ctx.From);
9999
addToken(stripSenderPrefix(params.ctx.From));
100-
addToken(params.ctx.To);
101-
addToken(stripSenderPrefix(params.ctx.To));
102100

103101
for (const rawEntry of allowTokens) {
104102
const entry = rawEntry.trim();

0 commit comments

Comments
 (0)