Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

fix(web): prevent invited members from overwriting workspace slug (#314)

Generd60a33565b45
diff --git a/src/web/src/app/(app)/w/[slug]/layout.tsx b/src/web/src/app/(app)/w/[slug]/layout.tsx
index 18b31e078..ea58a691e 100644
--- a/src/web/src/app/(app)/w/[slug]/layout.tsx
+++ b/src/web/src/app/(app)/w/[slug]/layout.tsx
@@ -35,7 +35,7 @@ export default async function WorkspaceLayout({
)
if (!membership) redirect("/workspaces")
- const agents = await queries.agent.listAgents(db, ws.id, session.user.id)
+ const agents = await queries.agent.listAgents(db, ws.id)
if (agents.length === 0) {
const hdrs = await headers()
const cookieHeader = hdrs.get("cookie") || ""
diff --git a/src/web/src/app/(app)/workspaces/page.tsx b/src/web/src/app/(app)/workspaces/page.tsx
index 02fe72b13..7e52d5b79 100644
--- a/src/web/src/app/(app)/workspaces/page.tsx
+++ b/src/web/src/app/(app)/workspaces/page.tsx
@@ -24,7 +24,7 @@ export default async function WorkspacesPage({
// Auto-redirect to single workspace only on post-login flow
const params = await searchParams
if (workspaces.length === 1 && params.auto !== undefined) {
- const agents = await queries.agent.listAgents(db, workspaces[0].id, session.user.id)
+ const agents = await queries.agent.listAgents(db, workspaces[0].id)
if (agents.length === 0) {
redirect(`/studio/new?workspace_id=${workspaces[0].id}`)
}
@@ -34,7 +34,7 @@ export default async function WorkspacesPage({
// Find most recent workspace with 0 agents to reuse for "New workspace"
let emptyWorkspaceId: string | null = null
for (const ws of workspaces) {
- const agents = await queries.agent.listAgents(db, ws.id, session.user.id)
+ const agents = await queries.agent.listAgents(db, ws.id)
if (agents.length === 0) {
emptyWorkspaceId = ws.id
break
diff --git a/src/web/src/app/api/studios/route.test.ts b/src/web/src/app/api/studios/route.test.ts
index da19e29ac..cfa11b5b1 100644
--- a/src/web/src/app/api/studios/route.test.ts
+++ b/src/web/src/app/api/studios/route.test.ts
@@ -83,8 +83,9 @@ vi.mock("@/lib/middleware/auth", () => ({
}),
}));
+const mockWithWorkspaceMember = vi.fn(async () => ({ workspaceId: "w1", memberRole: "owner" }));
vi.mock("@/lib/middleware/workspace", () => ({
- withWorkspaceMember: vi.fn(async () => ({ workspaceId: "w1", memberRole: "owner" })),
+ withWorkspaceMember: (...args: unknown[]) => mockWithWorkspaceMember(...args),
}));
vi.mock("@/lib/api/responses", () => ({
@@ -333,6 +334,27 @@ describe("POST /api/studios", () => {
expect(agentData.avatarUrl).toBe("custom-avatar");
});
+ it("non-owner member cannot update workspace slug", async () => {
+ mockWithWorkspaceMember.mockResolvedValueOnce({ workspaceId: "w1", memberRole: "member" });
+ mockListAgents
+ .mockResolvedValueOnce([])
+ .mockResolvedValueOnce([
+ { id: "agent-1", name: "Solo", emailHandle: "solo" },
+ ]);
+
+ const req = new NextRequest("http://localhost/api/studios", {
+ method: "POST",
+ body: JSON.stringify({
+ name: "Hijacked Name",
+ members: [{ name: "Solo", role: "leader", runtime_id: "rt1" }],
+ }),
+ });
+
+ const res = await POST(req, {});
+ expect(res.status).toBe(201);
+ expect(mockUpdateWorkspace).not.toHaveBeenCalled();
+ });
+
it("creates agents with auto-generated names when name is omitted", async () => {
mockListAgents
.mockResolvedValueOnce([])
diff --git a/src/web/src/app/api/studios/route.ts b/src/web/src/app/api/studios/route.ts
index 23cc0e1ba..90f837deb 100644
--- a/src/web/src/app/api/studios/route.ts
+++ b/src/web/src/app/api/studios/route.ts
@@ -69,8 +69,8 @@ export const POST = withAuth(async (req: NextRequest, ctx) => {
return writeError("workspace not found", 404);
}
- if (body.name) {
- const existingAgents = await queries.agent.listAgents(db, ws.workspaceId, ctx.userId);
+ if (body.name && ws.memberRole === "owner") {
+ const existingAgents = await queries.agent.listAgents(db, ws.workspaceId);
const newSlug = slugify(body.name);
if (existingAgents.length === 0 && newSlug) {
let finalSlug = newSlug;
diff --git a/src/web/src/test/e2e/workspace-invites.test.ts b/src/web/src/test/e2e/workspace-invites.test.ts
index b6320dd02..908def5bb 100644
--- a/src/web/src/test/e2e/workspace-invites.test.ts
+++ b/src/web/src/test/e2e/workspace-invites.test.ts
@@ -1,6 +1,6 @@
import { describe, it, expect, beforeAll, afterAll } from "vitest"
import { randomUUID } from "crypto"
-import { seedTestData, cleanupTestData, type TestSeed, signUp, signIn, sessionRequest, tokenRequest, sqlRun } from "@alook/test-utils"
+import { seedTestData, cleanupTestData, type TestSeed, signUp, signIn, sessionRequest, tokenRequest, sqlRun, sqlQuery } from "@alook/test-utils"
let seed: TestSeed
@@ -111,4 +111,30 @@ describe("workspace invite flow", () => {
)
expect(res.status).toBe(404)
})
+
+ it("invited member creating studio does NOT overwrite workspace slug", async () => {
+ const originalSlug = sqlQuery<{ slug: string }>(
+ `SELECT slug FROM workspace WHERE id = ?`,
+ seed.workspaceId,
+ )[0].slug
+
+ const res = await sessionRequest(`/api/studios`, inviteeCookie, {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ "X-Workspace-ID": seed.workspaceId,
+ },
+ body: JSON.stringify({
+ name: "Hijacked Studio Name",
+ members: [{ name: "Rogue", role: "leader", runtime_id: seed.runtimeId }],
+ }),
+ })
+ expect(res.status).toBe(201)
+
+ const currentSlug = sqlQuery<{ slug: string }>(
+ `SELECT slug FROM workspace WHERE id = ?`,
+ seed.workspaceId,
+ )[0].slug
+ expect(currentSlug).toBe(originalSlug)
+ })
})