Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

feat: add internal agents whitelist

Gus34ad8a3e39f5
diff --git a/src/shared/src/db/queries/whitelist.ts b/src/shared/src/db/queries/whitelist.ts
index 328963e82..94f2c7197 100644
--- a/src/shared/src/db/queries/whitelist.ts
+++ b/src/shared/src/db/queries/whitelist.ts
@@ -1,6 +1,7 @@
import { eq, and } from "drizzle-orm";
-import { agentWhitelist } from "../schema";
+import { agentWhitelist, agent } from "../schema";
import type { Database } from "../index";
+import { parseEmailHandle } from "../../utils/email";
export async function getWhitelist(db: Database, agentId: string, workspaceId: string) {
return db
@@ -47,6 +48,16 @@ export async function removeWhitelistByEmail(db: Database, agentId: string, work
}
export async function isWhitelisted(db: Database, agentId: string, workspaceId: string, email: string): Promise<boolean> {
+ const handle = parseEmailHandle(email);
+ if (handle) {
+ const rows = await db
+ .select({ workspaceId: agent.workspaceId })
+ .from(agent)
+ .where(eq(agent.emailHandle, handle))
+ .limit(1);
+ if (rows.length > 0 && rows[0].workspaceId === workspaceId) return true;
+ }
+
const rows = await db
.select({ id: agentWhitelist.id })
.from(agentWhitelist)
diff --git a/src/web/src/app/(app)/w/[slug]/settings/page.tsx b/src/web/src/app/(app)/w/[slug]/settings/page.tsx
index 120a297aa..df828f684 100644
--- a/src/web/src/app/(app)/w/[slug]/settings/page.tsx
+++ b/src/web/src/app/(app)/w/[slug]/settings/page.tsx
@@ -50,7 +50,7 @@ export default function SettingsPage() {
<div className="flex-1 min-w-0 flex flex-col">
<div className="px-4 pt-2 md:hidden">
- <Tabs value={activeTab} onValueChange={(v) => setActiveTab(v as TabId)}>
+ <Tabs className="items-center" value={activeTab} onValueChange={(v) => setActiveTab(v as TabId)}>
<TabsList className="h-auto gap-1">
{TABS.map((tab) => (
<TabsTrigger key={tab.id} value={tab.id}>
diff --git a/src/web/src/components/agent-edit-form.tsx b/src/web/src/components/agent-edit-form.tsx
index e5a611f6d..cef5c66f7 100644
--- a/src/web/src/components/agent-edit-form.tsx
+++ b/src/web/src/components/agent-edit-form.tsx
@@ -101,6 +101,7 @@ export function AgentEditForm({
<div className="flex-1 min-w-0 flex flex-col">
<div className="px-4 pt-2 md:hidden">
<Tabs
+ className="items-center"
value={activeTab}
onValueChange={(v) => setActiveTab(v as TabId)}
>
diff --git a/src/web/src/components/agent-form-fields.tsx b/src/web/src/components/agent-form-fields.tsx
index 1e562b87a..876414fdf 100644
--- a/src/web/src/components/agent-form-fields.tsx
+++ b/src/web/src/components/agent-form-fields.tsx
@@ -26,7 +26,7 @@ import type { Agent } from "@alook/shared";
import { isValidHandle } from "@alook/shared";
import type { AgentRuntime as Runtime } from "@alook/shared";
import { cn } from "@/lib/utils";
-import { LockIcon, XIcon } from "lucide-react";
+import { InfoIcon, LockIcon, XIcon } from "lucide-react";
import { useWorkspace } from "@/contexts/workspace-context";
import {
listWhitelist,
@@ -36,6 +36,7 @@ import {
grantAgentAccess,
revokeAgentAccess,
listMembers,
+ listAgents,
updateAgent as updateAgentApi,
type WhitelistEntry,
type AgentAccessEntry,
@@ -285,6 +286,7 @@ export function AllowedSendersTab({ agentId }: { agentId: string }) {
const [loading, setLoading] = useState(true);
const [adding, setAdding] = useState(false);
const [error, setError] = useState<string | null>(null);
+ const [hasSiblingAgents, setHasSiblingAgents] = useState(false);
useEffect(() => {
let cancelled = false;
@@ -304,6 +306,23 @@ export function AllowedSendersTab({ agentId }: { agentId: string }) {
};
}, [agentId, workspaceId]);
+ useEffect(() => {
+ let cancelled = false;
+ listAgents(workspaceId)
+ .then((agents) => {
+ if (!cancelled) {
+ const siblings = agents.filter(
+ (a) => a.id !== agentId && a.email_handle
+ );
+ setHasSiblingAgents(siblings.length > 0);
+ }
+ })
+ .catch(() => {});
+ return () => {
+ cancelled = true;
+ };
+ }, [agentId, workspaceId]);
+
const isValidEmail = newEmail.includes("@") && newEmail.trim().length > 0;
const handleAdd = async () => {
@@ -346,6 +365,13 @@ export function AllowedSendersTab({ agentId }: { agentId: string }) {
Only emails from these addresses will trigger this agent. Applies to
all configured email addresses (alook.ai handle and custom email).
</p>
+ {hasSiblingAgents && (
+ <p className="text-xs text-muted-foreground/70 mt-1.5 flex items-center gap-1">
+ <InfoIcon className="size-3 shrink-0" />
+ Agents in this workspace can already email each other — no whitelist
+ entry needed.
+ </p>
+ )}
</div>
<div className="flex items-center gap-2">
diff --git a/src/web/src/test/e2e/whitelist-bypass.test.ts b/src/web/src/test/e2e/whitelist-bypass.test.ts
new file mode 100644
index 000000000..59eef0c2b
--- /dev/null
+++ b/src/web/src/test/e2e/whitelist-bypass.test.ts
@@ -0,0 +1,218 @@
+import { describe, it, expect, beforeAll, afterAll } from "vitest"
+import { seedTestData, cleanupTestData, type TestSeed } from "../helpers/seed"
+import { sql, sqlQuery } from "../helpers/db"
+import { randomUUID } from "crypto"
+
+let seed: TestSeed
+let seedOther: TestSeed
+
+function nanoid() {
+ return randomUUID().replace(/-/g, "").slice(0, 21)
+}
+
+beforeAll(() => {
+ seed = seedTestData()
+ seedOther = seedTestData()
+})
+afterAll(() => {
+ cleanupTestData(seed)
+ cleanupTestData(seedOther)
+})
+
+describe("whitelist bypass for same-workspace agents", () => {
+ const EMAIL_WORKER_URL = process.env.EMAIL_WORKER_URL ?? "http://localhost:8787"
+
+ function rawEmail(from: string, to: string, subject: string, body: string): string {
+ const msgId = `<${randomUUID()}@e2e.test>`
+ return [
+ `From: ${from}`,
+ `To: ${to}`,
+ `Subject: ${subject}`,
+ `Message-ID: ${msgId}`,
+ `Date: ${new Date().toUTCString()}`,
+ `MIME-Version: 1.0`,
+ `Content-Type: text/plain; charset=utf-8`,
+ "",
+ body,
+ ].join("\r\n")
+ }
+
+ async function waitForEmail(
+ agentId: string,
+ fromEmail: string,
+ maxMs = 5000,
+ ): Promise<Record<string, unknown> | null> {
+ const start = Date.now()
+ while (Date.now() - start < maxMs) {
+ const rows = sqlQuery<Record<string, unknown>>(
+ `SELECT * FROM emails WHERE agent_id = '${agentId}' AND from_email = '${fromEmail}' ORDER BY created_at DESC LIMIT 1`,
+ )
+ if (rows.length > 0) return rows[0]
+ await new Promise((r) => setTimeout(r, 300))
+ }
+ return null
+ }
+
+ it("same-workspace agent email is treated as whitelisted (bypass)", async () => {
+ // Create a second agent in the same workspace with its own email handle
+ const siblingAgentId = `ag_${nanoid()}`
+ const siblingHandle = `e2e-sib-${nanoid()}`
+ const now = new Date().toISOString()
+ sql(`INSERT INTO agent (id, workspace_id, name, runtime_id, email_handle, owner_id, created_at, updated_at) VALUES ('${siblingAgentId}', '${seed.workspaceId}', 'Sibling Agent', '${seed.runtimeId}', '${siblingHandle}', '${seed.userId}', '${now}', '${now}')`)
+
+ try {
+ // Sibling agent emails the seed agent — sibling is NOT in seed agent's whitelist
+ const from = `${siblingHandle}@alook.ai`
+ const to = `${seed.agentEmailHandle}@alook.ai`
+ const subject = "E2E bypass test"
+
+ const res = await fetch(
+ `${EMAIL_WORKER_URL}/cdn-cgi/handler/email?from=${encodeURIComponent(from)}&to=${encodeURIComponent(to)}`,
+ {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: rawEmail(from, to, subject, "Hello from sibling"),
+ },
+ )
+ expect(res.status).toBe(200)
+
+ const row = await waitForEmail(seed.agentId, from)
+ expect(row).not.toBeNull()
+ expect(row!.is_whitelisted).toBe(1)
+ } finally {
+ sql(`DELETE FROM agent WHERE id = '${siblingAgentId}' AND workspace_id = '${seed.workspaceId}'`)
+ }
+ })
+
+ it("agent emailing itself is treated as whitelisted", async () => {
+ const from = `${seed.agentEmailHandle}@alook.ai`
+ const to = `${seed.agentEmailHandle}@alook.ai`
+ const subject = "E2E self-email test"
+
+ const res = await fetch(
+ `${EMAIL_WORKER_URL}/cdn-cgi/handler/email?from=${encodeURIComponent(from)}&to=${encodeURIComponent(to)}`,
+ {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: rawEmail(from, to, subject, "Hello self"),
+ },
+ )
+ expect(res.status).toBe(200)
+
+ const row = await waitForEmail(seed.agentId, from)
+ expect(row).not.toBeNull()
+ expect(row!.is_whitelisted).toBe(1)
+ })
+
+ it("different-workspace agent email is NOT treated as whitelisted", async () => {
+ // seedOther is in a different workspace — its agent email should not bypass
+ const from = `${seedOther.agentEmailHandle}@alook.ai`
+ const to = `${seed.agentEmailHandle}@alook.ai`
+ const subject = "E2E cross-workspace test"
+
+ const res = await fetch(
+ `${EMAIL_WORKER_URL}/cdn-cgi/handler/email?from=${encodeURIComponent(from)}&to=${encodeURIComponent(to)}`,
+ {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: rawEmail(from, to, subject, "Cross workspace"),
+ },
+ )
+ // May be 200 (stored but rejected) or rejected
+ const row = await waitForEmail(seed.agentId, from)
+ expect(row).not.toBeNull()
+ expect(row!.is_whitelisted).toBe(0)
+ })
+
+ it("@alook.ai email with nonexistent handle is NOT whitelisted", async () => {
+ const from = `nonexistent-handle-${nanoid()}@alook.ai`
+ const to = `${seed.agentEmailHandle}@alook.ai`
+ const subject = "E2E nonexistent handle test"
+
+ await fetch(
+ `${EMAIL_WORKER_URL}/cdn-cgi/handler/email?from=${encodeURIComponent(from)}&to=${encodeURIComponent(to)}`,
+ {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: rawEmail(from, to, subject, "Ghost agent"),
+ },
+ )
+
+ const row = await waitForEmail(seed.agentId, from)
+ expect(row).not.toBeNull()
+ expect(row!.is_whitelisted).toBe(0)
+ })
+
+ it("regular whitelist entries still work (existing behavior)", async () => {
+ // [email protected] is in the whitelist — should still be whitelisted
+ const from = `${seed.userId}@test.local`
+ const to = `${seed.agentEmailHandle}@alook.ai`
+ const subject = "E2E regular whitelist test"
+
+ const res = await fetch(
+ `${EMAIL_WORKER_URL}/cdn-cgi/handler/email?from=${encodeURIComponent(from)}&to=${encodeURIComponent(to)}`,
+ {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: rawEmail(from, to, subject, "Regular whitelisted"),
+ },
+ )
+ expect(res.status).toBe(200)
+
+ const row = await waitForEmail(seed.agentId, from)
+ expect(row).not.toBeNull()
+ expect(row!.is_whitelisted).toBe(1)
+ })
+
+ it("non-whitelisted non-agent email is rejected (existing behavior)", async () => {
+ const from = "[email protected]"
+ const to = `${seed.agentEmailHandle}@alook.ai`
+ const subject = "E2E stranger test"
+
+ await fetch(
+ `${EMAIL_WORKER_URL}/cdn-cgi/handler/email?from=${encodeURIComponent(from)}&to=${encodeURIComponent(to)}`,
+ {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: rawEmail(from, to, subject, "Stranger"),
+ },
+ )
+
+ const row = await waitForEmail(seed.agentId, from)
+ expect(row).not.toBeNull()
+ expect(row!.is_whitelisted).toBe(0)
+ })
+
+ it("sender that is both whitelisted AND same-workspace agent is whitelisted", async () => {
+ // Create a sibling agent and also add it to the whitelist
+ const siblingAgentId = `ag_${nanoid()}`
+ const siblingHandle = `e2e-both-${nanoid()}`
+ const now = new Date().toISOString()
+ const wlId = `wl_${nanoid()}`
+ sql(`INSERT INTO agent (id, workspace_id, name, runtime_id, email_handle, owner_id, created_at, updated_at) VALUES ('${siblingAgentId}', '${seed.workspaceId}', 'Both Agent', '${seed.runtimeId}', '${siblingHandle}', '${seed.userId}', '${now}', '${now}')`)
+ sql(`INSERT INTO agent_whitelist (id, agent_id, workspace_id, email, created_at) VALUES ('${wlId}', '${seed.agentId}', '${seed.workspaceId}', '${siblingHandle}@alook.ai', '${now}')`)
+
+ try {
+ const from = `${siblingHandle}@alook.ai`
+ const to = `${seed.agentEmailHandle}@alook.ai`
+ const subject = "E2E both paths test"
+
+ const res = await fetch(
+ `${EMAIL_WORKER_URL}/cdn-cgi/handler/email?from=${encodeURIComponent(from)}&to=${encodeURIComponent(to)}`,
+ {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: rawEmail(from, to, subject, "Both paths"),
+ },
+ )
+ expect(res.status).toBe(200)
+
+ const row = await waitForEmail(seed.agentId, from)
+ expect(row).not.toBeNull()
+ expect(row!.is_whitelisted).toBe(1)
+ } finally {
+ sql(`DELETE FROM agent_whitelist WHERE id = '${wlId}'`)
+ sql(`DELETE FROM agent WHERE id = '${siblingAgentId}' AND workspace_id = '${seed.workspaceId}'`)
+ }
+ })
+})