Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

misc: addressed feedback

Sheen Capadngan7323493a3b0a
diff --git a/backend/src/ee/routes/v1/agent-vault-routers/agent-vault-access-bundle-router.ts b/backend/src/ee/routes/v1/agent-vault-routers/agent-vault-access-bundle-router.ts
index b5e7632b13..ef61516ebd 100644
--- a/backend/src/ee/routes/v1/agent-vault-routers/agent-vault-access-bundle-router.ts
+++ b/backend/src/ee/routes/v1/agent-vault-routers/agent-vault-access-bundle-router.ts
@@ -11,6 +11,7 @@ import { parseHostPatterns } from "@app/ee/services/agent-vault/agent-vault-host
import { EventType } from "@app/ee/services/audit-log/audit-log-types";
import { AGENT_VAULT } from "@app/lib/api-docs";
import { ApiDocsTags } from "@app/lib/api-docs/constants";
+import { pick } from "@app/lib/fn";
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
import { emitAgentVaultTelemetry } from "@app/server/lib/telemetry";
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
@@ -50,6 +51,13 @@ const AccessBundleSchema = AgentVaultAccessBundlesSchema.pick({
updatedAt: true
});
+// Copied into the audit metadata as they are. The other fields are derived or reduced to names, so they stay explicit.
+const SERVICE_RULE_AUDIT_FIELDS: ("allowedMethods" | "allowedPathPrefixes" | "allowedTools")[] = [
+ "allowedMethods",
+ "allowedPathPrefixes",
+ "allowedTools"
+];
+
const variableKeysOf = (service: { variableReferences: { key: string }[] }) => [
...new Set(service.variableReferences.map((reference) => reference.key))
];
@@ -334,9 +342,7 @@ export const registerAgentVaultAccessBundleRouter = async (server: FastifyZodPro
service.credential.type === AgentVaultCredentialType.OAuth ? service.credential.issuer : undefined,
oauthScopes:
service.credential.type === AgentVaultCredentialType.OAuth ? service.credential.grantedScopes : undefined,
- allowedMethods: service.allowedMethods,
- allowedPathPrefixes: service.allowedPathPrefixes,
- allowedTools: service.allowedTools,
+ ...pick(service, SERVICE_RULE_AUDIT_FIELDS),
memberProvidedFields:
service.credential.type === AgentVaultCredentialType.Bearer ||
service.credential.type === AgentVaultCredentialType.Basic
@@ -434,9 +440,7 @@ export const registerAgentVaultAccessBundleRouter = async (server: FastifyZodPro
isOauthAuthorized && service.credential.type === AgentVaultCredentialType.OAuth
? service.credential.grantedScopes
: undefined,
- allowedMethods: update.allowedMethods,
- allowedPathPrefixes: update.allowedPathPrefixes,
- allowedTools: update.allowedTools,
+ ...pick(update, SERVICE_RULE_AUDIT_FIELDS),
// The setting after the update, present whenever the update touched the credential.
memberProvidedFields:
req.body.credential &&
diff --git a/backend/src/ee/services/agent-vault-access-bundle/agent-vault-mcp-tool-list-fns.test.ts b/backend/src/ee/services/agent-vault-access-bundle/agent-vault-mcp-tool-list-fns.test.ts
index ec527c2e9d..d99bcee759 100644
--- a/backend/src/ee/services/agent-vault-access-bundle/agent-vault-mcp-tool-list-fns.test.ts
+++ b/backend/src/ee/services/agent-vault-access-bundle/agent-vault-mcp-tool-list-fns.test.ts
@@ -167,6 +167,21 @@ describe("listing an MCP server's tools", () => {
expect(pong!.headers).toMatchObject({ "Mcp-Session-Id": "session-1" });
});
+ test("a server that sends a flood of pings fails the load before any of that batch is answered", async () => {
+ const pings = Array.from({ length: 21 }, (_, index) => ({ jsonrpc: "2.0", id: `ping-${index}`, method: "ping" }));
+ const { http, requests } = streamableServer(() => sse([pings]));
+ await expect(
+ listMcpServerTools({
+ serverUrl: SERVER_URL,
+ transport: AgentVaultMcpTransport.StreamableHttp,
+ headers: AUTH,
+ secrets: SECRETS,
+ http
+ })
+ ).rejects.toThrow("'mcp.example.com' sent too many pings while listing its tools.");
+ expect(requests.some((request) => request.body?.includes('"result"'))).toBe(false);
+ });
+
test("a temporary server failure asks to try again and still ends the session", async () => {
const { http, requests } = streamableServer(() => json(503, {}));
await expect(
diff --git a/backend/src/ee/services/agent-vault-access-bundle/agent-vault-mcp-tool-list-fns.ts b/backend/src/ee/services/agent-vault-access-bundle/agent-vault-mcp-tool-list-fns.ts
index 34bb08b261..94823e4e0c 100644
--- a/backend/src/ee/services/agent-vault-access-bundle/agent-vault-mcp-tool-list-fns.ts
+++ b/backend/src/ee/services/agent-vault-access-bundle/agent-vault-mcp-tool-list-fns.ts
@@ -18,6 +18,7 @@ const SESSION_END_TIMEOUT_MS = 3000;
const MAX_MESSAGE_BYTES = 4 * 1024 * 1024;
const MAX_STREAM_BYTES = 16 * 1024 * 1024;
const MAX_DESCRIPTION_LENGTH = 1000;
+const MAX_PING_REPLIES = 20;
type TMcpHttpMethod = AgentVaultHttpMethod.Get | AgentVaultHttpMethod.Post | AgentVaultHttpMethod.Delete;
@@ -66,21 +67,6 @@ type TJsonRpcMessage = { id?: unknown; method?: unknown; result?: unknown; error
// A server request can reuse a client request's id (ids are unique per sender), so only a response answers one.
const isResponseTo = (id: number) => (message: TJsonRpcMessage) => message.id === id && message.method === undefined;
-// MCP has the receiver answer a ping promptly, and a server may drop a client that doesn't. Not awaited, so the
-// pending response is still read while the answer is in flight.
-const answerPings = (
- messages: TJsonRpcMessage[],
- reply: (message: Record<string, unknown>) => Promise<TMcpHttpResponse>
-) => {
- messages
- .filter((message) => message.method === "ping" && message.id !== undefined)
- .forEach((message) => {
- void reply({ jsonrpc: "2.0", id: message.id, result: {} })
- .then((response) => response.body.destroy())
- .catch(() => {});
- });
-};
-
const toMessages = (parsed: unknown): TJsonRpcMessage[] =>
(Array.isArray(parsed) ? parsed : [parsed]).filter(
(message): message is TJsonRpcMessage => typeof message === "object" && message !== null
@@ -233,6 +219,26 @@ export const listMcpServerTools = async ({
return message.result;
};
+ // MCP has the receiver answer a ping promptly, and a server may drop a client that doesn't. Not awaited, so the
+ // pending response is still read while the answer is in flight. Capped per load, since one batch can hold any
+ // number of pings and each answer is a request.
+ let pingsAnswered = 0;
+ const answerPings = (
+ messages: TJsonRpcMessage[],
+ reply: (message: Record<string, unknown>) => Promise<TMcpHttpResponse>
+ ) => {
+ const pings = messages.filter((message) => message.method === "ping" && message.id !== undefined);
+ pingsAnswered += pings.length;
+ if (pingsAnswered > MAX_PING_REPLIES) {
+ throw new McpListError({ message: `'${server}' sent too many pings while listing its tools.` });
+ }
+ pings.forEach((message) => {
+ void reply({ jsonrpc: "2.0", id: message.id, result: {} })
+ .then((response) => response.body.destroy())
+ .catch(() => {});
+ });
+ };
+
const parseJson = (text: string) => {
try {
return JSON.parse(text) as unknown;