Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions apps/mesh/src/api/routes/downstream-token.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,62 @@ describe("Downstream Token Routes", () => {
expect(body.success).toBe(true);
expect(body.expiresAt).toBeTruthy();
});

describe("org-less API key rejection", () => {
let orglessApp: Hono<{ Variables: { meshContext: MeshContext } }>;

beforeEach(() => {
const ctx = {
organization: undefined,
auth: { user: { id: "user_1" }, apiKey: { userId: "user_1" } },
storage: {
connections: {
findById: mock(async () => ({ id: "conn_1" })),
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The new regression tests never assert findById is not called, so they don’t verify the intended “reject before lookup” security behavior.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/mesh/src/api/routes/downstream-token.test.ts, line 118:

<comment>The new regression tests never assert `findById` is not called, so they don’t verify the intended “reject before lookup” security behavior.</comment>

<file context>
@@ -105,4 +105,62 @@ describe("Downstream Token Routes", () => {
+        auth: { user: { id: "user_1" }, apiKey: { userId: "user_1" } },
+        storage: {
+          connections: {
+            findById: mock(async () => ({ id: "conn_1" })),
+          },
+        },
</file context>
Fix with Cubic

},
},
} as unknown as MeshContext;

orglessApp = new Hono();
orglessApp.use("*", async (c, next) => {
c.set("meshContext", ctx);
await next();
});
orglessApp.route("/", downstreamTokenRoutes);
});

it("POST rejects token write without organization context", async () => {
const res = await orglessApp.request("/connections/conn_1/oauth-token", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
accessToken: "ATTACKER_TOKEN",
tokenEndpoint: "https://evil.com/token",
}),
});

expect(res.status).toBe(403);
const body = (await res.json()) as { error: string };
expect(body.error).toBe("Organization context required");
});

it("DELETE rejects token deletion without organization context", async () => {
const res = await orglessApp.request("/connections/conn_1/oauth-token", {
method: "DELETE",
});

expect(res.status).toBe(403);
const body = (await res.json()) as { error: string };
expect(body.error).toBe("Organization context required");
});

it("GET status rejects token status check without organization context", async () => {
const res = await orglessApp.request(
"/connections/conn_1/oauth-token/status",
);

expect(res.status).toBe(403);
const body = (await res.json()) as { error: string };
expect(body.error).toBe("Organization context required");
});
});
});
Loading