Skip to content

Commit ab70717

Browse files
committed
fix(sessions): reject legacy peer overlap
1 parent 3223b3e commit ab70717

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

src/routing/session-key.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ describe("deriveSessionChatTypeFromKey", () => {
137137
{ key: "agent:main:discord:guild-123:channel-456", expected: "channel" },
138138
{ key: "agent:main:channel:legacy-room", expected: "channel" },
139139
{ key: "agent:main:channel:!room:example.org", expected: "channel" },
140+
{ key: "agent:main:channel:direct:user", expected: "channel" },
140141
{ key: "agent:main:group:room:part", expected: "group" },
142+
{ key: "agent:main:group:dm:user", expected: "group" },
141143
{ key: "agent:main:whatsapp:[email protected]", expected: "group" },
142144
{ key: "agent:main:telegram:dm:123456", expected: "direct" },
143145
{ key: "telegram:dm:123456", expected: "direct" },

src/sessions/send-policy.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ describe("resolveSendPolicy", () => {
117117
sessionKey: "agent:main:channel:!room:example.org",
118118
expected: "deny",
119119
},
120+
{
121+
name: "legacy channel keys overlapping canonical direct peers fail closed",
122+
cfg: cfgWithRules([{ action: "deny", match: { chatType: "channel" } }]),
123+
sessionKey: "agent:main:channel:direct:user",
124+
expected: "deny",
125+
},
120126
{
121127
name: "ambiguous account and peer-kind tokens fail closed",
122128
cfg: cfgWithRules([{ action: "deny", match: { chatType: "direct" } }]),

src/sessions/session-chat-type-shared.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,15 @@ export function hasAmbiguousCanonicalSessionPeerShape(scopedSessionKey: string):
2727
const hasAccountPeerShape = Boolean(
2828
parts[0] && parts[1] && isCanonicalPeerKind(parts[2]) && parts[3],
2929
);
30+
const hasBuiltInLegacyPeerShape =
31+
deriveBuiltInLegacySessionChatType(scopedSessionKey) !== undefined;
3032
return (
31-
[hasBareDirectPeerShape, hasChannelPeerShape, hasAccountPeerShape].filter(Boolean).length > 1
33+
[
34+
hasBareDirectPeerShape,
35+
hasChannelPeerShape,
36+
hasAccountPeerShape,
37+
hasBuiltInLegacyPeerShape,
38+
].filter(Boolean).length > 1
3239
);
3340
}
3441

0 commit comments

Comments
 (0)