Skip to content

Commit d561469

Browse files
feat(channels): grade sender identifier authentication in the ingress kernel (#123782)
* feat(channels): add identifier authentication kernel * fix(channels): preserve exact identity provenance * fix(channels): fail strict dynamic groups closed * fix(channels): bind plugin allowlists to exact identity fields Move the Twitch role normalizers into the kernel branch and keep Discord name and tag entries on their corresponding identity fields. Repair the same mismatch for Slack name slugs and IRC nick@host entries. Add regressions at the channel authorization boundaries. Related: #123782 Co-authored-by: Omar Shahine <[email protected]> * refactor(channels): resolve identifier authentication at intake Keep raw SDK inputs optional and carry required authentication through normalized kernel subjects, entries, and state. Resolve static claims at intake and floor omitted fields in a supplied per-message map to unverified. Remove the deprecated internal policy wrapper, downstream strength fallbacks, and unused type exports. Cover the partial-map floor, static claims, and mutable alias behavior, and document the map contract. Related: #123782 * fix(channels): retain affected admission contributions Preserve an authentication effect when other admission contributions were not evaluated. Prefer any affected result, then any evaluated result, before checking for uniformly unevaluated contributions. Cover the mixed case through the existing redacted receipt flow. Related: #123782 * test(twitch): await monitor delivery before resetting mocks Make the ingress fixture drain accepted deliveries on stop, matching the real monitor lifecycle. Await those deliveries directly so prefix and reply assertions cannot race or leak completions into the next case. Related: #123782 * fix(feishu): match ambiguous allow entries under both id fields --------- Co-authored-by: Omar Shahine <[email protected]> Co-authored-by: Peter Steinberger <[email protected]>
1 parent 698886c commit d561469

26 files changed

Lines changed: 1396 additions & 266 deletions

‎docs/plugins/sdk-channel-ingress.md‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,56 @@ The audit states are distinct:
126126
explicitly passes `channelIngress: "unsupported"`. Unsupported never means
127127
allowed and is not a shortcut for incomplete wiring.
128128

129+
## Identifier authentication
130+
131+
`IdentifierAuthentication` grades an identifier claim as `verified`,
132+
`asserted`, `unverified`, or `mutable`, strongest to weakest. It is an input to
133+
channel authorization only. It is not a principal, grant, relationship, or
134+
execution-identity assurance strength. In particular, an identifier claim of
135+
`verified` never becomes execution assurance `boundary-verified` or
136+
`cryptographic`.
137+
138+
The meanings are normative:
139+
140+
- `verified`: the owning trusted transport or session boundary bound this exact
141+
identifier to this sender.
142+
- `asserted`: a trusted boundary vouched for the sender without binding this
143+
exact identifier.
144+
- `unverified`: the identifier is exact and stable, but claimed ownership was
145+
not proved.
146+
- `mutable`: the identifier is a changeable or shared alias, such as a display
147+
name.
148+
149+
Declare `verified` only from transport or session metadata controlled by the
150+
owning boundary. Sender-controlled content, model input, ordinary message
151+
context, routing metadata, and the integrity of the host admission carrier do
152+
not establish it.
153+
154+
The kernel preserves the exact redacted allowlist-entry to subject-identifier
155+
pair that matched. It combines the entry and subject claims by taking the
156+
weaker claim for that exact pair, then compares it with
157+
`minIdentifierAuthentication`. Identifiers of the same kind remain distinct,
158+
so a weak secondary email does not weaken a separately matched verified email.
159+
160+
A subject that supplies a per-message `authentication` map must claim every
161+
field it wants counted. A field missing from a supplied map is treated as
162+
`unverified`, even if its identity descriptor declares a stronger static claim.
163+
Channels with static strength omit the map entirely.
164+
165+
Existing plugins remain source-compatible during the deprecation window:
166+
167+
| Deprecated field | Exact mapping |
168+
| -------------------------------------------------- | ------------------------------------ |
169+
| `dangerous: true` | `authentication: "mutable"` |
170+
| `dangerous: false` or omitted | default `authentication: "asserted"` |
171+
| `mutableIdentifierMatching: "enabled"` | minimum `mutable` |
172+
| `mutableIdentifierMatching: "disabled"` or omitted | default minimum `asserted` |
173+
174+
An explicit `authentication` or `minIdentifierAuthentication` takes
175+
precedence. The deprecated fields remain through the current Plugin SDK major
176+
and are planned for removal in the next major after bundled and known external
177+
plugins migrate.
178+
129179
## Access groups
130180

131181
`accessGroup:<name>` entries stay redacted. Core resolves static

‎extensions/discord/src/monitor/dm-command-auth.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,19 @@ describe("resolveDiscordDmCommandAccess", () => {
109109
expect(dmCommandAuthorized(result)).toBe(true);
110110
});
111111

112+
it("authorizes a matching Discord tag when name matching is enabled", async () => {
113+
const result = await resolveDiscordDmCommandAccess({
114+
accountId: "default",
115+
dmPolicy: "allowlist",
116+
configuredAllowFrom: ["alice#0001"],
117+
sender: { id: "999", name: "alice", tag: "alice#0001" },
118+
allowNameMatching: true,
119+
readStoreAllowFrom: async () => [],
120+
});
121+
122+
expect(result.senderAccess.allowed).toBe(true);
123+
});
124+
112125
it("blocks open DMs when configured allowlist does not match", async () => {
113126
const result = await resolveDiscordDmCommandAccess({
114127
accountId: "default",

‎extensions/discord/src/monitor/dm-command-auth.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function normalizeDiscordIdEntry(entry: string): string | null {
4141

4242
function normalizeDiscordNameEntry(entry: string): string | null {
4343
const text = entry.trim();
44-
if (!text || text === "*" || normalizeDiscordIdEntry(text)) {
44+
if (!text || text === "*" || normalizeDiscordIdEntry(text) || /#\d{4}$/.test(text)) {
4545
return null;
4646
}
4747
const nameSlug = normalizeDiscordAllowList([text], DISCORD_ALLOW_LIST_PREFIXES)
@@ -50,6 +50,11 @@ function normalizeDiscordNameEntry(entry: string): string | null {
5050
return typeof nameSlug === "string" && nameSlug ? nameSlug : null;
5151
}
5252

53+
function normalizeDiscordTagEntry(entry: string): string | null {
54+
const text = entry.trim();
55+
return /#\d{4}$/.test(text) ? normalizeDiscordNameSubject(text) : null;
56+
}
57+
5358
function normalizeDiscordNameSubject(value: string): string | null {
5459
const nameSlug = normalizeDiscordAllowList([value], DISCORD_ALLOW_LIST_PREFIXES)
5560
?.names.values()
@@ -66,7 +71,7 @@ const discordIngressIdentity = defineStableChannelIngressIdentity({
6671
aliases: (
6772
[
6873
["discordUserName", normalizeDiscordNameEntry],
69-
["discordUserTag", () => null],
74+
["discordUserTag", normalizeDiscordTagEntry],
7075
] as const
7176
).map(([key, normalizeEntry]) => ({
7277
key,

‎extensions/feishu/src/policy.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@ const feishuIngressIdentity = defineStableChannelIngressIdentity({
3030
sensitivity: "pii",
3131
aliases: [
3232
{
33+
// One configured entry is deliberately ambiguous between open_id and
34+
// user_id, so it normalizes under both same-kind fields and matches
35+
// whichever sender candidate carries the value under exact-field binding.
3336
key: "feishu-alt-id",
3437
kind: FEISHU_ID_KIND,
35-
normalizeEntry: () => null,
38+
normalizeEntry: normalizeFeishuAllowEntry,
3639
normalizeSubject: normalizeFeishuAllowEntry,
3740
sensitivity: "pii",
3841
},

‎extensions/irc/src/inbound.behavior.test.ts‎

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -433,35 +433,38 @@ describe("irc inbound behavior", () => {
433433
);
434434
});
435435

436-
it("admits a sender matching a full nick!user@host DM allowlist entry", async () => {
437-
const coreRuntime = createPluginRuntimeMock();
438-
const runtime = createRuntimeEnv();
439-
setIrcRuntime(coreRuntime as never);
436+
437+
"admits a sender matching the host-bound DM allowlist entry %s",
438+
async (entry) => {
439+
const coreRuntime = createPluginRuntimeMock();
440+
const runtime = createRuntimeEnv();
441+
setIrcRuntime(coreRuntime as never);
440442

441-
await handleIrcInbound({
442-
message: createMessage({
443-
target: "alice",
444-
senderNick: "alice",
445-
senderUser: "ident",
446-
senderHost: "example.com",
447-
text: "hello",
448-
}),
449-
account: createAccount({
450-
config: {
451-
dmPolicy: "allowlist",
452-
allowFrom: ["[email protected]"],
453-
groupPolicy: "allowlist",
454-
groupAllowFrom: [],
455-
},
456-
}),
457-
config: { channels: { irc: {} } } as CoreConfig,
458-
runtime,
459-
sendReply: vi.fn(async () => {}),
460-
});
443+
await handleIrcInbound({
444+
message: createMessage({
445+
target: "alice",
446+
senderNick: "alice",
447+
senderUser: "ident",
448+
senderHost: "example.com",
449+
text: "hello",
450+
}),
451+
account: createAccount({
452+
config: {
453+
dmPolicy: "allowlist",
454+
allowFrom: [entry],
455+
groupPolicy: "allowlist",
456+
groupAllowFrom: [],
457+
},
458+
}),
459+
config: { channels: { irc: {} } } as CoreConfig,
460+
runtime,
461+
sendReply: vi.fn(async () => {}),
462+
});
461463

462-
expect(
463-
(coreRuntime.channel.inbound.dispatchReply as unknown as { mock: { calls: unknown[][] } })
464-
.mock.calls.length,
465-
).toBe(1);
466-
});
464+
expect(
465+
(coreRuntime.channel.inbound.dispatchReply as unknown as { mock: { calls: unknown[][] } })
466+
.mock.calls.length,
467+
).toBe(1);
468+
},
469+
);
467470
});

‎extensions/irc/src/inbound.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const ircIngressIdentity = defineStableChannelIngressIdentity({
6161
{
6262
key: "irc-id-nick-host",
6363
kind: "stable-id" as const,
64-
normalizeEntry: () => null,
64+
normalizeEntry: normalizeIrcNickHostEntry,
6565
normalizeSubject: normalizeLowercaseStringOrEmpty,
6666
sensitivity: "pii" as const,
6767
},
@@ -116,12 +116,17 @@ function isHostlessNickUser(value: string): boolean {
116116

117117
function normalizeIrcStableEntry(value: string): string | null {
118118
const normalized = normalizeIrcAllowEntry(value);
119-
if (!normalized || normalized === "*" || !hasVerifiedHost(normalized)) {
119+
if (!normalized.includes("!") || !hasVerifiedHost(normalized)) {
120120
return null;
121121
}
122122
return normalized;
123123
}
124124

125+
function normalizeIrcNickHostEntry(value: string): string | null {
126+
const normalized = normalizeIrcAllowEntry(value);
127+
return !normalized.includes("!") && hasVerifiedHost(normalized) ? normalized : null;
128+
}
129+
125130
function normalizeIrcNickUserEntry(value: string): string | null {
126131
const normalized = normalizeIrcAllowEntry(value);
127132
if (!normalized || normalized === "*" || !isHostlessNickUser(normalized)) {

‎extensions/slack/src/monitor/auth.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,21 @@ describe("authorizeSlackSystemEventSender", () => {
511511
});
512512

513513
describe("resolveSlackCommandIngress", () => {
514+
it("matches a slugged allowlist entry against a spaced sender name", async () => {
515+
const result = await resolveSlackCommandIngress({
516+
ctx: makeAuthorizeCtx({ allowNameMatching: true }),
517+
senderId: "U123",
518+
senderName: "Alice Smith",
519+
channelId: "D123",
520+
channelType: "im",
521+
ownerAllowFromLower: ["alice-smith"],
522+
allowTextCommands: true,
523+
hasControlCommand: true,
524+
});
525+
526+
expect(result.commandAccess.authorized).toBe(true);
527+
});
528+
514529
it.each([
515530
["allows the workspace-qualified user in its workspace", "T11111111", "allow", true],
516531
["blocks the same bare user ID in another workspace", "T22222222", "block", false],

‎extensions/slack/src/monitor/auth.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ function normalizeSlackNameSlugEntry(entry: string): string | null {
116116
if (!name) {
117117
return null;
118118
}
119-
const slug = normalizeSlackSlug(name);
120-
return slug && slug !== name ? slug : null;
119+
return normalizeSlackSlug(name) || null;
121120
}
122121

123122
const slackIngressIdentity = defineStableChannelIngressIdentity({

‎extensions/twitch/src/access-control.ts‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ const twitchUserIdentity = defineStableChannelIngressIdentity({
3636
const twitchRoleIdentity = defineStableChannelIngressIdentity({
3737
key: "role-moderator",
3838
kind: "role",
39-
normalizeEntry: normalizeTwitchRole,
39+
normalizeEntry: normalizeTwitchModeratorRole,
4040
normalizeSubject: normalizeTwitchRole,
4141
aliases: ["owner", "vip", "subscriber"].map((role) => ({
4242
key: `role-${role}`,
4343
kind: "role",
44-
normalizeEntry: () => null,
44+
normalizeEntry: (value: string) => normalizeSpecificTwitchRole(value, role),
4545
normalizeSubject: normalizeTwitchRole,
4646
})),
4747
isWildcardEntry: (entry) => normalizeTwitchRole(entry) === "all",
@@ -184,6 +184,15 @@ function normalizeTwitchRole(value: string): string | null {
184184
: null;
185185
}
186186

187+
function normalizeTwitchModeratorRole(value: string): string | null {
188+
return normalizeSpecificTwitchRole(value, "moderator");
189+
}
190+
191+
function normalizeSpecificTwitchRole(value: string, expected: string): string | null {
192+
const role = normalizeTwitchRole(value);
193+
return role === expected ? role : null;
194+
}
195+
187196
function reasonForTwitchIngressDecision(decision: { reasonCode: IngressReasonCode }): string {
188197
switch (decision.reasonCode) {
189198
case "activation_skipped":

‎extensions/twitch/src/monitor.test.ts‎

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ const mocks = vi.hoisted(() => ({
1515
createIngress: vi.fn(),
1616
getClient: vi.fn(async () => ({})),
1717
getRuntime: vi.fn(),
18+
ingressAccept: vi.fn<(message: TwitchChatMessage) => Promise<void>>(),
1819
ingressStart: vi.fn(),
19-
ingressStop: vi.fn(async () => undefined),
20+
ingressStop: vi.fn<() => Promise<void>>(),
2021
onMessage: vi.fn(),
2122
runInbound: vi.fn(),
2223
sendMessage: vi.fn(),
@@ -80,19 +81,26 @@ describe("monitorTwitchProvider", () => {
8081
onAbandoned: () => Promise<void>;
8182
},
8283
) => Promise<void>;
83-
}) => ({
84-
accept: async (message: TwitchChatMessage) => {
84+
}) => {
85+
mocks.ingressAccept.mockImplementation(async (message: TwitchChatMessage) => {
8586
await options.deliver(message, {
8687
admission: "exclusive",
8788
abortSignal: new AbortController().signal,
8889
onAdopted: async () => undefined,
8990
onDeferred: () => undefined,
9091
onAbandoned: async () => undefined,
9192
});
92-
},
93-
start: mocks.ingressStart,
94-
stop: mocks.ingressStop,
95-
}),
93+
});
94+
// Real ingress stop drains accepted deliveries before the next monitor starts.
95+
mocks.ingressStop.mockImplementation(async () => {
96+
await Promise.all(mocks.ingressAccept.mock.results.map((result) => result.value));
97+
});
98+
return {
99+
accept: mocks.ingressAccept,
100+
start: mocks.ingressStart,
101+
stop: mocks.ingressStop,
102+
};
103+
},
96104
);
97105
mocks.getRuntime.mockReturnValue({
98106
logging: {
@@ -203,7 +211,9 @@ describe("monitorTwitchProvider", () => {
203211
message: "hello bot",
204212
channel: "testchannel",
205213
});
206-
await vi.waitFor(() => expect(mocks.sendMessage).toHaveBeenCalledOnce());
214+
expect(mocks.ingressAccept).toHaveBeenCalledOnce();
215+
await mocks.ingressAccept.mock.results[0]?.value;
216+
expect(mocks.sendMessage).toHaveBeenCalledOnce();
207217
expect(mocks.sendMessage).toHaveBeenCalledWith(
208218
account,
209219
"testchannel",
@@ -307,7 +317,9 @@ describe("monitorTwitchProvider", () => {
307317
channel: "testchannel",
308318
});
309319

310-
await vi.waitFor(() => expect(settled).toHaveBeenCalledOnce());
320+
expect(mocks.ingressAccept).toHaveBeenCalledOnce();
321+
await mocks.ingressAccept.mock.results[0]?.value;
322+
expect(settled).toHaveBeenCalledOnce();
311323
expect(settled).toHaveBeenCalledWith({ visibleReplySent: expectedVisible });
312324
if (expectedText) {
313325
expect(mocks.sendMessage).toHaveBeenCalledWith(

0 commit comments

Comments
 (0)