Skip to content

Commit 5e2cf7a

Browse files
Haytwpfleger96
andcommitted
fix(desktop): gate canonical message-link authored labels
resolveMessageLinkRenderTarget's authored-label branch returned a bare interactive link for buzz://message?channel=&id= URLs, so a custom label could open a private destination that the bare-URL pill renders inert. Route both parser families through one shared AuthoredDeepLinkAnchor that applies the bounded per-id resolution + openable gate, preserving the display text. Co-authored-by: Will Pfleger <[email protected]> Signed-off-by: Will Pfleger <[email protected]>
1 parent 050fa14 commit 5e2cf7a

3 files changed

Lines changed: 96 additions & 54 deletions

File tree

‎desktop/src/features/channels/openChannelDirectoryResolver.test.mjs‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -545,17 +545,27 @@ test("markdown message links resolve private destinations without a directory sc
545545
});
546546

547547
test("authored-label channel and message links respect the private-destination gate", async () => {
548-
// buzz://channel/<uuid> and buzz://channel/<uuid>/<event-id> with an authored
549-
// label both go through ChannelDeepLinkAnchor. The authored-label branch must
550-
// route through the same bounded detail lookup + openable gate as the pill
551-
// paths — a private channel must render inert regardless of the display text.
548+
// Authored-label deep links must route through the same bounded detail
549+
// lookup + openable gate as the pill paths, regardless of parser family:
550+
// - buzz://channel/<uuid> and buzz://channel/<uuid>/<event-id> reach the
551+
// gate via ChannelDeepLinkAnchor's authored branch, and
552+
// - the canonical buzz://message?channel=&id= form (produced by
553+
// buildMessageLink) reaches it via resolveMessageLinkRenderTarget's
554+
// "label" branch.
555+
// A private channel must render inert on every route regardless of the
556+
// display text.
552557
const channelId = "aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa";
553558
const messageId = "b".repeat(64);
554559
const channelLink = `buzz://channel/${channelId}`;
555-
const messageLinkUrl = `buzz://channel/${channelId}/${messageId}`;
560+
const channelMessageLink = `buzz://channel/${channelId}/${messageId}`;
561+
const canonicalMessageLink = `buzz://message?channel=${channelId}&id=${messageId}`;
556562
const renderPaths = [
557563
["channel variant", `[private channel](${channelLink})`],
558-
["message variant", `[private message](${messageLinkUrl})`],
564+
[
565+
"channel-path message variant",
566+
`[private message](${channelMessageLink})`,
567+
],
568+
["canonical message variant", `[private message](${canonicalMessageLink})`],
559569
];
560570

561571
for (const [path, content] of renderPaths) {

‎desktop/src/shared/ui/markdown.tsx‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ import {
6262
import { ExternalLinkAnchor } from "./markdown/ExternalLinkAnchor";
6363
import { FileCard } from "./markdown/FileCard";
6464
import {
65+
AuthoredDeepLinkAnchor,
6566
ChannelDeepLinkAnchor,
6667
MarkdownChannelDeepLink,
6768
MarkdownChannelReference,
@@ -117,7 +118,6 @@ import {
117118
} from "./markdown/imageLightbox";
118119
import { MarkdownTable } from "./markdown/MarkdownTable";
119120
import { ProgressiveImage } from "./markdown/ProgressiveImage";
120-
import { BuzzInlineLink } from "./markdown/BuzzLinkChip";
121121
import { MessageLinkPill } from "./markdown/MessageLinkPill";
122122
import { renderCachedMarkdown } from "./markdown/nodeCache";
123123
import { useMessageLinkPreviews } from "./markdown/useMessageLinkPreviews";
@@ -1364,17 +1364,17 @@ export function createMarkdownComponents(
13641364
}
13651365

13661366
return (
1367-
<BuzzInlineLink
1368-
title={href}
1367+
<AuthoredDeepLinkAnchor
1368+
channelId={messageLinkTarget.link.channelId}
1369+
href={href}
13691370
interactive={interactive}
1370-
onOpenLink={() => onOpenMessageLink(messageLinkTarget.link)}
1371+
messageLink={messageLinkTarget.link}
13711372
>
13721373
{children}
1373-
</BuzzInlineLink>
1374+
</AuthoredDeepLinkAnchor>
13741375
);
13751376
}
1376-
// Malformed message deep link — fall through to the default
1377-
// anchor (renders as a normal external link).
1377+
// Malformed message deep link — fall through to the default anchor.
13781378
}
13791379

13801380
// `buzz://pr|issue|repo?…` entity links navigate in-app; malformed ones

‎desktop/src/shared/ui/markdown/ChannelDeepLink.tsx‎

Lines changed: 73 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
buildChannelLink,
1010
parseChannelLink,
1111
} from "@/features/messages/lib/channelLink";
12+
import type { ParsedMessageLink } from "@/features/messages/lib/messageLink";
1213
import type { Channel } from "@/shared/api/types";
1314

1415
import { BuzzInlineLink, BuzzLinkChip } from "./BuzzLinkChip";
@@ -68,22 +69,16 @@ function ResolvedChannelPermalinkChip(props: ChannelPermalinkChipProps) {
6869
);
6970
}
7071

72+
type AuthoredMessageLink = ParsedMessageLink;
73+
7174
type AuthoredDeepLinkProps = {
7275
channelId: string;
7376
children: React.ReactNode;
7477
href: string;
7578
interactive: boolean;
76-
messageLink: {
77-
channelId: string;
78-
messageId: string;
79-
threadRootId: null;
80-
} | null;
79+
messageLink: AuthoredMessageLink | null;
8180
onOpenChannel: (channelId: string) => void;
82-
onOpenMessageLink: (link: {
83-
channelId: string;
84-
messageId: string;
85-
threadRootId: null;
86-
}) => void;
81+
onOpenMessageLink: (link: AuthoredMessageLink) => void;
8782
};
8883

8984
function ResolvedAuthoredDeepLink({
@@ -120,6 +115,71 @@ function ResolvedAuthoredDeepLink({
120115
);
121116
}
122117

118+
/**
119+
* Renders an intentionally-labeled `buzz://channel|message` deep link through
120+
* the shared visibility gate. Known channels are interactive immediately;
121+
* unknown ids without a runtime resolver stay inert; otherwise a bounded
122+
* per-id lookup decides openability. Both parser families
123+
* (`buzz://channel/...` and `buzz://message?...`) share this decision so a
124+
* private destination can never render clickable via a custom label.
125+
*/
126+
export function AuthoredDeepLinkAnchor({
127+
channelId,
128+
children,
129+
href,
130+
interactive,
131+
messageLink,
132+
}: {
133+
channelId: string;
134+
children: React.ReactNode;
135+
href: string;
136+
interactive: boolean;
137+
messageLink: AuthoredMessageLink | null;
138+
}) {
139+
const {
140+
channels,
141+
onOpenChannel,
142+
onOpenMessageLink,
143+
resolveChannelReferences,
144+
} = useMarkdownRuntime();
145+
const openLink = () =>
146+
messageLink ? onOpenMessageLink(messageLink) : onOpenChannel(channelId);
147+
const label = getReactNodeText(children);
148+
const knownChannel = channels?.find((c) => c.id === channelId);
149+
if (knownChannel) {
150+
return (
151+
<BuzzInlineLink
152+
href={href}
153+
title={href}
154+
aria-label={`${messageLink ? "Open message" : "Open channel"}: ${label}`}
155+
interactive={interactive}
156+
onOpenLink={openLink}
157+
>
158+
{children}
159+
</BuzzInlineLink>
160+
);
161+
}
162+
if (!resolveChannelReferences) {
163+
return (
164+
<span className="font-medium text-current" data-buzz-link={href}>
165+
{children}
166+
</span>
167+
);
168+
}
169+
return (
170+
<ResolvedAuthoredDeepLink
171+
channelId={channelId}
172+
href={href}
173+
interactive={interactive}
174+
messageLink={messageLink}
175+
onOpenChannel={onOpenChannel}
176+
onOpenMessageLink={onOpenMessageLink}
177+
>
178+
{children}
179+
</ResolvedAuthoredDeepLink>
180+
);
181+
}
182+
123183
/**
124184
* A permalink labels from its synchronous member list first. Only production
125185
* markdown requests the bounded detail lookup for an unknown id; static
@@ -161,45 +221,17 @@ export function ChannelDeepLinkAnchor({
161221
threadRootId: null,
162222
}
163223
: null;
164-
const openLink = () =>
165-
messageLink
166-
? onOpenMessageLink(messageLink)
167-
: onOpenChannel(parsed.value.channelId);
168224
const authoredLabel = getReactNodeText(children);
169225
if (authoredLabel !== href) {
170-
const { channelId } = parsed.value;
171-
const knownChannel = channels?.find((c) => c.id === channelId);
172-
if (knownChannel) {
173-
return (
174-
<BuzzInlineLink
175-
href={href}
176-
title={href}
177-
aria-label={`${messageLink ? "Open message" : "Open channel"}: ${authoredLabel}`}
178-
interactive={interactive}
179-
onOpenLink={openLink}
180-
>
181-
{children}
182-
</BuzzInlineLink>
183-
);
184-
}
185-
if (!resolveChannelReferences) {
186-
return (
187-
<span className="font-medium text-current" data-buzz-link={href}>
188-
{children}
189-
</span>
190-
);
191-
}
192226
return (
193-
<ResolvedAuthoredDeepLink
194-
channelId={channelId}
227+
<AuthoredDeepLinkAnchor
228+
channelId={parsed.value.channelId}
195229
href={href}
196230
interactive={interactive}
197231
messageLink={messageLink}
198-
onOpenChannel={onOpenChannel}
199-
onOpenMessageLink={onOpenMessageLink}
200232
>
201233
{children}
202-
</ResolvedAuthoredDeepLink>
234+
</AuthoredDeepLinkAnchor>
203235
);
204236
}
205237
if (messageLink) {

0 commit comments

Comments
 (0)