Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

fix(eve): reject Linq webhooks when the verifier returns a falsy result (#5194)

OwenKephart798a91e7f3b7
diff --git a/.changeset/linq-reject-falsy-webhook-verifier.md b/.changeset/linq-reject-falsy-webhook-verifier.md
new file mode 100644
index 000000000..b48eaf7a3
--- /dev/null
+++ b/.changeset/linq-reject-falsy-webhook-verifier.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+The Linq channel now rejects inbound webhooks with a 401 whenever its webhook verifier returns any falsy value, including the `null` that `vercelOidc()` returns for a missing or invalid token. Previously only `false` rejected a request, so Vercel Connect setups without a `signingSecret` accepted unsigned webhooks.
diff --git a/docs/channels/linq.mdx b/docs/channels/linq.mdx
index fbbfb3cf7..be80fa4f9 100644
--- a/docs/channels/linq.mdx
+++ b/docs/channels/linq.mdx
@@ -37,7 +37,7 @@ export default linqChannel({
});
```
-Set `route` to override the webhook path or `webhookVerifier` to use a different trusted-forwarder verifier.
+Set `route` to override the webhook path or `webhookVerifier` to use a different trusted-forwarder verifier. A verifier rejects a webhook by throwing or returning a falsy value such as `null` or `false`.
## Tapbacks
diff --git a/packages/eve/src/public/channels/linq/linqChannel.test.ts b/packages/eve/src/public/channels/linq/linqChannel.test.ts
index d83dcacf3..ef52bf1fb 100644
--- a/packages/eve/src/public/channels/linq/linqChannel.test.ts
+++ b/packages/eve/src/public/channels/linq/linqChannel.test.ts
@@ -1,17 +1,31 @@
import { beforeEach, describe, expect, it, vi } from "vitest";
-const { createLinqAdapter, directMessage, fetchMessage, markRead, newMessage, reaction, send } =
- vi.hoisted(() => ({
- createLinqAdapter: vi.fn((_config: { credentials?: () => unknown | Promise<unknown> }) => ({
+const {
+ createLinqAdapter,
+ directMessage,
+ fetchMessage,
+ markRead,
+ newMessage,
+ reaction,
+ send,
+ vercelOidc,
+} = vi.hoisted(() => ({
+ createLinqAdapter: vi.fn(
+ (_config: {
+ credentials?: () => unknown | Promise<unknown>;
+ webhookVerifier?: (request: Request, rawBody: Uint8Array) => unknown;
+ }) => ({
name: "linq",
- })),
- directMessage: vi.fn(),
- fetchMessage: vi.fn(),
- markRead: vi.fn(),
- newMessage: vi.fn(),
- reaction: vi.fn(),
- send: vi.fn(),
- }));
+ }),
+ ),
+ directMessage: vi.fn(),
+ fetchMessage: vi.fn(),
+ markRead: vi.fn(),
+ newMessage: vi.fn(),
+ reaction: vi.fn(),
+ send: vi.fn(),
+ vercelOidc: vi.fn(),
+}));
vi.mock("#public/channels/chat-sdk/index.js", () => ({
chatSdkChannel: () => ({
@@ -32,11 +46,19 @@ vi.mock("#compiled/@chat-adapter/state-memory/index.js", () => ({
vi.mock("#compiled/@linqapp/chat-sdk-adapter/index.js", () => ({
createLinqAdapter,
}));
-vi.mock("#public/channels/auth.js", () => ({ vercelOidc: vi.fn() }));
+vi.mock("#public/channels/auth.js", () => ({ vercelOidc }));
import { Message } from "#compiled/chat/index.js";
import { defaultLinqAuth, linqChannel } from "#public/channels/linq/linqChannel.js";
+function forgedWebhook(): Request {
+ return new Request("https://agent.example/eve/v1/linq", {
+ body: JSON.stringify({ event_type: "message.received", data: { direction: "inbound" } }),
+ headers: { "content-type": "application/json" },
+ method: "POST",
+ });
+}
+
describe("linqChannel", () => {
beforeEach(() => {
vi.clearAllMocks();
@@ -121,19 +143,39 @@ describe("linqChannel", () => {
it("uses lazy credentials and the managed credential verifier", async () => {
const apiKey = vi.fn(async () => "rotating-token");
const signingSecret = vi.fn(async () => "rotating-secret");
- const webhookVerifier = vi.fn();
+ const webhookVerifier = vi.fn(async () => true);
linqChannel({ credentials: { apiKey, signingSecret, webhookVerifier } });
const config = createLinqAdapter.mock.calls[0]?.[0];
- expect(config).toMatchObject({ webhookVerifier });
expect(config).not.toHaveProperty("signingSecret");
+ const request = forgedWebhook();
+ const rawBody = new Uint8Array();
+ await expect(config?.webhookVerifier?.(request, rawBody)).resolves.toBe(true);
+ expect(webhookVerifier).toHaveBeenCalledWith(request, rawBody);
await expect(config?.credentials?.()).resolves.toEqual({
apiKey: "rotating-token",
signingSecret: "rotating-secret",
});
});
+ it.each([
+ ["default Vercel OIDC verifier", undefined],
+ ["supplied verifier", () => null],
+ ])("rejects webhooks when the %s returns a falsy result", async (_name, webhookVerifier) => {
+ vercelOidc.mockReturnValue(async () => null);
+ 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", webhookVerifier } });
+ 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 a15ac5aa1..78033c22a 100644
--- a/packages/eve/src/public/channels/linq/linqChannel.ts
+++ b/packages/eve/src/public/channels/linq/linqChannel.ts
@@ -63,7 +63,10 @@ export interface LinqChannelCredentials {
readonly apiKey?: LinqCredentialValue;
/** Signing secret for direct Linq webhook delivery. */
readonly signingSecret?: LinqCredentialValue;
- /** Trusted verifier for webhooks forwarded by a provider such as Vercel Connect. */
+ /**
+ * Trusted verifier for webhooks forwarded by a provider such as Vercel Connect.
+ * Return a falsy value or throw to reject the request.
+ */
readonly webhookVerifier?: LinqWebhookVerifier;
}
@@ -169,14 +172,18 @@ function normalizeCredentials(
if (apiKey !== undefined) {
config.credentials = createCredentialProvider(apiKey, signingSecret);
}
- if (webhookVerifier !== undefined) {
- config.webhookVerifier = webhookVerifier;
- } else if (signingSecret === undefined) {
- config.webhookVerifier = vercelOidc();
- }
+ const verifier = webhookVerifier ?? (signingSecret === undefined ? vercelOidc() : undefined);
+ if (verifier !== undefined) config.webhookVerifier = rejectFalsyResults(verifier);
return config;
}
+// The Linq adapter rejects only a strict `false`, but eve verifiers such as
+// vercelOidc() reject with `null`, which the adapter would otherwise accept.
+function rejectFalsyResults(verifier: LinqWebhookVerifier): LinqWebhookVerifier {
+ return async (request: Request, rawBody: Uint8Array) =>
+ (await verifier(request, rawBody)) || false;
+}
+
function createCredentialProvider(
apiKey: LinqCredentialValue,
signingSecret: LinqCredentialValue | undefined,