Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
peer_data: Ignore webhook bots in subscriber subset checks.
Sairam Bisoyi8757e81f8667
diff --git a/web/src/peer_data.ts b/web/src/peer_data.tsindex abad59ba9f5..9bc15213cdb 100644--- a/web/src/peer_data.ts+++ b/web/src/peer_data.ts@@ -2,6 +2,7 @@ import assert from "minimalistic-assert";import * as z from "zod/mini";import * as blueslip from "./blueslip.ts";+import {INCOMING_WEBHOOK_BOT_TYPE_INT} from "./bot_type_values.ts";import * as channel from "./channel.ts";import {LazySet} from "./lazy_set.ts";import {page_params} from "./page_params.ts";@@ -222,7 +223,26 @@ export async function is_subscriber_subset(return null;}- return [...sub1_set.keys()].every((key) => sub2_set.has(key));+ return [...sub1_set.keys()].every((key) => {+ // If the user is in the linked stream, the check passes.+ if (sub2_set.has(key)) {+ return true;+ }++ // Use ignore_missing=true because subscribers may include users+ // inaccessible to the current viewer (e.g., guest-visibility limits);+ // those will return undefined and fall through to the non-subset case.+ const user = people.maybe_get_user_by_id(key, true);++ // Incoming webhook bots are write-only and can't read messages, so a+ // private channel containing them as the only "extra" subscriber+ // doesn't expose anything.+ if (user?.bot_type === INCOMING_WEBHOOK_BOT_TYPE_INT) {+ return true;+ }++ return false;+ });}export function potential_subscribers(stream_id: number): User[] {diff --git a/web/tests/peer_data.test.cjs b/web/tests/peer_data.test.cjsindex 64787b75f76..d252b78dca6 100644--- a/web/tests/peer_data.test.cjs+++ b/web/tests/peer_data.test.cjs@@ -21,6 +21,7 @@ const {page_params} = require("./lib/zpage_params.cjs");const channel = mock_esm("../src/channel");+const {GENERIC_BOT_TYPE, INCOMING_WEBHOOK_BOT_TYPE_INT} = zrequire("bot_type_values");const peer_data = zrequire("peer_data");const people = zrequire("people");const {set_current_user, set_realm} = zrequire("state_data");@@ -529,6 +530,46 @@ test("is_subscriber_subset", async () => {);}+ // Create a mock Incoming Webhook bot+ const webhook_bot = make_bot({+ email: "[email protected]",+ full_name: "Webhook Bot",+ user_id: 105,+ bot_type: INCOMING_WEBHOOK_BOT_TYPE_INT,+ });+ people.add_active_user(webhook_bot);++ // Create a mock Generic Bot+ const generic_bot = make_bot({+ email: "[email protected]",+ full_name: "Generic Bot",+ user_id: 106,+ bot_type: GENERIC_BOT_TYPE,+ });+ people.add_active_user(generic_bot);++ const sub_with_webhook = make_sub(304, [1, 2, webhook_bot.user_id]);+ const sub_with_generic = make_sub(305, [1, 2, generic_bot.user_id]);+ const sub_with_unknown_user = make_sub(306, [1, 2, 9999]);++ // Webhooks should be ignored.+ assert.equal(+ await peer_data.is_subscriber_subset(sub_with_webhook.stream_id, sub_a.stream_id),+ true,+ );++ // Generic bots can read, so they are NOT ignored.+ assert.equal(+ await peer_data.is_subscriber_subset(sub_with_generic.stream_id, sub_a.stream_id),+ false,+ );++ // Unknown users are treated conservatively (not ignored).+ assert.equal(+ await peer_data.is_subscriber_subset(sub_with_unknown_user.stream_id, sub_a.stream_id),+ false,+ );+// Two untracked streams should never be passed into us.blueslip.expect("warn",