Skip to content

Commit 52ff472

Browse files
committed
fix(plugins): snapshot channel ingress authority once
1 parent b5c01c6 commit 52ff472

2 files changed

Lines changed: 29 additions & 6 deletions

File tree

‎src/plugins/registry-runtime.channel-ingress.test.ts‎

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,26 @@ describe("bundled channel ingress runtime ownership", () => {
185185
const retainedGuest = untrustedApi.runtime.agent.runCommandFromIngress;
186186
await expect(retainedGuest(guestOptions, commandRuntime)).resolves.toEqual({ payloads: [] });
187187
expect(command).toHaveBeenLastCalledWith(guestOptions, commandRuntime);
188+
let ownerClaimReads = 0;
189+
let channelReads = 0;
190+
const changingGuestOptions = {
191+
...guestOptions,
192+
get senderIsOwner() {
193+
return ownerClaimReads++ > 0;
194+
},
195+
get messageChannel() {
196+
return channelReads++ === 0 ? "community" : "discord";
197+
},
198+
};
199+
await expect(retainedGuest(changingGuestOptions, commandRuntime)).resolves.toEqual({
200+
payloads: [],
201+
});
202+
expect(command).toHaveBeenLastCalledWith(
203+
expect.objectContaining({ messageChannel: "community", senderIsOwner: false }),
204+
commandRuntime,
205+
);
206+
expect(ownerClaimReads).toBe(1);
207+
expect(channelReads).toBe(1);
188208
await expect(
189209
retainedGuest({ ...guestOptions, senderIsOwner: true }, commandRuntime),
190210
).rejects.toThrow('Plugin "impostor" cannot admit authenticated owner authority');
@@ -197,7 +217,7 @@ describe("bundled channel ingress runtime ownership", () => {
197217
await expect(retainedGuest(guestOptions, commandRuntime)).rejects.toThrow(
198218
'Plugin "impostor" cannot admit authenticated owner authority',
199219
);
200-
expect(command).toHaveBeenCalledTimes(2);
220+
expect(command).toHaveBeenCalledTimes(3);
201221
});
202222

203223
it("defers and preserves the exact active runtime across an inactive prepared load", async () => {

‎src/plugins/registry-runtime.ts‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -973,10 +973,14 @@ export function createPluginRuntimeResolver(state: PluginRegistryState) {
973973
params,
974974
commandRuntime,
975975
) => {
976+
const { senderIsOwner: claimedOwner, messageChannel, ...remainingParams } = params;
977+
const senderIsOwner = claimedOwner === true;
978+
// Validate and dispatch the same host-owned values; never re-read plugin-owned authority.
979+
const ingressParams = { ...remainingParams, senderIsOwner, messageChannel };
976980
if (
977981
!channelOwnerRecord ||
978982
// Community channels may admit guests; trusted provenance is required only for owner elevation.
979-
(params.senderIsOwner === true &&
983+
(senderIsOwner &&
980984
channelOwnerRecord.origin !== "bundled" &&
981985
channelOwnerRecord.trustedOfficialInstall !== true) ||
982986
pluginRuntimeRecordById.get(pluginId) !== channelOwnerRecord ||
@@ -986,16 +990,15 @@ export function createPluginRuntimeResolver(state: PluginRegistryState) {
986990
(record) => record === channelOwnerRecord && record.status === "loaded",
987991
) ||
988992
!registry.channels.some(
989-
(channel) =>
990-
channel.pluginId === pluginId && channel.plugin.id === params.messageChannel,
993+
(channel) => channel.pluginId === pluginId && channel.plugin.id === messageChannel,
991994
)
992995
) {
993996
throw new Error(
994-
`Plugin "${pluginId}" cannot admit authenticated owner authority for channel "${params.messageChannel ?? "unknown"}".`,
997+
`Plugin "${pluginId}" cannot admit authenticated owner authority for channel "${messageChannel ?? "unknown"}".`,
995998
);
996999
}
9971000
return await runWithPluginScope(() =>
998-
agent.runCommandFromIngress(params, commandRuntime),
1001+
agent.runCommandFromIngress(ingressParams, commandRuntime),
9991002
);
10001003
};
10011004
const scopedAgent = Object.create(

0 commit comments

Comments
 (0)