Skip to content

Commit ed16fc2

Browse files
matt2eclaude
andcommitted
fix(navigation): ignore unknown query parameters on Buzz links
Buzz links now drop any query parameter outside their grammar, values and repeats included, instead of failing as invalid-target: `message` keeps only channel, id and thread, the `channel` forms ignore the whole query, and the entity hosts keep only their per-type keys, so `commit` on a project and `tab` on a PR or issue are ignored too. A duplicated known key such as channel=a&channel=b is still ambiguous and rejects. This matches the original Buzz desktop client's lax message-link handling while staying strict on duplicated known keys. Credentials, port, fragment, the length cap, the lowercase scheme requirement and the OS-boundary refusal of buzz://open are unchanged. Everything rebuilt from a parsed link (entityHref, Copy link, the browser address) already emits the canonical form without the extra parameters. Co-Authored-By: Claude Fable 5.1 <[email protected]> Signed-off-by: Matt Toohey <[email protected]>
1 parent 5d2b08e commit ed16fc2

7 files changed

Lines changed: 182 additions & 23 deletions

File tree

‎docs/deep-links.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ The OS ingress accepts the Buzz link forms and nothing else:
2525
Entity sections are `files`, `commits`, `issues`, `prs`, `contributors`, and
2626
`channels`; omitting the section opens the overview. Repository commit links add
2727
`&tab=commits&commit=<40- or 64-hex hash>`. Identifiers use 1-64 ASCII letters,
28-
digits, `_`, `-`, or `.`, without a leading dot or `..`. Unknown or duplicate
29-
parameters are rejected. The same forms work in message content.
28+
digits, `_`, `-`, or `.`, without a leading dot or `..`. Query parameters outside
29+
a form's grammar are ignored, with their values and any repeats, so a link that
30+
another client decorated still opens; a duplicated known parameter is rejected as
31+
ambiguous. The `channel` forms carry everything in the path and ignore any query.
32+
The same forms work in message content.
3033

3134
None carries a community, so each binds to the currently selected community and
3235
viewer, and fail `unavailable` when no community is selected or no identity is

‎src/features/messages/message-link-parts.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,25 @@ it("recognizes bare and wrapped Buzz channel, message, thread and shared links",
1717
}
1818
}
1919
});
20+
it("keeps Buzz links with unknown query parameters as links rather than plain text", () => {
21+
const url = `buzz://message?channel=general&id=${"a".repeat(64)}&foo=bar`;
22+
for (const text of [url, `<${url}>`, `[Reply](${url})`]) {
23+
const parts = messageLinkParts(`See ${text}.`);
24+
expect(parts.filter((part) => part.url).map((part) => part.url)).toEqual([
25+
url,
26+
]);
27+
}
28+
expect(
29+
messageLinkParts("See buzz://channel/general?relay=evil.").filter(
30+
(part) => part.url,
31+
),
32+
).toEqual([
33+
{
34+
text: "buzz://channel/general?relay=evil",
35+
url: "buzz://channel/general?relay=evil",
36+
},
37+
]);
38+
});
2039
it("does not turn malformed Buzz addresses into links", () => {
2140
const content = "<buzz://message?channel=general&id=bad>";
2241
expect(messageLinkParts(content).some((part) => part.url)).toBe(false);

‎src/features/navigation/buzz-links.test.ts‎

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,74 @@ it("supports channels and leaves shared-link community ownership intact", () =>
7070
channelId: "general",
7171
});
7272
});
73+
it("ignores query parameters outside the Buzz link grammar, as the original desktop client does", () => {
74+
const thread = "b".repeat(64);
75+
const parsed = {
76+
format: "legacy",
77+
channelId: "c89a3185-29c5-40db-8284-054536d98b09",
78+
messageId:
79+
"9a77911a6e94147b1ce2cdb3c4e87046c67a29f29f3dd25626134621a5f6924b",
80+
};
81+
const withUnknown = `${example}&thread=${thread}&foo=bar`;
82+
expect(parseBuzzLink(withUnknown)).toEqual({
83+
...parsed,
84+
threadRootId: thread,
85+
});
86+
expect(buzzLinkKind(withUnknown)).toBe("thread");
87+
expect(
88+
deepLinkStep(withUnknown, {
89+
viewer: scope.viewer,
90+
selected: scope.communityOrigin,
91+
}),
92+
).toEqual({
93+
open: {
94+
version: 1,
95+
kind: "conversation",
96+
scope,
97+
channelId: parsed.channelId,
98+
messageId: parsed.messageId,
99+
threadRootId: thread,
100+
},
101+
});
102+
// Unknown keys are dropped with their values and repeats, wherever they sit.
103+
expect(parseBuzzLink(`${example}&foo=1&foo=2`)).toEqual(parsed);
104+
expect(parseBuzzLink(`${example}&viewer=${"b".repeat(64)}`)).toEqual(parsed);
105+
expect(
106+
parseBuzzLink(
107+
`buzz://message?foo=bar&channel=${parsed.channelId}&relay=evil&id=${parsed.messageId}`,
108+
),
109+
).toEqual(parsed);
110+
// The channel forms carry everything in the path and ignore any query.
111+
expect(parseBuzzLink("buzz://channel/general?relay=evil")).toEqual({
112+
format: "legacy",
113+
channelId: "general",
114+
});
115+
expect(parseBuzzLink(`buzz://channel/general/${thread}?foo=bar`)).toEqual({
116+
format: "legacy",
117+
channelId: "general",
118+
messageId: thread,
119+
});
120+
// A duplicated known key is ambiguous and still rejects.
121+
expect(
122+
parseBuzzLink(`buzz://message?channel=a&channel=b&id=${parsed.messageId}`),
123+
).toBeNull();
124+
expect(parseBuzzLink(`${example}&thread=${thread}&thread=${thread}`)).toBe(
125+
null,
126+
);
127+
});
73128
it.each([
74129
"buzz://channel/",
75130
"buzz://channel/general/extra",
76131
"buzz://channel/general/",
77132
`buzz://channel/general/${"a".repeat(64)}/extra`,
78133
`buzz://channel/general%2F${"a".repeat(64)}`,
79-
"buzz://channel/general?relay=evil",
80134
"buzz://channel/%2Fprivate",
81135
"buzz://channel/%ZZ",
82136
"buzz://user@channel/general",
83137
"buzz://channel:443/general",
84138
"buzz://message?channel=general&id=bad",
85139
`${example}&id=${"b".repeat(64)}`,
86140
`${example}&thread=bad`,
87-
`${example}&viewer=${"b".repeat(64)}`,
88141
`${example}#fragment`,
89142
"buzz://message/extra?channel=general",
90143
"buzz://join?relay=example",

‎src/features/navigation/buzz-links.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ export function parseBuzzLink(href: string): BuzzLink | null {
5151
if (entity) return { format: "entity", route: entity };
5252
const channelPattern = /^[a-zA-Z0-9][a-zA-Z0-9._-]{0,255}$/;
5353
const eventPattern = /^[a-f0-9]{64}$/i;
54-
if (url.hostname === "channel" && !url.search) {
54+
// Query parameters outside a form's grammar are ignored, values and repeats
55+
// included, as the original Buzz desktop client does. The channel forms carry
56+
// everything in the path, so any query is ignored there.
57+
if (url.hostname === "channel") {
5558
const parts = url.pathname.slice(1).split("/").map(decodeURIComponent);
5659
const [channelId = "", messageId] = parts;
5760
if (
@@ -67,10 +70,11 @@ export function parseBuzzLink(href: string): BuzzLink | null {
6770
};
6871
}
6972
if (url.hostname !== "message" || url.pathname) return null;
70-
const keys = [...url.searchParams.keys()];
73+
// A duplicated known key is ambiguous and still rejects.
7174
if (
72-
new Set(keys).size !== keys.length ||
73-
keys.some((key) => !["channel", "id", "thread"].includes(key))
75+
["channel", "id", "thread"].some(
76+
(key) => url.searchParams.getAll(key).length > 1,
77+
)
7478
)
7579
return null;
7680
const channelId = url.searchParams.get("channel") ?? "";

‎src/features/navigation/deep-links.test.ts‎

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,29 @@ it("binds message and channel links to the selected community and viewer", () =>
8484
},
8585
});
8686
});
87+
it("ignores query parameters outside the Buzz link grammar and opens the destination", () => {
88+
expect(deepLinkStep(`${messageLink}&foo=bar`, client)).toEqual({
89+
open: {
90+
version: 1,
91+
kind: "conversation",
92+
scope: { viewer, communityOrigin: origin },
93+
channelId: "general",
94+
messageId: message,
95+
threadRootId: root,
96+
},
97+
});
98+
expect(
99+
deepLinkStep(`${messageLink}&viewer=${"b".repeat(64)}`, client),
100+
).toEqual(deepLinkStep(messageLink, client));
101+
expect(deepLinkStep("buzz://channel/general?foo=bar", client)).toEqual({
102+
open: {
103+
version: 1,
104+
kind: "conversation",
105+
scope: { viewer, communityOrigin: origin },
106+
channelId: "general",
107+
},
108+
});
109+
});
87110
it("fails as unavailable without a selected community or identity, never inventing one", () => {
88111
expect(
89112
deepLinkStep("buzz://channel/general", { viewer, selected: null }),
@@ -125,9 +148,10 @@ it.each([
125148
"buzz",
126149
"buzz://user@channel/general",
127150
"buzz://channel:443/general",
128-
"buzz://channel/general?relay=evil",
129151
`${messageLink}#fragment`,
130-
`${messageLink}&viewer=${"b".repeat(64)}`,
152+
// Unknown keys are ignored, but a duplicated known key is ambiguous.
153+
`buzz://message?channel=general&channel=other&id=${message}`,
154+
`${messageLink}&id=${message}`,
131155
"buzz://message?channel=general&id=bad",
132156
"https://example.com/?next=buzz://channel/general",
133157
"javascript:alert(1)",
@@ -240,6 +264,32 @@ it("waits for loading to finish even for links that will fail, then reports them
240264
expect(t.log).toEqual(["fail:invalid-target"]);
241265
t.stop();
242266
});
267+
it("opens an OS message link carrying unknown query parameters as the bound conversation", async () => {
268+
const t = harness(ready);
269+
await settle();
270+
t.arrive(`${messageLink}&foo=bar&foo=baz`);
271+
await settle();
272+
expect(t.log).toEqual([
273+
`open:${JSON.stringify({
274+
version: 1,
275+
kind: "conversation",
276+
scope: { viewer, communityOrigin: origin },
277+
channelId: "general",
278+
messageId: message,
279+
threadRootId: root,
280+
})}`,
281+
]);
282+
expect(t.host.fail).not.toHaveBeenCalled();
283+
expect(t.host.navigation.snapshot().entry.target).toEqual({
284+
version: 1,
285+
kind: "conversation",
286+
scope: { viewer, communityOrigin: origin },
287+
channelId: "general",
288+
messageId: message,
289+
threadRootId: root,
290+
});
291+
t.stop();
292+
});
243293
it("opens the latest intent from a burst without presenting superseded destinations", async () => {
244294
const t = harness(ready);
245295
await settle();

‎src/features/projects/routes.test.ts‎

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,40 @@ describe("entity destinations", () => {
6767
`buzz://issue?id=${id}&owner=${owner}&d=repo`,
6868
);
6969
});
70+
it.each([
71+
[`repo?owner=${owner}&d=repo`, "relay=https://elsewhere.example"],
72+
[
73+
`repo?owner=${owner}&d=repo&tab=commits&commit=${"a".repeat(40)}`,
74+
"foo=bar&foo=baz",
75+
],
76+
// `commit` is outside the project grammar and `tab` outside the PR and
77+
// issue grammars, so they are ignored there rather than fatal.
78+
[`project?owner=${owner}&d=project`, `commit=${id}`],
79+
[`pr?id=${id}&owner=${owner}&d=repo`, "tab=prs"],
80+
[`issue?id=${id}&owner=${owner}&d=repo`, "foo=bar"],
81+
])(
82+
"ignores query parameters outside the entity grammar on %s: %s",
83+
(canonical, extra) => {
84+
const href = `buzz://${canonical}`;
85+
const parsed = parseBuzzLink(href);
86+
expect(parsed?.format).toBe("entity");
87+
const route = (parsed as { route: EntityRoute }).route;
88+
for (const lax of [
89+
`${href}&${extra}`,
90+
`buzz://${canonical.replace("?", `?${extra}&`)}`,
91+
]) {
92+
expect(parseBuzzLink(lax)).toEqual(parsed);
93+
expect(
94+
deepLinkStep(lax, {
95+
viewer: scope.viewer,
96+
selected: scope.communityOrigin,
97+
}),
98+
).toEqual({ open: entityTarget(route, scope) });
99+
}
100+
// Anything rebuilt from the parsed route is canonical again.
101+
expect(entityHref(route)).toBe(href);
102+
},
103+
);
70104
it.each([
71105
`repo?owner=${owner}`,
72106
`repo?owner=no&d=repo`,
@@ -77,10 +111,9 @@ describe("entity destinations", () => {
77111
`repo?owner=${owner}&d=repo&tab=files&commit=${id}`,
78112
`repo?owner=${owner}&d=repo&tab=commits&commit=short`,
79113
`repo?owner=${owner}&d=repo&owner=${owner}`,
80-
`repo?owner=${owner}&d=repo&relay=https://elsewhere.example`,
81-
`project?owner=${owner}&d=project&commit=${id}`,
114+
`repo?owner=${owner}&d=repo&tab=files&tab=commits`,
115+
`pr?id=${id}&id=${id}&owner=${owner}&d=repo`,
82116
`issue?owner=${owner}&d=repo`,
83-
`pr?id=${id}&owner=${owner}&d=repo&tab=prs`,
84117
`repo/path?owner=${owner}&d=repo`,
85118
`repo?owner=${owner}&d=repo#frag`,
86119
`user@repo?owner=${owner}&d=repo`,

‎src/features/projects/routes.ts‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,16 @@ export function parseEntityLink(url: URL): EntityRoute | null {
4040
!["repo", "project", "pr", "issue"].includes(type)
4141
)
4242
return null;
43+
// Query parameters outside the type's grammar are ignored, values and repeats
44+
// included, matching `parseBuzzLink`. A duplicated known key is ambiguous and
45+
// still rejects.
4346
const allowed =
4447
type === "repo"
4548
? ["owner", "d", "tab", "commit"]
4649
: type === "project"
4750
? ["owner", "d", "tab"]
4851
: ["owner", "d", "id"];
49-
const keys = [...url.searchParams.keys()];
50-
if (
51-
new Set(keys).size !== keys.length ||
52-
keys.some((key) => !allowed.includes(key))
53-
)
52+
if (allowed.some((key) => url.searchParams.getAll(key).length > 1))
5453
return null;
5554
const owner = url.searchParams.get("owner") ?? "";
5655
const dtag = url.searchParams.get("d") ?? "";
@@ -63,12 +62,10 @@ export function parseEntityLink(url: URL): EntityRoute | null {
6362
: null;
6463
}
6564
const tab = url.searchParams.get("tab");
66-
const commit = url.searchParams.get("commit");
65+
// `commit` belongs to the repo grammar only; on a project it is an unknown key.
66+
const commit = type === "repo" ? url.searchParams.get("commit") : null;
6767
if (tab !== null && !entityTabs.some((value) => value === tab)) return null;
68-
if (
69-
commit !== null &&
70-
(type !== "repo" || tab !== "commits" || !gitHash.test(commit))
71-
)
68+
if (commit !== null && (tab !== "commits" || !gitHash.test(commit)))
7269
return null;
7370
return {
7471
type: type as "repo" | "project",

0 commit comments

Comments
 (0)