Skip to content

Commit 93140fa

Browse files
matt2eclaude
andcommitted
fix(desktop): ignore deep-link policy receipts for native invite consent
Anyone holding an invite code can mint a join-policy receipt from the public accept-policy endpoint, so a receipt carried by a buzz://join link does not prove this app showed consent. Desktop persisted that receipt into the onboarding transaction (and kept a retained same-relay receipt on resume), which made useClaimInvite skip policy discovery and claim without the native consent stage. startCommunityOnboarding now drops receipts for deep-link-join transactions, both when creating one and when resuming a same-relay transaction, so the invite-consent stage is the only source of the receipt a link join claims with. The deep-link drain no longer forwards the link's receipt. The useClaimInvite jsdom table gains rows for a link-supplied receipt and a retained same-relay receipt. Each row asserts the flow reaches invite-consent with zero claims, then claims once with the app-minted receipt after native acceptance. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Matt Toohey <[email protected]>
1 parent 7a35f29 commit 93140fa

3 files changed

Lines changed: 80 additions & 21 deletions

File tree

‎desktop/src/features/onboarding/communityOnboarding.tsx‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ export function startCommunityOnboarding(
155155
now = new Date(),
156156
): CommunityOnboardingTransaction {
157157
const relayUrl = canonicalRelayUrl(input.relayUrl);
158+
// Anyone holding the invite code can mint a receipt from the public
159+
// accept-policy endpoint, so a receipt arriving with an app handoff link
160+
// proves nothing about consent. Link joins start without one — and drop any
161+
// retained same-relay receipt — so only the native `invite-consent` stage
162+
// can supply the receipt they claim with.
163+
const trustsReceipt = input.source !== "deep-link-join";
158164
const existing = loadCommunityOnboardingTransaction(storage);
159165
if (existing?.relayUrl === relayUrl) {
160166
const updated = {
@@ -165,7 +171,9 @@ export function startCommunityOnboarding(
165171
communityName: input.communityName?.trim() || existing.communityName,
166172
token: input.token?.trim() || existing.token,
167173
reposDir: input.reposDir ?? existing.reposDir,
168-
policyReceipt: input.policyReceipt ?? existing.policyReceipt,
174+
policyReceipt: trustsReceipt
175+
? (input.policyReceipt ?? existing.policyReceipt)
176+
: undefined,
169177
updatedAt: now.toISOString(),
170178
error: undefined,
171179
// A freshly opened link deserves fresh feedback — re-present the gate
@@ -187,7 +195,7 @@ export function startCommunityOnboarding(
187195
communityName: input.communityName?.trim() || deriveCommunityName(relayUrl),
188196
token: input.token?.trim() || undefined,
189197
reposDir: input.reposDir,
190-
policyReceipt: input.policyReceipt,
198+
policyReceipt: trustsReceipt ? input.policyReceipt : undefined,
191199
createdAt: timestamp,
192200
updatedAt: timestamp,
193201
};

‎desktop/src/features/onboarding/useClaimInvite.jsdom-test.mjs‎

Lines changed: 67 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { createRoot } from "react-dom/client";
77
import {
88
CommunityOnboardingProvider,
99
loadCommunityOnboardingTransaction,
10+
saveCommunityOnboardingTransaction,
1011
startCommunityOnboarding,
1112
useCommunityOnboarding,
1213
} from "./communityOnboarding.tsx";
@@ -33,15 +34,61 @@ const tauri = {
3334
window.__TAURI_INTERNALS__ = tauri;
3435
globalThis.__TAURI_INTERNALS__ = tauri;
3536

36-
for (const configured of [true, false]) {
37-
test(`receipt-less invite ${configured ? "waits for native consent" : "claims a policy-free relay"}`, async () => {
37+
const linkJoin = {
38+
source: "deep-link-join",
39+
relayUrl: "wss://relay.example",
40+
inviteCode: "code",
41+
};
42+
// Anyone holding the invite code can mint a receipt, so one arriving with the
43+
// link (or retained from an earlier same-relay transaction) must not stand in
44+
// for the app's own consent stage.
45+
for (const [name, configured, seed] of [
46+
[
47+
"receipt-less invite claims a policy-free relay",
48+
false,
49+
() => startCommunityOnboarding(linkJoin),
50+
],
51+
[
52+
"receipt-less invite waits for native consent",
53+
true,
54+
() => startCommunityOnboarding(linkJoin),
55+
],
56+
[
57+
"link-supplied receipt cannot bypass native consent",
58+
true,
59+
() =>
60+
startCommunityOnboarding({ ...linkJoin, policyReceipt: "link-receipt" }),
61+
],
62+
[
63+
"retained same-relay receipt cannot bypass native consent",
64+
true,
65+
() => {
66+
const timestamp = new Date().toISOString();
67+
saveCommunityOnboardingTransaction({
68+
id: "retained",
69+
source: "deep-link-join",
70+
stage: "claiming",
71+
relayUrl: "wss://relay.example",
72+
inviteCode: "code",
73+
communityName: "relay",
74+
policyReceipt: "link-receipt",
75+
createdAt: timestamp,
76+
updatedAt: timestamp,
77+
error: "offline",
78+
});
79+
startCommunityOnboarding(linkJoin);
80+
},
81+
],
82+
]) {
83+
test(name, async () => {
3884
localStorage.clear();
39-
const requests = [];
85+
const claimReceipts = [];
4086
const original = globalThis.fetch;
41-
globalThis.fetch = async (url) => {
42-
requests.push(String(url));
87+
globalThis.fetch = async (url, options) => {
4388
if (String(url).endsWith("/api/join-policy"))
4489
return Response.json(configured ? { policy } : {});
90+
assert.equal(url, "https://relay.example/api/invites/claim");
91+
claimReceipts.push(JSON.parse(options.body).policy_receipt);
4592
return Response.json({
4693
status: "joined",
4794
community_id: "id",
@@ -50,11 +97,7 @@ for (const configured of [true, false]) {
5097
});
5198
};
5299
try {
53-
startCommunityOnboarding({
54-
source: "deep-link-join",
55-
relayUrl: "wss://relay.example",
56-
inviteCode: "code",
57-
});
100+
seed();
58101
render(
59102
React.createElement(
60103
CommunityOnboardingProvider,
@@ -68,10 +111,18 @@ for (const configured of [true, false]) {
68111
configured ? "invite-consent" : "connecting",
69112
),
70113
);
71-
assert.equal(
72-
requests.filter((url) => url.endsWith("/claim")).length,
73-
configured ? 0 : 1,
74-
);
114+
if (configured) {
115+
assert.equal(controls.transaction.policyReceipt, undefined);
116+
assert.deepEqual(claimReceipts, []);
117+
// Native acceptance, as the invite-consent stage's onRedeem applies it.
118+
await act(async () =>
119+
controls.update({ policyReceipt: "app-receipt", stage: "claiming" }),
120+
);
121+
await waitFor(() =>
122+
assert.equal(controls.transaction.stage, "connecting"),
123+
);
124+
}
125+
assert.deepEqual(claimReceipts, [configured ? "app-receipt" : undefined]);
75126
} finally {
76127
cleanup();
77128
globalThis.fetch = original;
@@ -85,8 +136,9 @@ test("rejected receipt returns to native consent and clears the stale proof", as
85136
globalThis.fetch = async () =>
86137
Response.json({ error: "join_policy_required" }, { status: 403 });
87138
try {
139+
// An in-app form minted this receipt; link receipts never reach a claim.
88140
startCommunityOnboarding({
89-
source: "deep-link-join",
141+
source: "add-community",
90142
relayUrl: "wss://relay.example",
91143
inviteCode: "code",
92144
policyReceipt: "expired",

‎desktop/src/shared/deep-link.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,13 @@ export type NostrBindDeepLinkPayload = {
5151

5252
/**
5353
* Payload emitted by the Rust deep-link handler for `buzz://join?…` —
54-
* a relay invite from the web landing page (`/invite/<code>`).
54+
* a relay invite from the web landing page (`/invite/<code>`). Any
55+
* `policy_receipt` the link carries is ignored: the app collects consent
56+
* itself (see `startCommunityOnboarding`).
5557
*/
5658
export type JoinDeepLinkPayload = {
5759
relayUrl: string;
5860
code: string;
59-
policyReceipt: string | null;
6061
};
6162

6263
type PendingCommunityDeepLink = {
@@ -65,7 +66,6 @@ type PendingCommunityDeepLink = {
6566
relayUrl: string;
6667
code: string | null;
6768
name: string | null;
68-
policyReceipt: string | null;
6969
};
7070

7171
type PendingEntityDeepLink = {
@@ -89,7 +89,6 @@ function acceptPendingCommunityDeepLink(
8989
pending.kind === "join" ? "deep-link-join" : "deep-link-connect",
9090
relayUrl: pending.relayUrl,
9191
inviteCode: pending.code ?? undefined,
92-
policyReceipt: pending.policyReceipt ?? undefined,
9392
});
9493
return accepted
9594
? invoke<boolean>("acknowledge_pending_community_deep_link", {

0 commit comments

Comments
 (0)