Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

fix(eve): accept default channel webhook OIDC only from the same environment (#5233)

OwenKephartb3ede0729f02
diff --git a/.changeset/same-environment-webhook-oidc.md b/.changeset/same-environment-webhook-oidc.md
new file mode 100644
index 000000000..804fc4b80
--- /dev/null
+++ b/.changeset/same-environment-webhook-oidc.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+The Linq and Photon channels' default webhook verification now only accepts Vercel OIDC tokens from the same project and environment.
diff --git a/docs/channels/linq.mdx b/docs/channels/linq.mdx
index be80fa4f9..0e9bfe01c 100644
--- a/docs/channels/linq.mdx
+++ b/docs/channels/linq.mdx
@@ -16,7 +16,7 @@ export default linqChannel({
});
```
-The default webhook route is `/eve/v1/linq`. The channel verifies forwarded webhooks with same-project Vercel OIDC by default, derives user auth from each message author, marks accepted messages as read, and continues the same eve session for every message in a Linq conversation. A new accepted message steers the active turn. Before answer output or local tool execution begins, steering can interrupt pending model generation. Executing tools finish first; after answer output starts, steering waits for the next committed workflow boundary. See [Overlapping messages](./overview#overlapping-messages).
+The default webhook route is `/eve/v1/linq`. The channel verifies forwarded webhooks with Vercel OIDC from the same project and environment by default, derives user auth from each message author, marks accepted messages as read, and continues the same eve session for every message in a Linq conversation. A new accepted message steers the active turn. Before answer output or local tool execution begins, steering can interrupt pending model generation. Executing tools finish first; after answer output starts, steering waits for the next committed workflow boundary. See [Overlapping messages](./overview#overlapping-messages).
Set `turnPolicy: "queue"` when every response should finish before Linq starts the next message.
diff --git a/docs/channels/photon.mdx b/docs/channels/photon.mdx
index f3e363fb1..70b8231cd 100644
--- a/docs/channels/photon.mdx
+++ b/docs/channels/photon.mdx
@@ -22,7 +22,7 @@ export default photonIMessageChannel({
```
The default webhook route is `/eve/v1/photon`. The channel verifies forwarded
-webhooks with same-project Vercel OIDC by default, derives user auth from each
+webhooks with Vercel OIDC from the same project and environment by default, derives user auth from each
message author, marks accepted messages as read, and continues the same eve
session for every message in an iMessage conversation. A new accepted message
steers the active turn. Steering can interrupt pending model generation before
diff --git a/packages/eve/src/public/channels/discord/messages.ts b/packages/eve/src/public/channels/discord/messages.ts
index fa5791adb..96d07b835 100644
--- a/packages/eve/src/public/channels/discord/messages.ts
+++ b/packages/eve/src/public/channels/discord/messages.ts
@@ -9,7 +9,8 @@ import type { SessionAuthContext } from "#channel/types.js";
import { EveAttachmentError } from "#internal/attachments/errors.js";
import { readLimitedBytes } from "#internal/attachments/limited-read.js";
import { createLogger, logError } from "#internal/logging.js";
-import { type AuthFn, localDev, routeAuth, vercelOidc } from "#public/channels/auth.js";
+import { type AuthFn, localDev, routeAuth } from "#public/channels/auth.js";
+import { sameEnvironmentVercelOidc } from "#public/channels/same-environment-oidc.js";
import {
callDiscordApi,
discordContinuationToken,
@@ -161,7 +162,7 @@ export function createDiscordGatewayRoute(input: {
readonly buildContext: (state: DiscordChannelState) => DiscordContext;
}): HttpRouteDefinition<DiscordChannelState> {
const { config, gateway } = input;
- const auth = gateway.auth ?? [localDev(), sameEnvironmentRuntime()];
+ const auth = gateway.auth ?? [localDev(), sameEnvironmentVercelOidc()];
const onMessage = gateway.onMessage ?? defaultOnMessage;
return POST<DiscordChannelState>(
@@ -299,19 +300,6 @@ export function createDiscordGatewayRoute(input: {
);
}
-/**
- * Vercel OIDC from this project's runtime in the current environment only.
- * Other environments, such as a preview deployment, authenticate as
- * `service` and must not reach production as any Discord user.
- */
-function sameEnvironmentRuntime(): AuthFn<Request> {
- const oidc = vercelOidc();
- return async (request) => {
- const auth = await oidc(request);
- return auth?.principalType === "runtime" ? auth : null;
- };
-}
-
function ignored(reason: string): Response {
return Response.json({ accepted: false, reason });
}
diff --git a/packages/eve/src/public/channels/linq/linqChannel.test.ts b/packages/eve/src/public/channels/linq/linqChannel.test.ts
index ef52bf1fb..12beb22a7 100644
--- a/packages/eve/src/public/channels/linq/linqChannel.test.ts
+++ b/packages/eve/src/public/channels/linq/linqChannel.test.ts
@@ -176,6 +176,20 @@ describe("linqChannel", () => {
expect(response.status).toBe(401);
});
+ it("rejects default-verified webhooks signed by another environment of the project", async () => {
+ vercelOidc.mockReturnValue(async () => ({ principalType: "service", subject: "preview" }));
+ const { createLinqAdapter: createRealLinqAdapter } = await vi.importActual<
+ typeof import("#compiled/@linqapp/chat-sdk-adapter/index.js")
+ >("#compiled/@linqapp/chat-sdk-adapter/index.js");
+
+ linqChannel({ credentials: { apiKey: "linq-api-key" } });
+ const config = createLinqAdapter.mock.calls[0]?.[0];
+ if (config === undefined) throw new Error("Expected Linq adapter config.");
+ const response = await createRealLinqAdapter(config).handleWebhook(forgedWebhook());
+
+ expect(response.status).toBe(401);
+ });
+
it("drops blank inbound messages", async () => {
linqChannel({
credentials: { apiKey: "linq-api-key", signingSecret: "linq-signing-secret" },
diff --git a/packages/eve/src/public/channels/linq/linqChannel.ts b/packages/eve/src/public/channels/linq/linqChannel.ts
index 78033c22a..d21b2b2e6 100644
--- a/packages/eve/src/public/channels/linq/linqChannel.ts
+++ b/packages/eve/src/public/channels/linq/linqChannel.ts
@@ -1,6 +1,6 @@
import type { SessionAuthContext, TurnPolicy } from "#channel/types.js";
import type { SessionHistoryMessage } from "#shared/session-history.js";
-import { vercelOidc } from "#public/channels/auth.js";
+import { sameEnvironmentVercelOidc } from "#public/channels/same-environment-oidc.js";
import {
chatSdkChannel,
type ChatSdkChannelBridge,
@@ -172,7 +172,8 @@ function normalizeCredentials(
if (apiKey !== undefined) {
config.credentials = createCredentialProvider(apiKey, signingSecret);
}
- const verifier = webhookVerifier ?? (signingSecret === undefined ? vercelOidc() : undefined);
+ const verifier =
+ webhookVerifier ?? (signingSecret === undefined ? sameEnvironmentVercelOidc() : undefined);
if (verifier !== undefined) config.webhookVerifier = rejectFalsyResults(verifier);
return config;
}
diff --git a/packages/eve/src/public/channels/photon/photonIMessageChannel.test.ts b/packages/eve/src/public/channels/photon/photonIMessageChannel.test.ts
index 6e7a89535..0af8acb2a 100644
--- a/packages/eve/src/public/channels/photon/photonIMessageChannel.test.ts
+++ b/packages/eve/src/public/channels/photon/photonIMessageChannel.test.ts
@@ -1,11 +1,23 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
-const { directMessage, fetchMessage, newMessage, reaction, send } = vi.hoisted(() => ({
+const {
+ createiMessageAdapter,
+ directMessage,
+ fetchMessage,
+ newMessage,
+ reaction,
+ send,
+ vercelOidc,
+} = vi.hoisted(() => ({
+ createiMessageAdapter: vi.fn(
+ (_config: { webhookVerifier?: (request: Request) => unknown }) => ({}),
+ ),
directMessage: vi.fn(),
fetchMessage: vi.fn(),
newMessage: vi.fn(),
reaction: vi.fn(),
send: vi.fn(),
+ vercelOidc: vi.fn(),
}));
vi.mock("#public/channels/chat-sdk/index.js", () => ({
@@ -26,9 +38,9 @@ vi.mock("#compiled/@chat-adapter/state-memory/index.js", () => ({
createMemoryState: vi.fn(),
}));
vi.mock("#compiled/@photon-ai/chat-adapter-imessage/index.js", () => ({
- createiMessageAdapter: vi.fn(() => ({})),
+ createiMessageAdapter,
}));
-vi.mock("#public/channels/auth.js", () => ({ vercelOidc: vi.fn() }));
+vi.mock("#public/channels/auth.js", () => ({ vercelOidc }));
import {
defaultPhotonAuth,
@@ -43,6 +55,23 @@ describe("photonIMessageChannel", () => {
vi.clearAllMocks();
});
+ it("verifies webhooks by default only with Vercel OIDC from the current environment", async () => {
+ const runtime = { principalType: "runtime", subject: "production" };
+ const verify = vi.fn();
+ vercelOidc.mockReturnValue(verify);
+ photonIMessageChannel({
+ credentials: async () => ({ projectId: "project-id", projectSecret: "project-secret" }),
+ });
+ const webhookVerifier = createiMessageAdapter.mock.calls[0]?.[0].webhookVerifier;
+ if (webhookVerifier === undefined) throw new Error("Expected a default webhook verifier.");
+ const request = new Request("https://agent.example/webhook", { method: "POST" });
+
+ verify.mockResolvedValueOnce({ principalType: "service", subject: "preview" });
+ await expect(webhookVerifier(request)).resolves.toBeNull();
+ verify.mockResolvedValueOnce(runtime);
+ await expect(webhookVerifier(request)).resolves.toBe(runtime);
+ });
+
it("sends emoji tapbacks through the fetched spectrum message", async () => {
const react = vi.fn();
fetchMessage.mockResolvedValue({ raw: { react } });
diff --git a/packages/eve/src/public/channels/photon/photonIMessageChannel.ts b/packages/eve/src/public/channels/photon/photonIMessageChannel.ts
index 7c5c1c5d7..6646b5e01 100644
--- a/packages/eve/src/public/channels/photon/photonIMessageChannel.ts
+++ b/packages/eve/src/public/channels/photon/photonIMessageChannel.ts
@@ -1,6 +1,6 @@
import type { SessionAuthContext, TurnPolicy } from "#channel/types.js";
import type { SessionHistoryMessage } from "#shared/session-history.js";
-import { vercelOidc } from "#public/channels/auth.js";
+import { sameEnvironmentVercelOidc } from "#public/channels/same-environment-oidc.js";
import {
chatSdkChannel,
type ChatSdkChannel,
@@ -118,7 +118,7 @@ export function photonIMessageChannel(config: PhotonIMessageChannelConfig): Phot
? { webhookVerifier: config.webhookVerifier }
: webhookSecret
? { webhookSecret }
- : { webhookVerifier: vercelOidc() }),
+ : { webhookVerifier: sameEnvironmentVercelOidc() }),
});
addPhotonAttachmentRehydration(imessage);
const bridge = chatSdkChannel({
diff --git a/packages/eve/src/public/channels/same-environment-oidc.test.ts b/packages/eve/src/public/channels/same-environment-oidc.test.ts
new file mode 100644
index 000000000..d75a5da56
--- /dev/null
+++ b/packages/eve/src/public/channels/same-environment-oidc.test.ts
@@ -0,0 +1,32 @@
+import { beforeEach, describe, expect, it, vi } from "vitest";
+
+const { verify } = vi.hoisted(() => ({ verify: vi.fn() }));
+
+vi.mock("#public/channels/auth.js", () => ({ vercelOidc: () => verify }));
+
+import { sameEnvironmentVercelOidc } from "#public/channels/same-environment-oidc.js";
+
+const request = new Request("https://agent.example/webhook", { method: "POST" });
+
+describe("sameEnvironmentVercelOidc", () => {
+ beforeEach(() => {
+ verify.mockReset();
+ });
+
+ it("accepts a token from this project's current environment", async () => {
+ const auth = { principalType: "runtime", subject: "prj" };
+ verify.mockResolvedValue(auth);
+
+ await expect(sameEnvironmentVercelOidc()(request)).resolves.toBe(auth);
+ });
+
+ it.each([
+ ["another environment of this project", { principalType: "service", subject: "prj" }],
+ ["a user token", { principalType: "user", subject: "user" }],
+ ["a missing or invalid token", null],
+ ])("rejects %s", async (_name, auth) => {
+ verify.mockResolvedValue(auth);
+
+ await expect(sameEnvironmentVercelOidc()(request)).resolves.toBeNull();
+ });
+});
diff --git a/packages/eve/src/public/channels/same-environment-oidc.ts b/packages/eve/src/public/channels/same-environment-oidc.ts
new file mode 100644
index 000000000..af7eea85d
--- /dev/null
+++ b/packages/eve/src/public/channels/same-environment-oidc.ts
@@ -0,0 +1,14 @@
+import { type AuthFn, vercelOidc } from "#public/channels/auth.js";
+
+/**
+ * Vercel OIDC from this project in the current environment only. Tokens from
+ * the project's other environments, such as a preview deployment, authenticate
+ * as `service` and must not reach this deployment's inbound channel routes.
+ */
+export function sameEnvironmentVercelOidc(): AuthFn<Request> {
+ const oidc = vercelOidc();
+ return async (request) => {
+ const auth = await oidc(request);
+ return auth?.principalType === "runtime" ? auth : null;
+ };
+}