Skip to content

Commit 00ca77b

Browse files
omarshahineclaude
andcommitted
fix(channels): keep newly-optional auth state fields backward-compatible
Autoreview flagged that two optional fields on the public `ChannelIngressState` were treated as mandatory by authorization, so a caller constructing state directly without them would hit silent ingress denials. - allowlist.ts: only downgrade a wildcard to `mutable` when the subject's carried identifier kinds are actually known. An absent `subjectIdentifierKinds` no longer weakens the entry, consistent with the "an absent claim does not weaken" rule directly below it. The resolver always supplies the kinds, so the missing-identity downgrade still holds on the real ingress path. - decision.ts: a matched origin subject that omits its strength defaults to the baseline `asserted` (now a shared export) instead of being dropped, so the minimum is applied uniformly rather than failing a matched legacy state. Compat regression tests for both in identifier-authentication.test.ts. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01WxM7Yy33nFJM71NCaBqhyz
1 parent 0b99df3 commit 00ca77b

4 files changed

Lines changed: 86 additions & 7 deletions

File tree

‎src/channels/message-access/allowlist.ts‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,19 @@ function mergeResolvedAllowlists(
102102
function effectiveEntryAuthentication(params: {
103103
entry: ResolvedIngressAllowlist["normalizedEntries"][number];
104104
subjectAuthentication: SubjectIdentifierAuthentication;
105-
subjectIdentifierKinds: ReadonlySet<string>;
105+
subjectIdentifierKinds: ReadonlySet<string> | undefined;
106106
}): IdentifierAuthentication {
107107
const entry = identifierAuthenticationFrom(params.entry);
108108
// A wildcard is normalized against one identity field. It cannot borrow that field's
109-
// strength when the inbound subject did not carry the field at all.
110-
if (params.entry.wildcard && !params.subjectIdentifierKinds.has(params.entry.kind)) {
109+
// strength when the inbound subject did not carry the field at all. Only downgrade when the
110+
// subject's carried kinds are actually known: an absent set is a caller that made no claim,
111+
// and, exactly like an absent per-message authentication below, must not weaken the entry.
112+
// The resolver always populates it, so this preserves the check on the real ingress path.
113+
if (
114+
params.entry.wildcard &&
115+
params.subjectIdentifierKinds &&
116+
!params.subjectIdentifierKinds.has(params.entry.kind)
117+
) {
111118
return "mutable";
112119
}
113120
const subject = params.subjectAuthentication[params.entry.kind];
@@ -130,7 +137,12 @@ export function applyIdentifierAuthenticationPolicy(params: {
130137
}): ResolvedIngressAllowlist {
131138
const minimum = minimumIdentifierAuthenticationFrom(params.policy);
132139
const subjectAuthentication = params.subjectAuthentication ?? {};
133-
const subjectIdentifierKinds = new Set(params.subjectIdentifierKinds ?? []);
140+
// Undefined, not an empty set, when the caller omitted it: an empty set would read as "the
141+
// subject carried no kinds" and wrongly downgrade every wildcard. The resolver always
142+
// supplies the real kinds; a hand-built state that omits them keeps the pre-policy behavior.
143+
const subjectIdentifierKinds = params.subjectIdentifierKinds
144+
? new Set(params.subjectIdentifierKinds)
145+
: undefined;
134146
const { allowlist } = params;
135147
const rejected = allowlist.normalizedEntries.filter(
136148
(entry) =>

‎src/channels/message-access/decision.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
} from "../mention-gating.js";
1212
import { applyIdentifierAuthenticationPolicy, redactedAllowlistDiagnostics } from "./allowlist.js";
1313
import {
14+
DEFAULT_IDENTIFIER_AUTHENTICATION,
1415
meetsIdentifierAuthentication,
1516
minimumIdentifierAuthenticationFrom,
1617
} from "./identifier-authentication.js";
@@ -188,10 +189,14 @@ function eventGate(params: {
188189
if (!params.state.event.hasOriginSubject) {
189190
return eventResult(false, "origin_subject_missing");
190191
}
191-
const authentication = params.state.event.originSubjectAuthentication;
192+
// The resolver reports the matched origin identity's strength alongside the match. A
193+
// hand-built state may set `originSubjectMatched` without a strength; treat that as the
194+
// baseline `asserted` rather than a failed match, so the minimum is applied uniformly
195+
// instead of silently dropping a matched legacy state.
196+
const authentication =
197+
params.state.event.originSubjectAuthentication ?? DEFAULT_IDENTIFIER_AUTHENTICATION;
192198
const matched =
193199
params.state.event.originSubjectMatched &&
194-
authentication != null &&
195200
meetsIdentifierAuthentication(
196201
authentication,
197202
minimumIdentifierAuthenticationFrom(params.policy),

‎src/channels/message-access/identifier-authentication.test.ts‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,45 @@ describe("per-message subject claims", () => {
332332
}),
333333
).toMatchObject({ admission: "drop" });
334334
});
335+
336+
it("keeps a wildcard authenticated when the subject's carried kinds are unknown", async () => {
337+
// A hand-built ChannelIngressState that omits subjectIdentifierKinds must not silently
338+
// downgrade every wildcard to mutable. The resolver always supplies the kinds, so the
339+
// security downgrade above still holds on the real path; a legacy direct constructor keeps
340+
// the pre-policy behavior, matching the "an absent claim does not weaken" rule.
341+
const wildcardAdapter: InternalChannelIngressAdapter = {
342+
...adapter,
343+
normalizeEntries({ entries }) {
344+
return {
345+
matchable: entries.map((entry, index) => ({
346+
opaqueEntryId: `entry-${index + 1}`,
347+
kind: "email" as const,
348+
value: entry,
349+
wildcard: true,
350+
})),
351+
invalid: [],
352+
disabled: [],
353+
};
354+
},
355+
};
356+
const state = await resolveChannelIngressState({
357+
...input(),
358+
adapter: wildcardAdapter,
359+
subject: {
360+
identifiers: [
361+
{
362+
opaqueId: "alias",
363+
kind: "username",
364+
value: "name:Stranger",
365+
authentication: "unverified",
366+
},
367+
],
368+
},
369+
allowlists: { dm: ["*"] },
370+
});
371+
const legacy = { ...state, subjectIdentifierKinds: undefined };
372+
expect(decideChannelIngress(legacy, allowlistPolicy)).toMatchObject({ admission: "dispatch" });
373+
});
335374
});
336375

337376
describe("raising the minimum", () => {
@@ -477,6 +516,29 @@ describe("origin-subject authorization", () => {
477516
admission: "dispatch",
478517
});
479518
});
519+
520+
it("admits a matched origin subject that omits its strength, at the baseline", async () => {
521+
// A hand-built state may set originSubjectMatched without a strength. That is treated as
522+
// the baseline asserted, which clears the default minimum, rather than silently dropped.
523+
const verified = subject({
524+
address: "[email protected]",
525+
addressAuthentication: "verified",
526+
});
527+
const state = await resolveChannelIngressState(
528+
input({
529+
subject: verified,
530+
allowlists: { dm: ["[email protected]"] },
531+
event: {
532+
kind: "reaction",
533+
authMode: "origin-subject",
534+
mayPair: false,
535+
originSubject: verified,
536+
},
537+
}),
538+
);
539+
const legacy = { ...state, event: { ...state.event, originSubjectAuthentication: undefined } };
540+
expect(decideChannelIngress(legacy, allowlistPolicy)).toMatchObject({ admission: "dispatch" });
541+
});
480542
});
481543

482544
describe("redaction", () => {

‎src/channels/message-access/identifier-authentication.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const RANK: Record<IdentifierAuthentication, number> = {
4343
* has not earned the strongest claim. It is also the shipped minimum, so silence keeps
4444
* today's behavior instead of quietly failing closed on every existing channel.
4545
*/
46-
const DEFAULT_IDENTIFIER_AUTHENTICATION: IdentifierAuthentication = "asserted";
46+
export const DEFAULT_IDENTIFIER_AUTHENTICATION: IdentifierAuthentication = "asserted";
4747

4848
/** Returns true when `actual` meets or exceeds `minimum`. */
4949
export function meetsIdentifierAuthentication(

0 commit comments

Comments
 (0)