Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(members): hide guest rows from clients that can't render them (MUL-9706) (#11051)

Multica Evea6671705899e
diff --git a/apps/mobile/data/api.test.ts b/apps/mobile/data/api.test.ts
index 223dd19a56..f149c8420f 100644
--- a/apps/mobile/data/api.test.ts
+++ b/apps/mobile/data/api.test.ts
@@ -26,6 +26,20 @@ describe("api.listAgents", () => {
});
});
+// The server leaves guests out of the member list unless the caller declares
+// it can render them; useIsGuest reads the caller's own row from that list.
+describe("api.listMembers", () => {
+ afterEach(() => vi.unstubAllGlobals());
+
+ it("advertises the guest capability", async () => {
+ const fetchMock = vi.fn(async (_url: string, _init?: RequestInit) => Response.json([]));
+ vi.stubGlobal("fetch", fetchMock);
+ await api.listMembers("ws-1");
+ const headers = fetchMock.mock.calls[0]?.[1]?.headers as Record<string, string>;
+ expect(headers["X-Client-Capabilities"]).toBe("workspace-guests-v1");
+ });
+});
+
describe("api.deleteComment", () => {
const fetchMock = vi.fn(async () => new Response(null, { status: 204 }));
diff --git a/apps/mobile/data/api.ts b/apps/mobile/data/api.ts
index 4a12eeb849..ae4008399f 100644
--- a/apps/mobile/data/api.ts
+++ b/apps/mobile/data/api.ts
@@ -572,7 +572,12 @@ class ApiClient {
): Promise<MemberWithUser[]> {
const raw = await this.fetch<unknown>(
`/api/workspaces/${workspaceId}/members`,
- { signal: opts?.signal },
+ {
+ signal: opts?.signal,
+ // Without it the server leaves guests out of the list, and useIsGuest
+ // could not recognize a guest. Mirrors protocol.AppCapabilityWorkspaceGuestsV1.
+ headers: { "X-Client-Capabilities": "workspace-guests-v1" },
+ },
);
return parseWithFallback(raw, MemberListSchema, EMPTY_MEMBER_LIST, {
endpoint: "listMembers",
diff --git a/packages/core/api/client.test.ts b/packages/core/api/client.test.ts
index a98934835d..5ceca6dc2e 100644
--- a/packages/core/api/client.test.ts
+++ b/packages/core/api/client.test.ts
@@ -3,7 +3,7 @@ import { createAuthStore } from "../auth";
import { setCurrentWorkspace } from "../platform/workspace-storage";
import { configStore } from "../config";
import type { StorageAdapter, User } from "../types";
-import { ApiClient, ApiError, CHAT_DRAFT_RESTORE_CAPABILITY, clientErrorMessage } from "./client";
+import { ApiClient, ApiError, CHAT_DRAFT_RESTORE_CAPABILITY, WORKSPACE_GUESTS_CAPABILITY, clientErrorMessage } from "./client";
import { setApiRequestObserver } from "./request-observer";
import { EMPTY_PLUGIN_PACKAGE_LIST, EMPTY_PLUGIN_PREVIEW, EMPTY_PLUGIN_SURFACE_LAUNCH } from "./schemas";
@@ -3654,3 +3654,25 @@ describe("ApiClient request observer", () => {
expect(events[1]).toMatchObject({ phase: "end", status: null, error: "TypeError: Failed to fetch" });
});
});
+
+// The server hides guest rows from member and invitation lists unless the
+// caller declares it can render the guest role; drop the header and the
+// members page silently loses every guest.
+describe("workspace guest lists", () => {
+ afterEach(() => vi.unstubAllGlobals());
+
+ it.each([
+ ["listMembers", (c: ApiClient) => c.listMembers("ws-1")],
+ ["listWorkspaceInvitations", (c: ApiClient) => c.listWorkspaceInvitations("ws-1")],
+ ])("%s advertises the guest capability", async (_name, call) => {
+ const fetchMock = vi.fn().mockResolvedValue(new Response("[]", {
+ status: 200, headers: { "Content-Type": "application/json" },
+ }));
+ vi.stubGlobal("fetch", fetchMock);
+
+ await call(new ApiClient("https://api.example.test"));
+
+ const init = fetchMock.mock.calls[0]?.[1] as { headers: Record<string, string> };
+ expect(init.headers["X-Client-Capabilities"]).toBe(WORKSPACE_GUESTS_CAPABILITY);
+ });
+});
diff --git a/packages/core/api/client.ts b/packages/core/api/client.ts
index a94f772270..b217ebb263 100644
--- a/packages/core/api/client.ts
+++ b/packages/core/api/client.ts
@@ -879,6 +879,14 @@ function skillFromImportResult(raw: unknown, endpoint: string): Skill {
*/
export const CHAT_DRAFT_RESTORE_CAPABILITY = "chat-draft-restore-v1";
+/**
+ * Advertised in X-Client-Capabilities on member and invitation lists: without
+ * it the server leaves guest rows out, because clients released before guests
+ * crash on the unknown role. Must stay in sync with
+ * protocol.AppCapabilityWorkspaceGuestsV1.
+ */
+export const WORKSPACE_GUESTS_CAPABILITY = "workspace-guests-v1";
+
/**
* Body shared by both unsubscribe endpoints: an omitted target means "the
* caller", which the server resolves from the request actor.
@@ -4132,7 +4140,9 @@ export class ApiClient {
// Members
async listMembers(workspaceId: string): Promise<MemberWithUser[]> {
- return this.fetch(`/api/workspaces/${workspaceId}/members`);
+ return this.fetch(`/api/workspaces/${workspaceId}/members`, {
+ headers: { "X-Client-Capabilities": WORKSPACE_GUESTS_CAPABILITY },
+ });
}
async createMember(workspaceId: string, data: CreateMemberRequest): Promise<Invitation> {
@@ -4170,7 +4180,9 @@ export class ApiClient {
// Invitations
async listWorkspaceInvitations(workspaceId: string): Promise<Invitation[]> {
- return this.fetch(`/api/workspaces/${workspaceId}/invitations`);
+ return this.fetch(`/api/workspaces/${workspaceId}/invitations`, {
+ headers: { "X-Client-Capabilities": WORKSPACE_GUESTS_CAPABILITY },
+ });
}
async revokeInvitation(workspaceId: string, invitationId: string): Promise<void> {
diff --git a/server/internal/cli/client.go b/server/internal/cli/client.go
index dc819a0a70..0df32cc5fc 100644
--- a/server/internal/cli/client.go
+++ b/server/internal/cli/client.go
@@ -218,7 +218,10 @@ func NewAPIClient(baseURL, workspaceID, token string) *APIClient {
// which keeps signing regardless of this capability — so the signature in list
// payloads was pure cost: raw bytes, a per-attachment RSA sign, and bytes that
// differ on every read and therefore defeat agent prompt caching.
-const clientCapabilities = "stable_attachment_urls"
+//
+// workspace-guests-v1 keeps guests in workspace member and invitation lists,
+// which the server hides from clients that cannot render the guest role.
+const clientCapabilities = "stable_attachment_urls,workspace-guests-v1"
func (c *APIClient) setHeaders(req *http.Request) {
req.Header.Set("X-Client-Capabilities", clientCapabilities)
diff --git a/server/internal/cli/client_test.go b/server/internal/cli/client_test.go
index 7bcab40953..15ee769936 100644
--- a/server/internal/cli/client_test.go
+++ b/server/internal/cli/client_test.go
@@ -494,11 +494,14 @@ func TestNormalizeGOOS(t *testing.T) {
// every other test green while the CLI silently went back to receiving ~800-char
// signed URLs on every attachment of every list read.
//
+// The same holds for workspace-guests-v1: without it, guests drop out of the
+// member lists the CLI resolves names from.
+//
// The exact string is load-bearing: the server matches the token literally
// (handler.requestHasClientCapability), so it is asserted verbatim rather than
// through the constant.
func TestSetHeaders_AdvertisesStableAttachmentURLs(t *testing.T) {
- const wantCapability = "stable_attachment_urls"
+ const wantCapability = "stable_attachment_urls,workspace-guests-v1"
// Every verb goes through setHeaders, and an agent's read path is not only
// GET (comment add posts, attachment upload multiparts). Cover the shapes
diff --git a/server/internal/handler/guest_test.go b/server/internal/handler/guest_test.go
index 0eb9f732f1..ce3b1e7679 100644
--- a/server/internal/handler/guest_test.go
+++ b/server/internal/handler/guest_test.go
@@ -10,6 +10,7 @@ import (
"github.com/multica-ai/multica/server/internal/projectaccess"
"github.com/multica-ai/multica/server/internal/testutil"
+ "github.com/multica-ai/multica/server/pkg/protocol"
)
// guestFixture: a guest of one workspace-visible project (shared), with a
@@ -49,10 +50,11 @@ func newGuestFixture(t *testing.T) guestFixture {
}
// guestRequest runs handler behind the workspace middleware, as the router
-// does, so the guest route allowlist applies.
+// does, so the guest route allowlist applies. It speaks as a guest-aware
+// client: only those can sign a guest in.
func guestRequest(t *testing.T, handler http.HandlerFunc, userID, method, path string, body any, params ...string) *testutil.Response {
t.Helper()
- req := asUser(newRequest(method, path, body), userID)
+ req := withGuestCapability(asUser(newRequest(method, path, body), userID))
if len(params) > 0 {
req = withURLParams(req, params...)
}
@@ -265,13 +267,90 @@ func TestGuestPromotionAndDemotion(t *testing.T) {
}
var members []MemberWithUserResponse
- req = withURLParam(newRequest(http.MethodGet, "/api/workspaces/"+testWorkspaceID+"/members", nil), "id", testWorkspaceID)
+ req = withGuestCapability(withURLParam(newRequest(http.MethodGet, "/api/workspaces/"+testWorkspaceID+"/members", nil), "id", testWorkspaceID))
testutil.Call(t, testHandler.ListMembersWithUser, req).Want(http.StatusOK).JSON(&members)
+ listed := false
for _, m := range members {
- if m.UserID == f.guest && fmt.Sprint(m.ProjectIDs) != fmt.Sprint([]string{f.other}) {
+ if m.UserID != f.guest {
+ continue
+ }
+ listed = true
+ if fmt.Sprint(m.ProjectIDs) != fmt.Sprint([]string{f.other}) {
t.Errorf("members list guest project_ids = %v, want only other", m.ProjectIDs)
}
}
+ if !listed {
+ t.Error("members list misses the guest")
+ }
+}
+
+// Clients released before guests index their role tables by role and crash on
+// "guest", so member and invitation lists leave guests out unless the caller
+// declares it can render them.
+func TestMemberAndInvitationListsHideGuestsFromOlderClients(t *testing.T) {
+ clearInvitationsForTestWorkspace(t)
+ f := newGuestFixture(t)
+ req := withURLParam(newRequest(http.MethodPost, "/api/workspaces/"+testWorkspaceID+"/members",
+ CreateMemberRequest{Email: f.marker + "[email protected]", Role: "guest", ProjectIDs: []string{f.shared}}), "id", testWorkspaceID)
+ testutil.Call(t, testHandler.CreateInvitation, req).Want(http.StatusCreated)
+ req = withURLParam(newRequest(http.MethodPost, "/api/workspaces/"+testWorkspaceID+"/members",
+ CreateMemberRequest{Email: f.marker + "[email protected]", Role: "member"}), "id", testWorkspaceID)
+ testutil.Call(t, testHandler.CreateInvitation, req).Want(http.StatusCreated)
+
+ for _, tc := range []struct {
+ name string
+ capability string
+ wantGuests bool
+ }{
+ {"older client", "", false},
+ {"other capabilities only", "stable_attachment_urls", false},
+ {"guest-aware client", "stable_attachment_urls, workspace-guests-v1", true},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ withCapability := func(req *http.Request) *http.Request {
+ if tc.capability != "" {
+ req.Header.Set("X-Client-Capabilities", tc.capability)
+ }
+ return req
+ }
+
+ var members []MemberWithUserResponse
+ req := withCapability(withURLParam(newRequest(http.MethodGet, "/api/workspaces/"+testWorkspaceID+"/members", nil), "id", testWorkspaceID))
+ testutil.Call(t, testHandler.ListMembersWithUser, req).Want(http.StatusOK).JSON(&members)
+ guests, owner := 0, false
+ for _, m := range members {
+ if m.Role == projectaccess.RoleGuest {
+ guests++
+ }
+ owner = owner || m.UserID == testUserID
+ }
+ if !owner {
+ t.Error("members list misses the owner")
+ }
+ if (guests > 0) != tc.wantGuests {
+ t.Errorf("members list has %d guests, want guests = %v", guests, tc.wantGuests)
+ }
+
+ var invitations []InvitationResponse
+ req = withCapability(withURLParam(newRequest(http.MethodGet, "/api/workspaces/"+testWorkspaceID+"/invitations", nil), "id", testWorkspaceID))
+ testutil.Call(t, testHandler.ListWorkspaceInvitations, req).Want(http.StatusOK).JSON(&invitations)
+ roles := map[string]int{}
+ for _, inv := range invitations {
+ roles[inv.Role]++
+ }
+ if roles["member"] != 1 {
+ t.Errorf("invitations by role = %v, want the member invitation", roles)
+ }
+ if (roles[projectaccess.RoleGuest] > 0) != tc.wantGuests {
+ t.Errorf("invitations by role = %v, want guests = %v", roles, tc.wantGuests)
+ }
+ })
+ }
+}
+
+func withGuestCapability(req *http.Request) *http.Request {
+ req.Header.Set("X-Client-Capabilities", protocol.AppCapabilityWorkspaceGuestsV1)
+ return req
}
func TestGuestSeesOnlyGuestsItSharesAProjectWith(t *testing.T) {
diff --git a/server/internal/handler/invitation.go b/server/internal/handler/invitation.go
index 19ee59b5d0..a8f7505f91 100644
--- a/server/internal/handler/invitation.go
+++ b/server/internal/handler/invitation.go
@@ -314,9 +314,13 @@ func (h *Handler) ListWorkspaceInvitations(w http.ResponseWriter, r *http.Reques
return
}
- resp := make([]InvitationResponse, len(rows))
- for i, row := range rows {
- resp[i] = InvitationResponse{
+ includeGuests := clientRendersGuestRole(r)
+ resp := make([]InvitationResponse, 0, len(rows))
+ for _, row := range rows {
+ if projectaccess.IsGuestRole(row.Role) && !includeGuests {
+ continue
+ }
+ resp = append(resp, InvitationResponse{
ID: uuidToString(row.ID),
WorkspaceID: uuidToString(row.WorkspaceID),
InviterID: uuidToString(row.InviterID),
@@ -330,7 +334,7 @@ func (h *Handler) ListWorkspaceInvitations(w http.ResponseWriter, r *http.Reques
ExpiresAt: timestampToString(row.ExpiresAt),
InviterName: row.InviterName,
InviterEmail: row.InviterEmail,
- }
+ })
}
writeJSON(w, http.StatusOK, resp)
diff --git a/server/internal/handler/workspace.go b/server/internal/handler/workspace.go
index 4d9cadb532..77fed39f05 100644
--- a/server/internal/handler/workspace.go
+++ b/server/internal/handler/workspace.go
@@ -619,6 +619,7 @@ func (h *Handler) ListMembersWithUser(w http.ResponseWriter, r *http.Request) {
// each other. Nobody's projects are listed to a guest.
requester, _ := ctxMember(r.Context())
requesterIsGuest := projectaccess.IsGuestRole(requester.Role)
+ includeGuests := clientRendersGuestRole(r)
visibleGuests := map[[16]byte]bool{requester.UserID.Bytes: true}
if requesterIsGuest {
mine := map[string]bool{}
@@ -637,6 +638,9 @@ func (h *Handler) ListMembersWithUser(w http.ResponseWriter, r *http.Request) {
resp := make([]MemberWithUserResponse, 0, len(members))
for _, m := range members {
guest := projectaccess.IsGuestRole(m.Role)
+ if guest && !includeGuests {
+ continue
+ }
if requesterIsGuest && guest && !visibleGuests[m.UserID.Bytes] {
continue
}
@@ -679,6 +683,13 @@ func (h *Handler) memberWithUserResponse(member db.Member, user db.User) MemberW
}
}
+// clientRendersGuestRole reports whether the caller declared it can render
+// guest rows. Member and invitation lists hide guests from older clients,
+// whose role tables have no guest entry and crash on one.
+func clientRendersGuestRole(r *http.Request) bool {
+ return requestHasClientCapability(r, protocol.AppCapabilityWorkspaceGuestsV1)
+}
+
func normalizeMemberRole(role string) (string, bool) {
if role == "" {
return "member", true
diff --git a/server/pkg/protocol/messages.go b/server/pkg/protocol/messages.go
index ebb4eb22b5..de238a52e9 100644
--- a/server/pkg/protocol/messages.go
+++ b/server/pkg/protocol/messages.go
@@ -107,6 +107,13 @@ const (
// synchronous restore — a client without this capability would silently
// drop the user's prompt, and keeps the legacy synchronous restore instead.
AppCapabilityChatDraftRestoreV1 = "chat-draft-restore-v1"
+
+ // AppCapabilityWorkspaceGuestsV1 is advertised (X-Client-Capabilities) by
+ // clients that can render the guest member role. Workspace member and
+ // invitation lists leave guest rows out for any other caller: clients
+ // released before guests index their role tables by role and crash on an
+ // unknown one. Authorization never depends on it.
+ AppCapabilityWorkspaceGuestsV1 = "workspace-guests-v1"
)
// ChatQuickAction is a server-validated follow-up attached to one assistant