Repository navigation
fix(desktop): enforce agent mention authorization at send boundaries #5681
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
26ea485
fix(desktop): show eligible remote member agents in mentions
JDiz00 235aa2c
fix(desktop): fail closed for agent mentions
wesbillman dfc79a2
fix(desktop): revalidate agent mentions before send
wesbillman e780f87
fix(desktop): close agent mention send races
wesbillman 7278cdd
Merge origin/main into fix/remote-agent-member-mentions
wesbillman 6c2417b
Revalidate agent mentions before forum sends
wesbillman 1709de5
Merge origin/main into fix/remote-agent-member-mentions
wesbillman 31bb821
Lock forum drafts during mention revalidation
wesbillman ae71c72
Close forum preflight mutation side doors
wesbillman e17d341
Authorize agent mentions before preparation
wesbillman 939bf53
Revalidate agent mentions before inviting
wesbillman b972eb2
Merge origin/main into fix/remote-agent-member-mentions
wesbillman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
desktop/src/features/messages/lib/agentMentionRevalidation.test.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import assert from "node:assert/strict"; | ||
| import test from "node:test"; | ||
|
|
||
| import { revalidateAgentMentionPubkeys } from "./agentMentionRevalidation.ts"; | ||
|
|
||
| const CURRENT = "a".repeat(64); | ||
| const AGENT = "b".repeat(64); | ||
| const HUMAN = "c".repeat(64); | ||
| const OTHER_OWNER = "d".repeat(64); | ||
|
|
||
| function options(refetchOwnerProfiles) { | ||
| return { | ||
| pubkeys: [HUMAN, AGENT], | ||
| agentPubkeys: new Set([AGENT]), | ||
| currentPubkey: CURRENT, | ||
| eligibilityScope: { type: "channel", channelId: "general" }, | ||
| sharedChannelIds: new Set(["general"]), | ||
| ownerOnly: true, | ||
| ownerPolicyError: null, | ||
| refetchManagedAgents: async () => ({ data: [], error: null }), | ||
| refetchRelayAgents: async () => ({ | ||
| data: [ | ||
| { | ||
| pubkey: AGENT, | ||
| respondTo: "anyone", | ||
| respondToAllowlist: [], | ||
| channelIds: ["general"], | ||
| }, | ||
| ], | ||
| error: null, | ||
| }), | ||
| refetchOwnerProfiles, | ||
| }; | ||
| } | ||
|
|
||
| test("owner-only revalidation admits an agent only from a fresh same-owner proof", async () => { | ||
| const requested = []; | ||
| const result = await revalidateAgentMentionPubkeys( | ||
| options(async (pubkeys) => { | ||
| requested.push(...pubkeys); | ||
| return { | ||
| profiles: { [AGENT]: { ownerPubkey: CURRENT } }, | ||
| missing: [], | ||
| }; | ||
| }), | ||
| ); | ||
|
|
||
| assert.deepEqual(requested, [AGENT]); | ||
| assert.deepEqual(result, [HUMAN, AGENT]); | ||
| }); | ||
|
|
||
| for (const [name, refetchOwnerProfiles] of [ | ||
| ["revoked owner proof", async () => ({ profiles: {}, missing: [AGENT] })], | ||
| [ | ||
| "changed owner proof", | ||
| async () => ({ | ||
| profiles: { [AGENT]: { ownerPubkey: OTHER_OWNER } }, | ||
| missing: [], | ||
| }), | ||
| ], | ||
| [ | ||
| "owner profile query error", | ||
| async () => { | ||
| throw new Error("relay unavailable"); | ||
| }, | ||
| ], | ||
| ]) { | ||
| test(`owner-only revalidation fails closed on ${name}`, async () => { | ||
| assert.deepEqual( | ||
| await revalidateAgentMentionPubkeys(options(refetchOwnerProfiles)), | ||
| [HUMAN], | ||
| ); | ||
| }); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤖
ownerOnly = falsehere swallows theundefinedthatuseMentionspasses while the owner-policy query is still loading (ownerOnly: agentAccessOwnerOnlyQuery.data), so the"unknown"branchgetAgentMentionAdmissionhas for exactly that state is unreachable through this wrapper. During the window where the agent directories are ready but the owner policy isn't, an other-owned relay agent is admitted into autocomplete in an owner-only build. Send-time revalidation strips it on the chat/edit paths (it checksownerOnly === undefinedexplicitly), which keeps this non-blocking — but it contradicts the fail-closed intent, and both reviews flagged it independently. Fix: drop the destructuring default and passundefinedthrough, or foldownerPolicyReadyinto thedirectoryReadyvalue this call site receives.